Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 16: Page and Buffer Cache


The function__getblk


Figure 16-9 shows the code flow diagram for__getblk(this function is discussed first because it is
invoked by__bread).

Cache miss?

Null pointer?

_ _getblk

_ _find_get_block

_ _find_get_block_slow

bh_lru_install

touch_buffer

_ _getblk_slow

lookup_bh_lru

Figure 16-9: Code flow diagram for__getblk.

As the code flow diagram shows, there are two possible options when__getblkexecutes.
__find_get_blockis invoked to find the desired buffer using the method described below. A
buffer_headinstance is returned if the search is successful. Otherwise, the task is delegated to
__getblk_slow. As the name suggest,__getblk_slowyields the desired buffer but takes longer than
__find_get_block. However, this function is able to guarantee that a suitablebuffer_headinstance will
always be returned and that the space needed for the data will be reserved.

As already noted, the fact that a buffer head is returned doesnotmean that the
contents of the data area are correct. But because the buffer head itself is correct, it is
inserted in the buffer cache at the end of the function by means ofbh_lru_install,
andtouch_buffercalls themark_page_accessedmethod (see Chapter 18) for the
page associated with the buffer.

The key issue is obviously the difference between__find_get_blockand__getblk_slow,wherethe
main work of__getblktakes place.

The familiarlookup_bh_lrufunction is invoked at the start of__find_get_blockto check whether the
required block is already present in the LRU cache.

If not, other means must be applied to continue the search.__find_get_block_slowattempts to find the
data in the page cache, and this can produce two different results:

❑ A null pointer is returned if the data arenotin the page cache, if it is in the page cache but the
page doesnothave any attached buffers.
❑ The pointer to the desired buffer head is returned if the data are in the page cache and the page
also has attached buffers.
Free download pdf