RFR: 8319969: os::large_page_init() turns off THPs for ZGC
Stefan Karlsson
stefank at openjdk.org
Fri Dec 1 09:51:17 UTC 2023
There is code in `os::large_page_init()` that checks `/sys/kernel/mm/transparent_hugepage/enabled` and forcefully turns off `UseTransparentHugePages` if anonymous THPs are disabled in the OS:
if (UseTransparentHugePages && !HugePages::supports_thp()) {
if (!FLAG_IS_DEFAULT(UseTransparentHugePages)) {
log_warning(pagesize)("UseTransparentHugePages disabled, transparent huge pages are not supported by the operating system.");
}
UseLargePages = UseTransparentHugePages = false;
return;
}
This is problematic because ZGC doesn't use the `/sys/kernel/mm/transparent_hugepage/enabled` THPs, but instead the `/sys/kernel/mm/transparent_hugepage/shmem_enabled` THPs. So, with the following settings:
/sys/kernel/mm/transparent_hugepage/enabled: never
/sys/kernel/mm/transparent_hugepage/shmem_enabled: advise
the above code will force ZGC to run without THPs.
This PR is a proposal for how to work around this in the ZGC code without disturbing the the rest of the JVM too much. The patch:
1) remembers the initial values for UseLargePages and UseTransparentHugePages and saves those so that ZGC can continue using THPs even though they have been disabled for the rest of the JVM.
2) adds better logic to figure out if ZGC is actually going to get THPs for the heap or not. This is then used to more accurately log the current situation and allows for a precise usage of `madvise + MADV_HUGEPAGE`.
3) tweaks the generic pagesize logging to better reflect the situation when anonymous THPs are disabled but shared memory THPs are enabled and ZGC is used.
The result of this change can be seen in these tables:
ZGC large pages log output:
E (T) = Enabled (Transparent)
E (T, OS) = Enabled (Transparent, OS enforced)
D = Disabled
D = Disabled (OS enforced)
-XX:+UseTransparentHugePages
shem \ anon | always | madvise | never
------------+--------+---------+-------
always | E (T) | E (T) | E (T)
within_size | E (T) | E (T) | E (T)
advise | E (T) | E (T) | E (T)
never | D (OS) | D (OS) | D (OS)
deny | D (OS) | D (OS) | D (OS)
force | E (T) | E (T) | E (T)
-XX:-UseTransparentHugePages
shem \ anon | always | madvise | never
------------+-----------+-----------+-------
always | E (T, OS) | E (T, OS) | E (T, OS)
within_size | E (T, OS) | E (T, OS) | E (T, OS)
advise | D | D | D
never | D | D | D
deny | D | D | D
force | E (T, OS) | E (T, OS) | E (T, OS)`
OS reported usage of shared memory huge pages
Y = Yes
- = No
-XX:+UseTransparentHugePages
shem \ anon | always | madvise | never
------------+--------+---------+-------
always | Y | Y | Y
within_size | Y | Y | Y
advise | Y | Y | Y
never | - | - | -
deny | - | - | -
force | Y | Y | Y
-XX:-UseTransparentHugePages
shem \ anon | always | madvise | never
------------+--------+---------+-------
always | Y | Y | Y
within_size | Y | Y | Y
advise | - | - | -
never | - | - | -
deny | - | - | -
force | Y | Y | Y
OS reported usage of anonymous memory huge pages
Y = Yes
- = No
-XX:+UseTransparentHugePages
shem \ anon | always | madvise | never
------------+--------+---------+-------
always | Y | Y | -
within_size | Y | Y | -
advise | Y | Y | -
never | Y | Y | -
deny | Y | Y | -
force | Y | Y | -
-XX:-UseTransparentHugePages
shem \ anon | always | madvise | never
------------+--------+---------+-------
always | Y | - | -
within_size | Y | - | -
advise | Y | - | -
never | Y | - | -
deny | Y | - | -
force | Y | - | -
-------------
Commit messages:
- 8319969: os::large_page_init() turns off THPs for ZGC
Changes: https://git.openjdk.org/jdk/pull/16690/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=16690&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8319969
Stats: 303 lines in 10 files changed: 258 ins; 12 del; 33 mod
Patch: https://git.openjdk.org/jdk/pull/16690.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/16690/head:pull/16690
PR: https://git.openjdk.org/jdk/pull/16690
More information about the hotspot-dev
mailing list