Chapter3:MemoryManagement
Since future hardware implementations might support larger physical address spaces, it is not possible
to simply to remap the subset that is not addressable to a different subset of the address space. Suppose
that any program would rely on pointers into the unimplemented address space to be remapped to some
part of the regular address space. Next-generation processors that implement more physical address bits
would lead to a different behavior and thus break all existing code.
Clearly, accessing the unimplemented regions must be hindered by the processor. One possibility to
enforce this would be to forbid use of all virtual addresses larger than the physical address space. This,
however, is not the approach chosen by the hardware designers. Their solution is based on asign extension
approach, which is illustrated in Figure 3-18.
Higher
half
Lower
half
Kernelspace
o × FFFF
Userspace
o
(^264) FFFF FFFF FFFF
o × 0000 7FFF FFFF FFFF Bits [0,46] arbitrary
[47, 63] not set
Bits [0,46] arbitrary
[47, 63] not set
o × FFFF
Non-canonical area
8000 0000 0000
Figure 3-18: Possible virtual versus implemented physical address
space on AMD64 machines.
The first 47 bits of a virtual address, that is, [0, 46], can be arbitrarily set. Bits in the range [47, 63], however,
always need to have the same value: Either all are 0, or all are 1. Such addresses are calledcanonical.They
divide the total address space into three parts: a lower half, a higher half, and a forbidden region in
between. Together both portions form an address space that spans exactly 2^48 bits. The address space for
the lower half is [0x0,0x0000 7FFF FFFF FFFF], while the subset for the top half is [0xFFF 800 0000 0000,
0xFFFF FFFF FFFF FFFF]. Notice that0x0000 7FFF FFFF FFFFis a binary number with the lower 47 bits set
to 1 and all other bits not set, so it is the last address before the non-addressable region. Similarly,0xFFFF
8000 0000 0000has the bits [48, 63] set and is thus the first valid address in the higher half.
Partitioning the virtual address space into two parts is nothing the kernel is afraid of: It actually relies
on a separation of the address space into kernel and user parts on most architectures.^15 The separation
enforced by the AMD64 therefore lends itself naturally to implement the separation between user and
kernel address space. Figure 3-19 shows how the Linux kernel lays out the virtual address space on
AMD64 machines.^16
The complete lower half of the accessible address space is used as userspace, while the complete upper
half is reserved for the kernel. Since both spaces are huge, no fiddling with splitting ratios and the like is
required.
The kernel address space starts with a guard hole to prevent incidental access on the non-canonical
portion of the address space that would result in a general protection exception raised by the processor.
Physical pages are identity-mapped into kernel space starting fromPAGE_OFFSET.2^46 bits (as specified by
MAXMEM) are reserved for physical page frames. This amounts to 16 TiB of memory.
(^15) There are also machines that allow a different approach. UltraSparc processors provide different virtual address spaces for user
and kernel space per default, so a separation of one address space into two components is not required.
(^16) The kernel sources contain some documentation about the address space layout inDocumentation/x86_64/mm.txt.