Linux can have both standard 4KiB page memory and 1GiB (huge) paged memory (and 2MiB pages, but I don't know if anyone uses that).
Is there a standard call to get the page size from an arbitrary virtual address? The pointer could be pointing to 4K pages or huge pages.
The problem at hand is to sanity (assert(...)
) check arguments to a function that requires the base address and size of the region needs to be multiples of the page size, to be handed to mbind
. But the page size varies on the system. Without sanity checking, the return value of mbind
just gives Invalid argument
which is not helpful for debugging.
I've looked at this answer How to get linux kernel page size programmatically but it gives answers that assume that the entire system is the same, and they are also compile time constants. Also getpagesize()
does the same and it is deprecated anyways.
This is related to the MMU, see https://unix.stackexchange.com/questions/128213/how-is-page-size-determined-in-virtual-address-space and normally the page size is equal for the entire system / kernel, it is determined during kernel compilation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With