Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 16: Page and Buffer Cache


❑ releasepageprepares page release in journaling filesystems.
❑ invalidatepageis called if a page is going to be removed from the address space and buffers
are associated with it as signalized by thePG_Privateflag.
❑ direct_IOis used to implement direct read and write access. This bypasses buffering in the
block layer and allows an application to communicate very directly with a block device. Large
databases make frequent use of this feature as they are better able to forecast future input and
output than the generic mechanisms of the kernel and can therefore achieve better results by
implementing their own caching mechanisms.
❑ get_xip_pageis used for the execute-in-place mechanism that can launch executable code with-
out having to first load it into the page cache. This is useful on, for example, memory-based
filesystems such as a RAM disk or on small systems with little memory that can address ROM
areas containing filesystems directly via the CPU. As this mechanism is seldom used, it need not
be discussed at length.
❑ migrate_pageis used if the kernel wants to relocate a page, that is, move contents of one page
onto another page. Since pages are often equipped with private data, it is not just sufficient to
copy the raw information from the old to the new page. Moving pages is, for instance, required
to support memory hotplugging.
❑ launder_pageoffers a last chance to write back a dirty page before it is freed.

Most address spaces do not implement all functions and therefore assign null pointers to some. In many
cases, the kernel’s default routines are invoked instead of the specific implementation of the individ-
ual address spaces. Below a few of the kernel’saddress_space_operationsare examined to give an
overview of the options available.

The Third Extended Filesystem defines theext3_writeback_aopsglobal variable, which is a filled
instance ofaddress_space_operations. It contains the functions used in writeback mode:

fs/ext3/inode.c
static const struct address_space_operations ext3_writeback_aops = {
.readpage = ext3_readpage,
.readpages = ext3_readpages,
.writepage = ext3_writeback_writepage,
.sync_page = block_sync_page,
.write_begin = ext3_write_begin,
.write_end = ext3_writeback_write_end,
.bmap = ext3_bmap,
.invalidatepage = ext3_invalidatepage,
.releasepage = ext3_releasepage,
.direct_IO = ext3_direct_IO,
.migratepage = buffer_migrate_page,
};

The pointers that are not explicitly set are automatically initialized withNULLby the compiler.

At first sight, Ext3 appears to set a rather large number of function pointers to use its own implemen-
tations. However, this supposition is quickly disproved by looking at the definitions ofext2_...in the
kernel sources. Many functions consist of few lines and delegate work to the generic helper functions of
the kernel:
Free download pdf