Understanding Linux Virtual File System VFS-Overview __linux

Source: Internet
Author: User
Tags garbage collection

Currently, in addition to Linux standard file system EXT2/EXT3/EXT4, there are many kinds of file systems, such as ReiserFS, XFS, Windows VFAT NTFS, Network File system NFS and Flash file system JFFS2, yaffs/ YAFFS2 ubifs. Linux provides perfect support for these file systems through the middle tier called VFS.

For users, these file systems are almost transparent, and in most cases the user interacts through the libc and kernel VFS without caring for the underlying file system's implementation, but sometimes the application needs to consider the underlying file system limitations (such as fat vfat not support links, For example, each file system supports a different maximum file limit. the significance of the existence of VFS

1. Up, provide a standard file operation interface to the application layer;

2. To the next, the file system provides a standard interface, so that other operating system file system can be easily ported to Linux;

3. VFS internal through a series of efficient management mechanisms, such as Inode cache, dentry cache and file system of the pre-read technology, so that the underlying file system does not need to indulge in complex kernel operations, you can get high-performance;

4. Additionally, the VFS abstracts some complex operations into the VFS as much as possible, making the underlying file system easier to implement.


VFS schema Diagram



File System Classification

File systems can generally be grouped into the following categories

1. disk File System

The largest number of such file systems, the most common: Ext2/ext3/ext4 file system, Resierfs file system SGI XFS file system, JFFS2 yaffs ubifs and other Flash file systems, Crasmfs SQUASHFS and other read-only file systems; fat VFA NTFS and other Windows file systems;

Most of these file systems are based on block device file system, file system data and metadata are stored on the block device, the Flash file system is slightly different, the Flash file system is located in MTD above,

The Flash file system needs to deal with complex functions such as fast, garbage collection, and wear balance. F with the popularity of SD/MMC card, as well as the Flash file system in the scalability, start-up speed on the congenitally deficient. The flash file system has slowly exited the embedded stage.

The significance of the existence of Cramfs SQUASHFS is simplicity, efficiency, stability (simple natural stability), which is still used in the file system read-only scenario. The common feature of both is read-only, compressed. We want to have such a concept, file system complexity comes from write data, delete, TRUNCATE operations, directory add Delete, so a read-only file system is much simpler than the writable file system. The most intuitive way is to view the Cramfs file system implementation lines of code, only a few two small files.

Reiserfs put forward a lot of new concepts of file systems, the reading and writing of small files have done a great deal of optimization, of course, too many new concepts, but also lead to poor readability of the reasons. In addition, because ReiserFS's author Hans ReiserFS was convicted of murdering his wife, the development of ReiserFS was also affected.

XFS is quite complicated, and I'm going to open up a separate analysis later.

2. The Special file system

This type of file system is also very common, they do not provide regular file storage and access, the file system is built on top of memory, providing special file system features. such as proc file system, pipe file system, and TMPFS

3. Network File System

Including NFS CODA AFS and other network file systems


Common File Model

The VFS provides abstractions for the underlying file system, and there are two strategies that provide this abstraction.

1. Provides a minimal common model that enables this model to support the minimum intersection of all file systems

2. Provide a universal model as large as possible, so that this model contains the collection of all file system functions.

Linux uses the second strategy to implement the VFS, so the VFS encapsulates all the functionality and abstraction of the underlying file system, which is responsible for forwarding application-level requests to specific file systems.


When working with files, the objects used in the application space and kernel space are different. For an application, a file descriptor is used to represent a file, which is an integer that the kernel assigns to the file when the file is opened, noting that the file descriptor is valid only within this process, and for the kernel, an inode is used to represent a file. This inode may correspond to multiple file descriptors in multiple processes within the application layer.


Inode

Each file or directory in the kernel has a inode,inode consisting of two main parts:

1. Describes the state of the file metadata, file metadata including file size, permissions, type, time;

2. The file data description is used to define where the file data is stored on the disk.

The inode is simply the manifestation of the file in kernel memory, although each file has an inode, but not every file has a corresponding disk inode on disk, and some file systems do not have disk Inode,inode generated sometimes with file system scans.


Link

Links are Unix-specific concepts and are divided into soft links and hard links

Soft links, also known as symbolic Links, soft link file content point to a file path, that is, the real location of the file, soft links to the file can also be soft links

Hard links are two files that share the same inode,

Not all file systems support symbolic links and hard links, such as fat, yaffs and other file systems do not support symbolic links. In general, a file system without a disk directory structure certainly does not support hard links, and the absence of a disk inode certainly does not support links.

Although soft and hard links have brought a lot of convenience to Linux/unix Operation Management, many software implementations often introduce a lot of complexity.


VFS Object Type

The VFS generic model contains the following types of objects:

1. Super Block

Store file system-related information, for the disk file system, this object usually corresponds to a file system control block on disk (disk super blocks)

2. Inode

Stores a file-related information for the disk file system, which typically corresponds to a file control block (disk inode) on the disk. Each inode corresponds to a number that uniquely identifies the file within the file system.

3. File

File is related to the process, file represents an open file, and the relationship between file and Inode is Many-to-many, because multiple processes can open the same file, and the system creates a file structure for each time it is opened.

4. Dentry

Many operations of the underlying file system rely heavily on the inode of the file, and we need to find the corresponding inode for the file according to the path name before the file operation. We know that the filesystem is tree-shaped, so we need to find the file or directory to operate from the root directory tree, which involves disk operations and is time-consuming. According to the local principle, it is necessary to cache the search process, dentry is to speed up the directory traversal operation introduced by the data structure.

Each disk-based file system has a specific method for building a directory tree. There are generally two ways:

1. A directory entry is stored on the disk

2. Rebuilding directory entries through a parent-child relationship to a disk file


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.