The implementation diagram of Linux kernel drive fsync mechanism

Source: Internet
Author: User
Tags data structures

The IO model in the Linux kernel is basically divided into 4 categories:

1. Synchronous Blocking I/O

2. Synchronous non-blocking I/O

3. Asynchronous blocking I/O

4. Asynchronous non-blocking I/O

Synchronization: Applies an explicit access to data through a function, which results when the function returns (success or failure).

Asynchronous: The application is displayed by using a function to make a visit or a concern request. When the data arrives, the hardware and the driver notify the application, and the code is generally not in the read-write access function, but is notified and then accessed with purposeful access to the data.

Blocking: Sleeps here while waiting for data, rather than blocking, which returns immediately after the function is not dormant, and executes the next code.

For these 4 mechanisms, in the in-depth Linux device driver kernel mechanism, there are two implementations for asynchronous non-blocking I/O in fact, one is AIO and the other is fasync. AIO should be regarded as a relatively new framework, more complex, I did not in-depth research, after the study in writing summary. For Fasync, "Deep Linux device driver kernel mechanism" in a detailed explanation and experiment, after reading this knowledge, I as usual, drew a block diagram to comb all the code associations. The picture was drawn two months ago and was delayed due to the relationship between my baby and my job.

(The above picture compares, the proposal downloads to the local open)

To understand the fasync mechanism of the kernel, you can combine this diagram with the explanation in the "Deep Linux device driver kernel mechanism." I have summed up my own knowledge according to this flowchart:

First, the fasync mechanism is to implement notification mechanisms through the Sigio signal sent by the kernel, not through hibernation.

From this perspective, applications must do the following:

1, the installation of Sigio signal (signal routine processing of kernel data accessible)

2, tell the kernel need to notify the process ID

3, set the FASYNC flag, the kernel will be driven by the driver call Fasync method for future signal notification to prepare.

After the application has completed the relevant settings, you can do something else, if there are any problems, the kernel will pass the SIGIO signal notification, the application of the installation of signal routines will be called.

In the kernel space, the relevant drivers need to do the following:

1, the definition of a global struct fasync_struct pointer;

2, to implement the Fasync method in File_operations, the basic is to call the auxiliary function of the kernel fasync_helper.

3. Call the Kill_fasync function in a routine that drives some information that can be accessed by the data.

Through the combination of the above kernel and application, we can use the kernel asynchronous notification mechanism conveniently. This mechanism is simple to use, look at its mechanism, at first feel very complex, once the depth of all the relevant structures and routines will be found, in fact, the implementation of this mechanism is also very clear. The individual has always thought that for the kernel of learning, first of all to clarify the relationship between the structure and data structures. And look at other people's Code analysis allows you to properly understand the framework, the final key lies in their own RTFSC. So I now generally no longer posting analysis of the code, but only to say that the architecture and graphics, the code needs interested friends to analyze their own.

Related Article

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.