Short note on Linux Virtual file system
1 Answer

Linux Virtual file system

The Linux virtual memory system is responsible for maintaining the address space accessible to each process. It creates pages of virtual memory on demand and manages loading those pages from disk and swapping them back out to disk as required. Under Linux, the virtual memory manager maintains two separate views of a process’s address space: as a set of separate regions and as a set of pages.

  1. The first view of address space is the logical view, describing instructions that the virtual memory system has received concerning the layout of the address space.

  2. In this view, the address space consists of a set of non-overlapping regions, each region representing a continuous, page-aligned subset of the address space. Each region is described internally by a single VM area struct the structure that defines the properties of the region, including the process’s read, write, and execute permissions in the region as well as information about any files associated with the region.

  3. The regions for each address space are linked into a balanced binary tree to allow fast lookup of the region corresponding to any virtual address.

  4. The kernel also maintains a second, physical view of each address space. This view is stored in the hardware page tables for the process.

  5. The page table entries identify the exact current location of each page of virtual memory, whether it is on disk or in physical memory.

  6. The physical view is managed by a set of routines, which are invoked from the kernel’s software-interrupt handlers whenever a the process tries to access a page that is not currently present in the page tables. Each VM area struct in the address-space description contains a field pointing to a table of functions that implement the key page-management functionality for any given virtual memory region.

  7. All requests to read or write an unavailable page are eventually dispatched to the appropriate handler in the function table for the VM area struct so that the central memory management routines do not have to know the details of managing each possible type of memory region.

  8. Linux implements several types of virtual memory regions. One property that characterizes virtual memory is the backing store for the region, which describes where the pages for the region come from.

  9. Most memory regions are backed either by a file or by nothing. A region backed by nothing is the simplest type of virtual memory region. Such a region represents demand-zero memory: when a process tries to read a page in such a region, it is simply given back a page of memory filled with zeros.

  10. A region backed by a file acts as a viewport onto a section of that file. Whenever the process tries to access a page within that region, the page table is filled with the address of a page within the kernel’s page cache corresponding to the appropriate offset in the file.

  11. The same page of physical memory is used by both the page cache and the process’s page tables, so any changes made to the file by the file system are immediately visible to any processes that have mapped that file into their address space. Any number of processes can map the same region of the same file, and they will all end up using the same page of physical memory for the purpose.

  12. A virtual memory region is also defined by its reaction to writes. The mapping of a region into the process’s address space can be either private or shared. If a process writes to a privately mapped region, then the pager detects that a copy-on-write is necessary to keep the changes local to the process.

  13. In contrast, writing to a shared region result in updating the object mapped into that region, so that the change will be visible immediately to any other process that is mapping that object.

Please add some formatting.

Please log in to add an answer.