Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 4: Virtual Process Memory



  1. pte_file(pte)checks if a given page table entry is used to represent a nonlinear mapping.
    This especially allows for distinguishing a page table entry of a nonlinear mapping from a
    page table entry for a regular swapped-out page when a page fault occurs.


The pre-processor constantPTE_FILE_MAX_BITSdenotes how many bits of a page table entry can be
used to store a file offset. Since this constant will usually be smaller than the word size of the processor
because some status bits in the PTE are required by the architecture and to distinguish it from swap-PTEs,
the range of a file that can be remapped is, in general, smaller than the maximally possible file size.

Since the layout of non-present page table entries is not plagued by any historical oddities on IA-64,
the way nonlinear PTEs are implemented is particularly clean, so I present it as an example, which is
illustrated in Figure 4-14.

include/asm-ia64/pgtable.h
#define PTE_FILE_MAX_BITS 61
#define pte_to_pgoff(pte) ((pte_val(pte) << 1) >> 3)
#define pgoff_to_pte(off) ((pte_t) { ((off) << 2) | _PAGE_FILE })

_PAGE_PROTNONE _PAGE_FILE_PAGE_PRESENT

10

63

Nonlinear page
offset

Figure 4-14: Representing
nonlinear mappings in page
table entries on IA-64
systems.

Swap identifiers are 64 bits long. Bit 0 must be zero because the page is not present, and bit 1 represents
_PAGE_FILEto indicate that the entry belongs to a nonlinear mapping in contrast to a swap specifier. The
last bit, that is, 63, is reserved for the_PAGE_PROTNONEbit.^12 Consequently,thisleaves61bitsrawcapacity
to represent the nonlinear page offset.

pte_to_pgofffirst extracts the value stored in the page table entry withpte_valas provided by the
architecture-specific code. Performing one left-shift and two right-shifts is a simple method to extract the
bits at position [2, 62]. When a PTE representing a nonlinear mapping is constructed, the kernel needs to
shift the offset into the bit range starting at bit 2, and must additionally ensure that_PTE_FILEis set to
identify it as a nonlinear mapping in contrast to a regular swapped-out identifier.

The essential steps ofsys_remap_file_pagesare summarized in the code flow diagram in Figure 4-15.

(^12) A page with this bit set was marked as completely inaccessible by themmapsystem call. While such pages do not need to be
backed by a physical page frame (they are not accessible, so what should be read from or written to the page?), the kernel never-
theless has to mark somehow that they must not be accessed, and the aforementioned bit provides this capability.

Free download pdf