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.

1 Like

This is definitely a runtime rather than compile time constraint. On most *nix systems you'd call sysconf(3) - Linux manual page

1 Like

Ah, oh well. Thanks!

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

2 Likes

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

2 Likes