Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


Not only the length but also the way in which the address is split are different on the individual
architectures. The kernel therefore defines macros to break down the address into its individual
components.


PAGE_SHIFT
PMD_SHIFT
PUD_SHIFT
PGDIR_SHIFT

BITS_PER_LONG

PGD PUD PMD PTE Offset

Figure 3-7: Breakdown of a virtual address.

Figure 3-7 shows how the positions of the address elements are defined by bit shifts.BITS_PER_LONG
specifies the number of bits used for anunsigned longvariable and therefore also for a generic pointer
to virtual address space.


At the end of each pointer there are several bits to specify the position within the selected frame page.
The number of bits required is held inPAGE_SHIFT.


PMD_SHIFTspecifies thetotalnumber of bits used by a pageandby an entry in the last level of the page
tables. This number can be subtracted fromPAGE_SHIFTto determine the number of bits required by
an entry in the last hierarchy level of the page table. More important is the fact that the value indicates
the size of the partial address space managed by an entry in the middle page table, namely, 2PMD_SHIFT
bytes.


PUD_SHIFTadds together the bit lengths ofPAGE_OFFSETandPMD_SHIFT,whereasPGDIR_SHIFTcombines
the bit lengths ofPAGE_OFFSET,PUD_SHIFT,andPMD_SHIFTwith the bit number of an entry in the page
middle directory. The value is the binary logarithm of the size of the partial address space that can be
addressed via an entry in the page global directory.


The number of pointers that can be stored in the various directories of the page table is also deter-
mined by macro definitions.PTRS_PER_PGDspecifies the number of entries in the page global directory,
PTRS_PER_PMDthe number in the page middle directory,PTRS_PER_PUDthe number in the page upper
directory, andPTRS_PER_PTEthe number in the page table entry.


Architectures with two-level page tables definePTRS_PER_PMDandPTRS_PER_PUDas


  1. This persuades the remaining parts of the kernel that they are working with
    four-level page translation although only two pages are used — the page middle
    and page upper directories are effectively eliminated because they have only a
    single entry. Because only a very few systems use a four-level page table, the kernel
    uses the header fileinclude/asm-generic/pgtable-nopud.hto hold all the declara-
    tions needed to simulate the presence of a fourth page table. The header file
    include/asm-generic/pgtable-nopmd.his also available to simulate the presence
    of a third page table level on systems with two-level address translation.

Free download pdf