In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Linux kernel driver fsync mechanism implementation process, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
IO models in the Linux kernel are basically divided into four categories:
1. Synchronous blocking Istroke O
2. Synchronous non-blocking Istroke O
3. Asynchronous blocking IBG O
4. Asynchronous non-blocking Istroke O
Synchronization: the application explicitly accesses the data through the function and gets the result (success or failure) when the function returns.
Async: the application will explicitly submit a request for access or interest through the function. When the data arrives, the hardware and driver will notify the application. At this time, the code is generally not in the read-write access function, but is notified before purposefully accessing the data.
Blocking: it sleeps here while waiting for data, and non-blocking means that the function returns immediately without sleep, and the following code can be executed.
In fact, the kernel provides two implementations for asynchronous non-blocking iAccord O, one is aio and the other is fasync. Aio should be regarded as a relatively new framework, which is more complex. I have not studied it in depth. I will write a summary after studying it later. For fasync, a block diagram is drawn to sort out all the code associations. This picture was drawn two months ago, but the release was delayed because of my baby and my work.
To understand the fasync mechanism of the kernel, you can combine this diagram with the explanation in "going deep into the kernel mechanism of Linux device drivers." According to this flow chart, I would like to summarize my own understanding:
First of all, the fasync mechanism implements the notification mechanism through the SIGIO signal sent by the kernel, not through sleep and wake-up.
From this point of view, the application must do the following:
1. Install SIGIO signals (signal routines handle situations where kernel data can be accessed)
2. Tell the process ID that the kernel needs to notify
3. Set the FASYNC flag, and the kernel will call the fasync method through the driver to prepare for future signal notifications.
After the application has completed the relevant settings, you can do something else. If there is any problem, the kernel will notify you through the SIGIO signal, and the signal routine installed by the application will be called.
On the kernel space side, the relevant drivers need to do the following:
1. Define a global struct fasync_struct pointer
2. To realize the fasync method in file_operations is basically to call the kernel auxiliary function fasync_helper.
3. Call the kill_fasync function when driving a routine that can know the accessible information of the data.
Through the cooperation of the above kernel and application, we can easily use the kernel asynchronous notification mechanism. This mechanism is simple to use. At first, it feels very complicated. Once you sort out all the relevant structures and routines in depth, you will find that the implementation of this mechanism is also very clear. I have always believed that for kernel learning, we should first sort out the relationship between architecture and data structures. Looking at other people's code analysis can give you a proper understanding of the architecture, and finally the key lies in your own RTFSC. So now I generally no longer analyze the code in the blog post, but only talk about architecture and diagrams. The code needs to be analyzed by interested friends themselves.
After reading the above, have you mastered how to implement the fsync mechanism of the Linux kernel driver? 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.