Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 4: Virtual Process Memory


❑ vm_pgoffsetspecifies an offset for a file mapping when not all file contents are to be mapped
(the offset is 0 if the whole file is mapped).

The offset is not expressed in bytes but in multiples ofPAGE_SIZE. On a system with
pages of 4 KiB, an offset value of 10 equates to an actual byte offset of 40,960. This is
reasonable because the kernel only supports mappings in whole-page units, and
smaller values would make no sense.

❑ vm_filepoints to thefileinstance that describes a mapped file (it holds a null pointer if the
object mapped is not a file). Chapter 8 discusses the contents of thefilestructure at length.
❑ Depending on mapping type,vm_private_datacan be used to store private data that are not
manipulated by the generic memory management routines. (The kernel ensures only that the
element is initialized with a null pointer when a new region is created.) Currently, only a few
sound and video drivers make use of this option.

vm_flagsstores flags to define the properties of a region. They are all declared as pre-processor constants
in<mm.h>.

❑ VM_READ,VM_WRITE,VM_EXEC,andVM_SHAREDspecify whether page contents can be
read, written, executed, or shared by several processes.
❑ VM_MAYREAD,VM_MAYWRITE,VM_MAYEXEC,andVM_MAYSHAREdetermine whether
theVM_*flagsmaybeset.Thisisrequiredforthemprotectsystem call.
❑ VM_GROWSDOWNandVM_GROWSUPindicate whether a region can be extended downward
or upward (to lower/higher virtual addresses). Because the heap grows from bottom to
top,VM_GROWSUPis set in its region;VM_GROWSDOWNis set for the stack, which grows from top
to bottom.
❑ VM_SEQ_READis set if it is likely that the region will be read sequentially from start to end;
VM_RAND_READspecifies that read access may be random. Both flags are intended as ‘‘prompts‘‘
for memory management and the block device layer to improve their optimizations (e.g., page
readahead if access is primarily sequential. Chapter 8 takes a closer look at this technique).
❑ IfVM_DONTCOPYis set, the relevant region is not copied when theforksystem call is executed.
❑ VM_DONTEXPANDprohibits expansion of a region by themremapsystem call.
❑ VM_HUGETLBis set if the region is based on huge pages as featured in some architectures.
❑ VM_ACCOUNTspecifies whether the region is to be included in the calculations for theovercommit
features. These features restrict memory allocations in various ways (refer to Section 4.5.3 for
more details).

4.4.3 The Priority Search Tree


Priority search treesare required to establish a connection between a region in a file and all virtual address
spaces into which the region is mapped. To understand how this connection is established, we need to
introduce some data structures of the kernel, which will be discussed in more detail and within a more
general context in the following chapters.
Free download pdf