Get page size of target platform


#1

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?
#2

This is definitely a runtime rather than compile time constraint. On most *nix systems you’d call http://man7.org/linux/man-pages/man3/sysconf.3.html


#3

Ah, oh well. Thanks!


#4

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


#5

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:
https://github.com/jemalloc/jemalloc/issues/467