2

I am curious what is the size of the x86_64 linux kernel page. I heard that it is 4KB but some other sources tell it is 2MB.

I am also curious if the user kernel page size can be different from the kernel page size. Can linux use 2MB for the kernel page and 4KB for the user page?

Thanks

3

The page size on the x86_64 architecture (same as in i386 or IA-32, which is the 32-bit version of the architecture) is 4KiB.

You will also see references to 2MiB because that's one of the sizes of "huge pages" in the x86_64 architecture, which also allows for 1GiB huge pages, which are used in Linux in some situations as well. (The 32-bit variant i386 or IA-32 has 4MiB huge pages instead.)

Furthermore, the Linux kernel has a feature called "transparent huge pages," which is often enabled by default in many modern Linux distributions. Whenever a process allocates larger amounts of memory, the Linux kernel might decide to allocate 2MiB aligned chunks of memory and to set the page tables to give the process huge pages instead. But if the system goes into memory pressure and needs to swap out some memory, it's still able to break that down into separate pages, so it can swap some of them out and keep the others in memory. (In some circumstances, it is also able to reassemble transparent huge pages from an allocation that included single pages.)

In regards to kernel vs. userspace, there are several nuances into how page tables are set up (and security features, particularly ones introduced after the latest security issues such as Spectre and Meltdown, try to isolate page table mappings from kernel and userspace.) But typically both kernel and userspace will access the same memory region the same way, for instance huge pages (transparent or otherwise) will also use huge page mappings when in kernel mode.

  • Thank you for the detailed explanation. Is the page sizing configurable by any chance? – Atul May 12 at 15:18
  • 1
    @Atul: Not on x86_64, it is not configurable, it is a characteristic of the hardware and the VMM in x86_64 only supports those sizes. Some archirectures permit different page sizes, for instance IBM POWER supports 64KiB or 16KiB (more recently, POWER9 also supports 4KiB), Linux kernel itself only picks one of those via a compile-time option (I believe other kernels such as IBM AIX would allow mixing those page sizes in the same running system, but I might be wrong about that.) – filbranden May 12 at 15:24
  • 1
    Thank you for the explanation :) – Jaebum May 12 at 21:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.