Chapter 8: The Virtual Filesystem
this is different from the synchronous readahead operation started before: Now the kernel does
not wait for the readahead operation to complete, but performs the reading whenever it finds
time. The readahead mechanism is considered in more detail in Chapter 16.4.5.
❑ Although the page is in the page cache, the data may not be current; this can be checked using
Page_Uptodate.
If the page is not up-to-date, it must be re-read usingmapping->a_ops->readpage. The function
pointer normally points tompage_readpage. After this call, the kernel knows for sure that the
page is filled with the most recent data.
The access to the page must be marked withmark_page_accessed; this is important to
determine page activity when it is necessary to swap data out of RAM. (Swapping is
discussed in Chapter 18.) Theactorroutine (usuallyfile_read_actor) maps the appro-
priate page into userspace address space. I won’t bother going into the details of how this
is done.^26
page still not in cache?
Usually mpage_readpage
Async
readahead
requested?
Page uptodate?
No
No
Yes
Yes
Yes
Oage not
in Page
Iterate until all desired pages have been read in
do_generic_mapping_read
find_get_page
page_cache_sync_readahead
find_get_page
page_cache_async_readahead
mapping->a_ops->readpage
no_cached_page
mark_page_accessed
actor
Figure 8-14: Code flow diagram fordo_generic_mapping_read.
If the readahead mechanism has not already read the desired page in anticipation, the function is forced
to do it itself. Theno_cached_pagesection ofdo_generic_mapping_readis used for this purpose. Its
code flow diagram is shown in Figure 8-15.^27
Oncepage_cache_alloc_coldhas reserved a cache-cold page, it is inserted in the LRU list of the
page cache viaadd_to_page_cache_lruas described in Chapter 16. Themapping->a_ops->readpage
method provided by the mapping is used to read the data. Usually, the function pointer points to
mpage_readpage, which I deal with in Chapter 16. Finally,mark_page_accessedtells the accounting
system that the page has been accessed.
(^27) Except to say that thecopy_to_userroutine discussed in Chapter 3 is used.