0
3.6kviews
Short note on Linux Virtual file system

Linux Virtual File System (VFS) is an abstraction layer that provides a unified interface for file systems in the Linux kernel. It allows different file systems, such as ext4, NTFS, and FAT, to be accessed using a consistent set of system calls regardless of their underlying implementation.

Here are some key points about the Linux Virtual File System:

  1. Abstraction Layer: VFS acts as an abstraction layer between the file systems and the kernel. It provides a common interface that enables applications and processes to interact with different file systems without needing to know their specific details.

  2. File System Operations: VFS defines a set of operations that all file systems must implement, such as file opening, reading, writing, and closing. These operations are represented by function pointers in the file system's superblock, allowing the kernel to invoke the appropriate functions for a specific file system.

  3. Superblock and Inode Structures: VFS uses two main data structures: the superblock and the inode. The superblock contains information about the file system, such as its type and mount options. The inode represents an individual file or directory and contains metadata like file size, permissions, and pointers to the actual data blocks.

  4. File System Registration: When a new file system is added to the Linux kernel, it needs to register itself with VFS. This registration process involves providing function pointers to the file system operations, allowing VFS to invoke the correct functions when interacting with files on that file system.

  5. Mounting and File System Hierarchy: VFS handles the mounting of file systems onto specific directories in the file system hierarchy. Each mounted file system is represented by a mount structure that contains information about the mounted device and the associated file system type.

  6. File System Caching: VFS employs a caching mechanism to improve performance. It caches file system data in memory, including directory entries, file attributes, and file data. This caching reduces the need for frequent disk accesses, improving overall system performance.

  7. File System Modules: VFS supports dynamically loadable file system modules, allowing additional file system types to be added to the kernel without recompiling it. This modularity enhances the flexibility and extensibility of the Linux file system.

1 Answer
3
97views

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.