Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 8: The Virtual Filesystem


The-EIOCBQUEUEDreturn value indicates that the read request was queued and not yet processed. In this
case,wait_on_sync_kiocbwaits until the data are in memory. The function can check this by referring
to the initialized control block. The process is put to sleep while it is waiting so that the CPU is available
for other tasks. For the sake of simplicity, I do not differentiate between synchronous or asynchronous
termination of the read operation in the following description.

AsynchronousReading


generic_file_aio_readfrommm/filemap.creads data asynchronously. The associated code flow dia-
gram is shown in Figure 8-13.

Yes

No do_generic_mapping_read

generic_file_aio_read

generic_segment_checks

0_DIRECT set? generic_file_direct_IO

do_generic_file_read

Figure 8-13: Code flow diagram forgeneric_file_aio_read.

Aftergeneric_segment_checkshas ensured that the read request contains valid parameters, two possi-
ble Read modes are distinguished.


  1. If the flagO_DIRECTis set, data are read without using the page cache.genericfile
    direct_IOmust then be used.

  2. Otherwise,do_generic_file_read— a front end fordo_generic_mapping_read—isused.
    This converts the read request for a file into a read operation with a mapping.


Reading from Mappings


Figure 8-14 shows the code flow diagram fordo_generic_mapping_read.

The function uses the mapping mechanism described in Chapter 3 to map the desired section of the file
onto pages in memory. It consists of a large endless loop that continues to read pages until all file data
have been transferred into memory if the data are not already in any cache.

Each loop pass performs the following actions:

❑ First of all,find_get_pagechecks if the page is already contained in the page cache. If this fails,
a synchronous readahead request is issued by callingpage_cache_sync_readahead.
❑ Since the readahead mechanism has most likely ensured that the data are by now in the cache,
find_get_pageis used to find the page once again. There’s still a small chance that this fails
again and that the page has to be read in manually, which is handled by jumping to the label
no_cached_page. I will deal with this below. Usually, however, the page will have been read in
at this point.
❑ If the page flagPG_readaheadis set — the kernel can check this withReadaheadPage—anasyn-
chronous readahead operation must be started withpage_cache_async_readahead.Notethat
Free download pdf