Get page size of target platform


Is it possible to get the page size for the target platform programmatically? Ideally this would be as a compile-time constant, but a runtime variable would be good too.

Conditional compilation using compile-time logic?

This is definitely a runtime rather than compile time constraint. On most *nix systems you’d call


Ah, oh well. Thanks!


Note that some platforms have multiple page sizes (4KB, 2MB and 1GB on x86).


The raw PAGE_SIZE is always 4096 on x86 Linux – huge pages are a different beast.

Still, there definitely are other arches that have (statically) configurable sizes. Just grep for define PAGE_SHIFT in the kernel sources for a taste, or PAGE_SHIFT definitions in lxr. And there are other OSes that can have more dynamic per-process page sizes.

Here’s a taste of what can go wrong if you statically compile the page size: