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.
Get page size of target platform
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
cuviper
#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