-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8319969: os::large_page_init() turns off THPs for ZGC #16690
Conversation
👋 Welcome back stefank! A progress list of the required criteria for merging this PR into |
ea584ae
to
7c70720
Compare
7c70720
to
7b29a1d
Compare
7b29a1d
to
c277417
Compare
Webrevs
|
At first glance it looks reasonable, but I will look at it closer next week (no time). Thanks for following the clean separation of OS-info vs what-the-jvm-does-with-it. |
Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small question:
https://wiki.openjdk.org/display/zgc/Main#Main-EnablingTransparentHugePagesOnLinux
mentions that to use THPs with ZGC, one needs both
/sys/kernel/mm/transparent_hugepage/enabled -> "madvise"
and /sys/kernel/mm/transparent_hugepage/shmem_enabled -> "advise"
in conjunction. Is that correct, the latter needs the former? I did not read this from https://www.kernel.org/doc/html/next/admin-guide/mm/transhuge.html.
src/hotspot/os/linux/os_linux.cpp
Outdated
return; | ||
} | ||
|
||
log_warning(pagesize)("UseTransparentHugePages disabled, transparent huge pages are not supported by the operating system."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be not clearer to define when to warn, as we do in warn_no_large_pages?
Related to that, should we not warn if ZGC and +shmemthp configured but -anonymous thp? I am not sure the heap is the only part of the JVM that uses THP, and other parts would still use anon THP, or? E.g. Code heap.
Also, maybe a better message for the poor admin that tries to setup. E.g.:
bool requires_shmem_thp = UseTHP + UseZGC
bool requires_anon_thp = UseTHP
bool off = false;
if (requires_shmem && !shmem configured)
(log_warning "Shmem thp are not supported. Set /sys/kernel/mm/transparent_hugepage/shmem_enabled to advise to support shmem thp")
off = true;
if (requires_anonthp && !anon_thp configured)
(log_warning "anonymous Thp are not supported. Set /sys/kernel/mm/transparent_hugepage/enabled to madvise")
off = true;
if (off)
UseTHP = 0
log_warning(UseTHP disabled (see previous messages)
if ZGC and !supports shmemthp or
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be not clearer to define when to warn, as we do in warn_no_large_pages?
I don't understand what you are suggesting with this question / request, so I'm not sure exactly what you are looking for. Instead, I made my own version of the pseudo code you posted.
This is the warnings I get with that change:
Without ZGC:
$ thp never never
always madvise [never]
always within_size advise [never] deny force
$ java -XX:+UseTransparentHugePages -version
[0.002s][warning][pagesize] Anonymous transparent huge pages are not enabled in the OS. Set /sys/kernel/mm/transparent_hugepage/enabled to 'madvise' to enable them.
[0.002s][warning][pagesize] UseTransparentHugePages disabled, transparent huge pages are not supported by the operating system.
...
$ thp never advise
always madvise [never]
always within_size [advise] never deny force
java -XX:+UseTransparentHugePages -version
[0.002s][warning][pagesize] Anonymous transparent huge pages are not enabled in the OS. Set /sys/kernel/mm/transparent_hugepage/enabled to 'madvise' to enable them.
[0.002s][warning][pagesize] UseTransparentHugePages disabled, transparent huge pages are not supported by the operating system.
...
$ thp madvise never
always [madvise] never
always within_size advise [never] deny force
$ java -XX:+UseTransparentHugePages -version
...
$ thp madvise advise
always [madvise] never
always within_size [advise] never deny force
$ java -XX:+UseTransparentHugePages -version
...
With ZGC:
$ thp never never
always madvise [never]
always within_size advise [never] deny force
$ java -XX:+UseTransparentHugePages -XX:+UseZGC -version
[0.002s][warning][pagesize] Shared memory transparent huge pages are not enabled in the OS. Set /sys/kernel/mm/transparent_hugepage/shmem_enabled to 'advise' to enable them.
[0.002s][warning][pagesize] Anonymous transparent huge pages are not enabled in the OS. Set /sys/kernel/mm/transparent_hugepage/enabled to 'madvise' to enable them.
[0.002s][warning][pagesize] UseTransparentHugePages disabled, transparent huge pages are not supported by the operating system.
...
$ thp never advise
always madvise [never]
always within_size [advise] never deny force
$ java -XX:+UseTransparentHugePages -XX:+UseZGC -version
[0.001s][warning][pagesize] Anonymous transparent huge pages are not enabled in the OS. Set /sys/kernel/mm/transparent_hugepage/enabled to 'madvise' to enable them.
[0.001s][warning][pagesize] UseTransparentHugePages disabled, transparent huge pages are not supported by the operating system.
...
$ thp madvise never
always [madvise] never
always within_size advise [never] deny force
$ java -XX:+UseTransparentHugePages -XX:+UseZGC -version
[0.002s][warning][pagesize] Shared memory transparent huge pages are not enabled in the OS. Set /sys/kernel/mm/transparent_hugepage/shmem_enabled to 'advise' to enable them.
...
$ thp madvise advise
always [madvise] never
always within_size [advise] never deny force
$ java -XX:+UseTransparentHugePages -XX:+UseZGC -version
...
Please take a look and see if this is an OK solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is okay, what do you think? Too many messages?
@@ -3713,16 +3733,24 @@ struct LargePageInitializationLoggerMark { | |||
os::page_sizes().print_on(&ls); | |||
ls.print_cr(". Default large page size: " EXACTFMT ".", EXACTFMTARGS(os::large_page_size())); | |||
} else { | |||
ls.print("Large page support disabled."); | |||
ls.print("Large page support %sdisabled.", uses_zgc_shmem_thp() ? "partially " : ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder whether we could make our life simpler by not supporting mixes: we could require that for ZGC, to use THP, both shmen and anon thps have to be active. Would that be acceptable or do you think there are too many misconfigured systems out there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to not force users to set both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. It is better to be able to run efficiently on as many configurations as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is good. Thank you.
@stefank This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been no new commits pushed to the ➡️ To integrate this PR with the above commit message to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks all for reviewing!
I've run this through our tier1-tier5 testing.
/integrate |
Going to push as commit f482260.
Your commit was automatically rebased without conflicts. |
There is code in
os::large_page_init()
that checks/sys/kernel/mm/transparent_hugepage/enabled
and forcefully turns offUseTransparentHugePages
if anonymous THPs are disabled in the OS: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: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:
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.
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
.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:
OS reported usage of shared memory huge pages
OS reported usage of anonymous memory huge pages
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/16690/head:pull/16690
$ git checkout pull/16690
Update a local copy of the PR:
$ git checkout pull/16690
$ git pull https://git.openjdk.org/jdk.git pull/16690/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 16690
View PR using the GUI difftool:
$ git pr show -t 16690
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/16690.diff
Webrev
Link to Webrev Comment