Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 16: Page and Buffer Cache


Function Standard implementation
ext3_readpage mpage_readpage
ext3_readpages mpage_readpages
ext3_writeback_writepage block_write_full_page
ext3_write_begin block_write_begin
ext3_writeback_write_end block_write_end
ext3_direct_IO blockdev_direct_IO

The functions of theaddress_space_operationsstructure and the generic helpers of the kernel use other
arguments so that a brief wrapper function is needed for purposes of parameter conversion. Otherwise,
in most cases, the pointers could point directly to the helper functions mentioned.


Other filesystems also use assignments of theaddress_space_operationsinstances that make direct or
indirect use of kernel standard functions.


The structure of theaddress_space_operationsinstance of the shared-memory filesystem is particularly
simple since only two fields need to be filled with non-NULLpointers:


mm/shmem.c
static struct address_space_operations shmem_aops = {
.writepage = shmem_writepage,
.set_page_dirty = __set_page_dirty_no_writeback,
.migratepage = migrate_page,
};

All that need be implemented is the marking of the page as dirty, page writeback, and page migration.
The other operations are not used to provide shared memory.^5 With which backing store does the kernel
operate in this case? Memory from the shared-memory filesystem is totally independent of a specific
block device because all files of the filesystem are generated dynamically (e.g., by copying the contents
of a file from another filesystem, or by writing calculated data into a new file) and do not reside on any
original block device.


Memory shortage can, of course, also apply to pages that belong to this filesystem so that it is then
necessary to write the pages back to the backing store. Because there is no backing store in the real
sense, the swap area is used in its stead. Whereas normal files are written back to their filesystem on the
hard disk (or on any other block device) in order to free the used page frame, files of the shared-memory
filesystem must be stored in the swap area.


Since access to block devices need not always be made by way of filesystems but may also apply to raw
devices, there are address space operations to support the direct manipulation of the contents of block
devices (this kind of access is required, e.g., when creating filesystems from within userspace):


fs/block_dev.c
struct address_space_operations def_blk_aops = {
.readpage = blkdev_readpage,
.writepage = blkdev_writepage,

(^5) Iftmpfs, which is implemented on top of shared memory, is enabled, thenreadpage,write_begin,andwrite_endare also
implemented.

Free download pdf