RFR: 8253683: Clean up and clarify uses of os::vm_allocation_granularity
Casper Norrbin
cnorrbin at openjdk.org
Tue Nov 25 14:40:48 UTC 2025
Hi everyone,
`os::vm_allocation_granularity()` is meant to describe the alignment restrictions of the operating system when we reserve memory. That is 64 KiB on Windows (`VirtualAlloc`) and 256 MiB on AIX (with `shmat`). On every other platform it happens to match the page size. The page size (available via `os::vm_page_size()`) is what matters when we later commit or protect the reserved pages.
Because the functions are poorly documented and the two numbers are identical on most systems, they have gradually been used more and more interchangeably. We now have many code paths that round **sizes** up to `os::vm_allocation_granularity()` or assert that a size is a multiple of it. That is wrong. Only addresses need that alignment, sizes merely have to be page-aligned. Places that round sizes should instead use `os::vm_page_size()` as they are unrelated to attach alignment.
For this change I have gone over the call sites of `os::vm_allocation_granularity()` and where it was being used to pad or sanity-check a size I have instead replaced it with `os::vm_page_size()`. The calls that genuinely deal with an attach address are left untouched.
Testing:
- Oracle tiers 1-8
-------------
Commit messages:
- Changed allocation_granularity for page_size for aligning sizes
Changes: https://git.openjdk.org/jdk/pull/28493/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=28493&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8253683
Stats: 58 lines in 17 files changed: 3 ins; 4 del; 51 mod
Patch: https://git.openjdk.org/jdk/pull/28493.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/28493/head:pull/28493
PR: https://git.openjdk.org/jdk/pull/28493
More information about the hotspot-dev
mailing list