F2FS Source code Analysis of the file read and write process

Source: Internet
Author: User

This article includes three parts: 1) F2fs file representation method, 2) Nat details, 3) f2fs file reading and writing process; 4)

The following is a detailed description of F2FS reading and writing process.

The key data structure to manage the location of the database is node,node including three types: Inode, direct node, indirect node. The Inode records the basic information of the file, including access rights, file size, modification time, etc., as well as indexing functions; direct node and indirect node are solely responsible for indexing. The F2FS Inode has 923 direct data block indexes, 2 primary indexes, 2 two-level indexes, a three-level index, and a logical representation of the file, such as:

There are 923 index entries in the Inode, and there are 1018 index entries in both the direct node and the indirect node.

By, 923 direct data block indexes in the inode can be indexed to XXK data,

2 level indexes can be indexed to

2 levels of two indexes can be indexed to

A level three index can be indexed to

Therefore, the F2FS supports a single file maximum of 3.94T,

The above describes how the F2FS three node matches the index file, but there is a very important detail: The index entry of the indirect node records the NID number (which is related to NAT) and directly records the block address directly in the index entry of node. Take the three-level index part of the figure (a) as an example:

where node block 1) 2) belongs to the indirect node, the index entry is NID, 3), and 4 is a direct node, the address of the data block in the index entry. This design is designed to solve the avalanche tree problem in the log-structured file system, where the NID is the subscript for the NAT table.

In F2FS file systems, NAT tables are a very important data structure that is strongly related to file storage. So, in the second part of this article, we'll talk about the NAT table in detail, including its role and how F2FS manages the NAT table.

The NAT table is located in the metadata area and can be thought of as a large array, with the data subscript nid, where each table entry records information about a node block, including which inode the node belongs to, and the address of that node block on disk.

As an example of the three-level index section in figure (i), we found that the whole index process should be the truth:

This is compared to figure one is beyond recognition, figure one more macro, the image granularity is finer.

Here we can basically understand why F2FS can weaken the impact of the avalanche tree: When the data block in the figure is dirty, it's direct index 2 is dirty, but because 2 is a direct index, node block, the information is managed in NAT, So just need to update the new address in Nat 2)! In this case 3) the corresponding index entry is not changed at all, because the index entry of 3 points to something in Nat!

This mechanism effectively eliminate the snowball more and more big! However, this method, similar to "level two pointers", brings a certain level of performance overhead, so f2fs NAT information is maintained in memory in the form of a linked list + cardinality tree to speed up the discovery, update process.

Okay, here NAT is basically clear, and the process of reading and writing files later involves NAT operations. Here's how to store the following NAT:

There are two Nat in the metadata area, and two Nat is stored in the metadata area with segment granularity (assuming that each NAT table has 3 segment):

Two NAT is prepared because there are two copies of Snapshot,nat in F2FS that are strongly related to file storage and therefore two copies. However, there is not a one by one correspondence between two copies of Snapshort and two Nat, such as not that the NAT data for the first snapshot is completely stored in NAT0 (or NAT1) in the diagram. It is done by a bitmap to complete the mapping of the NAT on the block granularity:

Well, after the introduction of NAT, we have a new understanding of the index of the F2fs file, the following describes the file read and write process:

1) First in the VFS layer,

The above describes the F2fs file logical representation, the following see F2FS source code is how

F2FS Source code Analysis of the file read and write process

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.