Figure 318 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 called canonical. 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 248 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 that 0x0000 7FFF ffff ffff is 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 0000 has 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 from page_offset. 246 bits (as specified by maxmem) are reserved for physical page frames. This amounts to 16 TiB of memory.

15There 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.

16The kernel sources contain some documentation about the address space layout in Documentation/x86_64/mm.txt.

include/asm-x86/pgtable_64.h

#define _PAGE_OFFSET _AC(0xffff810000000000, UL)

#define PAGE_OFFSET _PAGE_OFFSET

#define MAXMEM _AC(0x3fffffffffff, UL)

Non-canonical area

Hole

(unused)

2 Bits (MAXMEM)

Identity maped pages

212 Bits kernel_text_size Modules

M

V V

K

M

M

L

s s p g

p

(.0

(.0

O

o

p

H

H

P

p

P H

z

A

A

z

z

-

P g

p

X

X

z

z

O

H g o A

p

p

P

H

H

O

(.0

(.0

P

p

p

P

(.0

E_

p

p

P

V

H

H

p in

X

X

X

A

z

A

p p

p

z

z

z

z

P

A

P

P

p

H

H

P

-

p

Continue reading here: Figure 319 Organization of the virtual address space on AMD64 systems The image is not drawn to scale naturally

Was this article helpful?

0 0