For read operations in Linux

Source: Internet
Author: User

About the file read and write, is too complex, too much detail, so can only analyze his principle, the details involved too much.

This article describes the read operation of the file.

Let's talk about the outline of the read operation. The read operation reads the data from the disk into the kernel buffer, the data is organized into a radix_tree form in the kernel buffer, and then the contents of the buffer are copied to the user buffer, and the user can manipulate the data in its own buffer.

The specific point is:

For each process open file, have a file object descriptor, from the file object descriptor can find the index node, from the index node and can find Adress_space, this object is the file in memory cache. Therefore, each process that opens this file will operate on this Adress_space object.

For each given file, the index and the length to be read are checked.

The user will first look for the page it needs from the cache, and if this page is found, check that the page is not up to date. Therefore, this page is mutually exclusive, but this can happen before:

This page may be a page that another process reads from a file, but does not have an IO operation on this page. So he thinks the page data is invalid, need to read the page from disk, but before reading, that process may also delete this page, so at this time need to check the page is not in memory, if not, request a physical page box, and marked as pg_locked, indicating lock, cannot remove this page from memory, Because you want to do an IO operation on this page. You can now start populating this page from disk read content.

Reading this page is not everything, because the above mentioned may exist another process in the operation of this file, and the modification of its contents are written back to the disk, so it is possible to delete the probability of the file, so at this time check if the index + length is found, the page is not valid, to free this page.

Finally, the page is copied to the user-state buffer.

For read operations in Linux

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.