Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux Kernel Memory Management Paging Levels

I'm reading through the book "Understanding Linux Kernel" by Bovet and Cesati. In the second chapter, under "Paging in Linux" the author mentions how Page Middle and Upper Directories are eliminated with 32 architectures not having PAE enabled. I'm having trouble following what the author means.

They have been loose in their treatment and does not make a whole lot of intuitive sense.

For 32-bit architectures with no Physical Address Extension, two paging levels are sufficient. Linux essentially eliminates the Page Upper Directory and the Page Middle Directory fields by saying that they contain zero bits. However, the positions of the Page Upper Directory and the Page Middle Directory in the sequence of pointers are kept so that the same code can work on 32-bit and 64-bit architectures. The kernel keeps a position for the Page Upper Directory and the Page Middle Directory by setting the number of entries in them to 1 and mapping these two entries into the proper entry of the Page Global Directory.

Can someone explain this in a more palatable manner?

like image 389
subramanian Avatar asked Sep 23 '12 23:09

subramanian


1 Answers

Well, I think what is meant is that the kernel always uses 4 levels of page tables, which can accommodate both normal 32 bit, PAE, and long mode. I think what they mean in the quote is that the PM4L and the PDT are just set to a length of one entry which just points to the next one down. So that means that in normal 32 bit, you get this:

                              /-> Page table
PM4L -> PDT -> Page Directory --> Page table
                              \-> Page table

But in PAE, you get this:

PM4L -> PDT -> 512 Page Directories -> 1024 Page tables

And in Long mode, you get this:

PM4L -> 512 PDTs -> 512 Page Directories -> 1024 Page tables

But because of the 4 levels always, the rest of the kernel has a unified interface across 32 bits, PAE, and long mode.

like image 152
Linuxios Avatar answered Nov 09 '22 03:11

Linuxios