Memory Regions

Linux implements a memory region by means of an object of type vm_area_struct; its fields are shown in Table 8-3.

Table 8-3. The fields of the memory region object

Type

Field

Description

struct mm struct *

vm_mm

Pointer to the memory descriptor that owns the region

unsigned long

vm start

First linear address inside the region

unsigned long

vm end

First linear address after the region

struct vm area struct *

vm next

Next region in the process list

pgprot t

vm page prot

Access permissions for the page frames of the region

unsigned long

vm flags

Flags of the region

rb node t

vm rb

Data for the red-black tree (see later in this chapter)

struct vm area struct *

vm next share

Pointer to the next element in the file memory mapping list

struct vm area struct **

vm pprev share

Pointer to previous element in the file memory mapping list

struct vm operations struct *

vm_ops

Pointer to the methods of the memory region

unsigned long

vm pgoff

Offset in mapped file, if any (see Chapter 15)

struct file *

vm_file

Pointer to the file object of the mapped file, if any

unsigned long

vm raend

End of current read-ahead window of the mapped file (see Section 15.2.4)

Each memory region descriptor identifies a linear address interval. The vm_start field contains the first linear address of the interval, while the vm_end field contains the first linear address outside of the interval; vm_end - vm_start thus denotes the length of the memory region. The vm_mm field points to the mm_struct memory descriptor of the process that owns the region. We shall describe the other fields of vm_area_struct as they come up.

Memory regions owned by a process never overlap, and the kernel tries to merge regions when a new one is allocated right next to an existing one. Two adjacent regions can be merged if their access rights match.

As shown in Figure 8-1, when a new range of linear addresses is added to the process address space, the kernel checks whether an already existing memory region can be enlarged (case a). If not, a new memory region is created (case b). Similarly, if a range of linear addresses is removed from the process address space, the kernel resizes the affected memory regions (case c). In some cases, the resizing forces a memory region to split into two smaller ones (case d ).[2]

[2] Removing a linear address interval may theoretically fail because no free memory is available for a new memory descriptor.

Figure 8-1. Adding or removing a linear address interval

Figure 8-1. Adding or removing a linear address interval

Modified Folfirinox

The vm_ops field points to a vm_operations_struct data structure, which stores the methods of the memory region. Only three methods are defined:

open

Invoked when the memory region is added to the set of regions owned by a process.

close

Invoked when the memory region is removed from the set of regions owned by a process.

nopage

Invoked by the Page Fault exception handler when a process tries to access a page not present in RAM whose linear address belongs to the memory region (see the later section Section 8.4).

Was this article helpful?

0 0

Post a comment