Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 4: Virtual Process Memory


4.3 Principle of Memory Mappings


Because the total virtual address space of all user processes issubstantiallylarger than the available RAM
memory, only the most frequently used elements can be associated with a physical page frame. This
is not a problem because most programs occupy only a small part of the memory actually available to
them. Let’s look at the situation in which a file is manipulated by a text editor. Typically, the user is only
bothered with the end of the file so although the complete file is mapped into memory, only a few pages
are actually used to store the data at the end of the file. As for the beginning of the file, the kernel need
only keep the information in address space about where on the disk to find the data and how to read
them when they are required.

The situation is similar with the text segment — only part of it is always needed. If we stay with the
example of the text editor, only the code for the central editing function is required. Other parts — the
Help system or the obligatory Web and e-mail client common to all programs — are only loaded when
explicitly required by the user.^3

The kernel must provide data structures to establish an association between the regions of the virtual
address space and the places where the related data are located. In the case of a mapped text file, for
example, the virtual memory area must be associated with the area on the hard disk in which the filesys-
tem has stored the contents of the file. This is illustrated in Figure 4-4.

Virtual

Virtual Process Address Space


File on hard disk

Figure 4-4: Mapping a file into virtual memory.

Of course, I have shown the situation in simplified form because file data are not generally stored con-
tiguously on hard disk but are distributed over several smaller areas (this is discussed in Chapter 9). The
kernel makes use of theaddress_spacedata structure^4 to provide a set of methods to read data from
abacking store— from a filesystem, for example.address_spaces therefore form an auxiliary layer to
represent the mapped data as a contiguous linear area to memory management.

Allocating and filling pages on demand is known asdemand paging. It is based on interaction between the
processor and the kernel using a variety of data structures as shown in Figure 4-5.

(^3) I assume that all program parts reside in a single, large binaryfile. Of course, program parts can also be loaded at the explicit
request of the program itself, but I do not discuss this here.
(^4) Unfortunately, the names for the virtual address space and the address space indicating how thedata are mapped are identical.

Free download pdf