Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 16: Page and Buffer Cache


mark_buffer_async_readis also invoked to setend_buffer_async_readforb_end_io—thisfunction
is invoked automatically when data transfer ends.

Actual I/O is triggered in the third phase in whichsubmit_bhforwards all buffers to be read
to the block or BIO layer where the read operation is started. The function stored inb_end_io
(end_buffer_async_readin this case) is called when the read operation terminates. It iterates over all
the page’s buffers, checks their state, and sets the state of the entire page to up-to-date assumingall
buffers have this state.

As can be seen, the advantage ofblock_read_full_pageis that it is necessary to read only those parts
of the page that are not up-to-date. However, if it is certain that the entire page is not up-to-date,
mpage_readpageis the better alternative as the buffer overhead is then superfluous.

Writing Whole Pages into Buffers


Not only reading but also writing of full pages can bedivided into smaller buffer units. Only those parts
of a page that have actually been modified need be written back, not the whole page contents. Unfor-
tunately, from the buffer viewpoint, the implementation of write operations is much more complicated
than the read operations described above. I ignore the minor details of the (somewhat simplified) write
operations and focus on the key actions required of the kernel in my discussion below.

Figure 16-8 shows the code flow diagram for the error-free performance of the buffer-related operations
needed to write back dirty pages in the__block_write_full_pagefunction (to simplify matters, I also
omit some seldom required corner cases that must be dealt with in reality).

_ _block_write_full_page

!page_has_buffers

!buffer_mapped && buffer_dirty get_block

lock_buffer

mark_buffer_async_write

SetPageWriteback

buffer_async_write submit_bh

buffer_mapped && buffer_dirty

create_empty_buffers

Figure 16-8: Code flow diagram for the buffer-related operations of
__block_write_full_page.

The writeback process is split into several parts, each of which repeatedly iterates over the singly linked
list of buffers attached to a page.
Free download pdf