In Linux, the kernel maintains a three-level page table (regardless of the CPU’s capabilities). The top level is the page global directory, and each process has its own directory, pgd
in mm_struct
. Thus each process can have its own mappings, so address 12345 in different processes points to different physical addresses.
CPUs aren’t really aware of processes, but they do tend to have features to support them. On x86-style CPUs, there are various task-related features, but they actually tend to be ignored. Since process scheduling is managed by the kernel, it can keep track of page table changes itself, and update whatever CPU state is required to switch to a new process’s page table when it switches tasks. On x86 PCs, that involves updating the CR3 control register which points to the page directory.
The Page Table Management chapter in Mel Gorman’s Understanding the Linux Virtual Memory Manager book gives a good overview.
So first of all, it is not possible just like that to run 32 bit executable on a 64 bit system. So you don't need to translate the 32 bit address in a 64 bit address or something like that.
Second, 32 bit (without PAE) simply does not allow to map memory above the 4 GB border.
I thought a lot about the problem and by reading the section several times, I figured it out.
You may have seen the similar question on StackOverflow: Linux Kernel Memory Management Paging Levels
But I try to explain it how I understood it.
The thing I try to explain is how four level paging works on a 32 bit system.
The first sentence is essential
[...] eliminates the Page Upper Directory and the Page Middle Directory fields by saying that they contain zero bits.
This does not mean, that the kernel sets these fields to zero but it says these are zero without expressing this somewhere.
So you have the usual 32 bit address separation for a two level paging.
This means you use the 10 most significant bits of the virtual address for PML4 (Linux: PGD).
The PML4 (Linux: PGD) points to the PDPT (Linux: PUD) which has only one entry. Because the kernel says, the index/offset is zero, this only entry is taken.
The only entry of the PDPT (Linux: PUD) points to the PD (Linux: PMD) which again has only one entry. And again, the kernel says, the index/offset is zero, so this only entry is taken.
And finally, the only entry of the PD (Linux: PMD) points to the PT, where the intermediate 10 bits of the virtual address are used as the index to find the wanted page.
Summarized in short:
[1024 *] PML4 (Linux: PGD) -> 1 * PDPT (Linux: PUD) -> 1 * PD (Linux: PMD) -> 1024 * PT
Best Answer
You are correct. The VM of a process consists of the user address space and kernel address space. The kernel address space is the same across all processes but protected from access. If you've heard the 2/2 or 3/1 memory split (from x32), it was the user/kernel amount of memory in GBs. So for a 4GB address space you could (e.g.) have 3G for processes and 1G for the kernel.
I would recommend reading the "Understanding the Linux Kernel" book which will answer this and many other of your questions.