Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 4: Virtual Process Memory


Data Structures


Every open file (and every block device, because these can also be memory-mapped via device special
files) is represented by an instance ofstruct file. This structure, in turn, contains a pointer to anaddress
spaceobject as represented bystruct address_space.Thisobjectisthebasisoftheprioritysearchtree
(prio tree) by which the connection between mapped intervals and the address spaces into which these are
mapped is established. The definition of both structures is as follows (I only show the elements required
for our purposes here):


<fs.h>
struct address_space {
struct inode *host; /* owner: inode, block_device */
...
struct prio_tree_root i_mmap; /* tree of private and shared mappings */
struct list_head i_mmap_nonlinear;/*list VM_NONLINEAR mappings */
...
}

<fs.h>
struct file {
...
struct address_space *f_mapping;
...
}

Additionally, each file and each block device are represented by an instance ofstruct inode. In contrast
tostruct file, which is the abstraction for a file opened by theopensystem call, the inode represents
the object in the filesystem itself.


<fs.h>
struct inode {
...
struct address_space *i_mapping;
...
}

Notice that only mapped file intervals are discussed below although, it is also possible to map different
things, for instance, direct intervals in raw block devices, without a detour over filesystems. When a file is
opened, the kernel setsfile->f_mappingtoinode->i_mapping. This allows multiple processes to access
the same file without directly interfering with the other processes:inodeis a file-specific data structure,
whilefileis local to a given process.


These data structures are connected with each other, and Figure 4-7 provides an overview about the
situation in memory. Notice that the representation of the tree is only symbolic and does not reflect the
actual, complicated tree layout.


Given an instance ofstruct address_space, the kernel can infer the associated inode, which, in turn,
allows for access to the backing store on which the file data are stored. Usually, the backing store will be a
block device; the details are discussed in Chapter 9. Section 4.6 and Chapter 16 are devoted to discussing
more about address spaces. Here it suffices to know that the address space is the base element of a

Free download pdf