Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 4: Virtual Process Memory


However, the operation has no information on the mapping type or on its properties. As there are numer-
ous kinds of file mappings (regular files on different filesystem types, device files, etc.), more information
is required. In fact, the kernel needs a more detailed description of the address space of the data source.


Theaddress_spacestructure mentioned briefly above is defined for this purpose and contains additional
information on a mapping. Recall that the connection between files, address spaces, and inodes has been
shown in Figure 4-7. Some of the data structures involved are explained in future chapters, and thus their
relationships are not dealt with here; let us simply state that each file mapping has an associated instance
ofaddress_space.


Neither is the exact definition ofstruct address_spacerelevant at this point; it is discussed in more
detail in Chapter 16. Here it is sufficient to know that each address space has a set of address space
operations held as function pointers in the structure shown below (only the most important entries are
reproduced).


<fs.h>
struct address_space_operations {
int (*writepage)(struct page *page, struct writeback_control *wbc);
int (*readpage)(struct file *, struct page *);
...
/* Write back some dirty pages from this mapping. */
int (*writepages)(struct address_space *, struct writeback_control *);

/* Set a page dirty. Return true if this dirtied it */
int (*set_page_dirty)(struct page *page);

int (*readpages)(struct file *filp, struct address_space *mapping,
struct list_head *pages, unsigned nr_pages);
...
};

A detailed description of the structure can also be found in Chapter 16.


❑ readpagereads a single page from the underlying block medium into RAM memory;readpages
performs the same task for several pages at once.
❑ writepagewrites the contents of a page from RAM memory back to the corresponding location
on a block device to permanently save changes.
❑ set_page_dirtyindicates that the contents of a page have been changed and no longer match
the original contents on the block device.

How is the link betweenvm_operations_structandaddress_spaceestablished? There is no static
link to assign an instance of each structure to the other structure. Nevertheless, both are linked by the
standard implementations that the kernel provides forvm_operations_structand that are used by
almost all filesystems.


mm/filemap.c
struct vm_operations_struct generic_file_vm_ops = {
.fault = filemap_fault,
};
Free download pdf