In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How to analyze the Linux kernel file system, I believe that many inexperienced people do not know what to do. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Overview of Linux kernel storage stack
The kernel storage stack is mainly divided into three layers from top to bottom: 1. VFS 2.Block layer 3. Drive
A brief introduction
This picture is from https://blog.vmsplice.net/2020/04/how-linux-vfs-block-layer-and-device.html. This paper mainly introduces the connection relationship between several important data structures of the storage stack in the kernel. The VFS layer data structure struct block_device connects with the fast layer data structure struct gendisk. The block layer receives a request from VFS and sends it to request_queue, and the driver finally responds to the request and operates on the final physical device.
2.1 VFS layer
VFS provides an interface layer for different underlying file systems (ext4,XFS,NFS, etc.).
System calls such as open,read are handled by VFS and then distributed to the corresponding struct file_operations handlers.
Block devices are represented by struct block_device, VFS layer data structures. Struct block_device uses block-layer data structures struct gendisk and struct request_queue to connect VFS inode and struct file_operations interfaces.
Block device nodes such as / dev/sda is implemented in fs/block_dev.c, providing the function of a bridge to connect VFS and Linux block layer. The block layer processes actual IO requests and knows specific information about the disk, such as disk capacity, block size, and so on.
2.2 Block layer layer
Each disk is represented by a data structure struct gendisk, and struct hd_struct represents a disk partition.
There is always a part0 partition, which represents the entire disk
The IO request queue is represented by struct request_queue
2.3 driver layer
The disk device driver registers struct genhd with the block layer and sets up the struct request_queue to receive requests that need to be submitted to the physical device.
Even though user space may open an struct block_device instance for multiple partitions on disk, the entire device has only one struct genhd.
The drive layer cannot see the disk partition because the IO request has adjusted the logical address according to the offset of the starting position of the partition.
VFS is connected to the block layer struct gendisk. The device driver connects the block layer and the VFS layer struct block_device. The block layer is not directly related to the other two layers, but there is a callback function registered by the driver layer.
Detailed introduction
The components of the Icano flow in the kernel are shown in the following figure:
Here is a diagram of the relationship between the main data structures in the storage stack in the kernel.
Here we track the data flow of a read function call from user space to analyze the process from the kernel to the driver and finally to the physical device hardware.
The kernel executes the system call sys_read in response to the read operation in user space.
Call vfs_read 's common file system read interface in the VFS layer. Here, the corresponding read function is called based on the specific file system type.
Take the ext4 file system as an example. Ext4_file_read_iter is executed.
3.4 the main data structure in the VFS layer is bio, which defines a series of specific behaviors for file operations. After the corresponding bio data structure is constructed, ext4_file_read_iter is called to submit the request to the block layer.
3.5 after receiving the request, the block layer will call the custom function or the general submit_bio according to whether the file system defines its own submit_bio function. The ext4 file system calls generic submit_bio.
Block layer requests for VFS are not submitted directly to the device driver for execution. Instead, the merge is delayed, because finding processing on the physical disk is a time-consuming operation. Operations that can be merged with requests in the request queue are merged first. Otherwise, it is inserted into the request queue. The kernel has a variety of different algorithms for Ipact O scheduling: 1. Elevator dispatching II. Deadline algorithm 3. CFQ completely fair queuing algorithm 4. Expected algorithm 5.No Operations algorithm.
Finally, the driver's queue_rq method is called to send the request to the driver. Different drivers register different queue_rq methods. Take the iscsi driver as an example. Call the execute scsi_queue_rq method.
Scsi_queue_rq constructs the request cmd and then calls scsi_dispatch_cmd to distribute the cmd to the underlying driver.
After that, according to the different underlying device types, call the corresponding queuecommand function to execute the cmd command.
In the kernel storage stack, the block layer acts as a connecting link between the preceding and the following. Accept the IO request sent by VFS to the north, dock the device driver to the south, and submit the request to the device driver. The more important points are: 1. Block layer merges and optimizes the processing of Imax O requests. This piece has a great impact on the performance of IWeiO. two。 Processing of the page cache. Design how to import disk data into memory and how data structures such as inode manipulate access to page data. There are many details to be analyzed.
After reading the above, have you mastered how to analyze the Linux kernel file system? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.