-
Notifications
You must be signed in to change notification settings - Fork 6.2k
JDK-8310233: Fix THP detection on Linux #14739
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
JDK-8310233: Fix THP detection on Linux #14739
Conversation
|
👋 Welcome back stuefe! A progress list of the required criteria for merging this PR into |
75829ce to
a216486
Compare
a216486 to
a6c19c9
Compare
Webrevs
|
jdksjolen
left a comment
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.
Hi Thomas,
Thanks for these changes. I've some suggestions for the code, but the conceptual change is good.
…ub.com:tstuefe/jdk into JDK-8310233-Linux-THP-initialization-incorrect
|
|
|
@jdksjolen Thanks a lot for your review! See inline remarks. Most of your code suggestions are good, but this patch just moved the static hugepage detection parts out of os_linux.cpp, and left them (mostly) alone otherwise, to avoid adding regressions. I'll keep your input in mind for the next round of cleanups. Wrt NonInterleavingLogStream, I decided to not do that. It is not needed, since we are single-threaded, and it without it I may still be lucky to get it integrated cleanly to at least 17. I added a new repro case. Please take a look! Thank you. |
jdksjolen
left a comment
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.
Some of the methods seems to leak file descriptors, other than that tests looks good.
|
Thanks @jdksjolen! I changed the test accordingly. |
jdksjolen
left a comment
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.
Thank you Thomas!
These changes look good to me now, I'm approving this.
|
@tstuefe 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 127 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
|
Gentle ping, second review needed. |
| return _default_hugepage_size; | ||
| } | ||
|
|
||
| // Scan /proc/meminfo and return value of Hugepagesize |
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.
Reviewer notes:
scan_default_hugepagesize is just a code move, it used to live in scan_default_large_page_size in os_linux.cpp. It is responsible for reading the default static hugepage size from /proc/meminfo. This code is mostly untouched to reduce chance for regressions (though the code could be tightened and cleaned for sure).
|
May I have a second review? |
|
@jdksjolen was kind enough to put this through Oracle's CI, all good. |
dholmes-ora
left a comment
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.
Not an area I am familiar with but scanning through the code this seems reasonable. A few minor comments below.
Thanks.
Many thanks, @dholmes-ora! Remarks follow. |
|
@dholmes-ora : I massaged in your feedback. |
dholmes-ora
left a comment
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.
Nothing further from me.
Thanks.
|
Thanks, @dholmes-ora ! /integrate |
|
Going to push as commit 37ca902.
Your commit was automatically rebased without conflicts. |
Today, if we use UseTransparentHugePages, we assume that the static hugepage detection we do is valid for THPs:
/proc/memlimit"Hugepagesize")Both assumptions are incorrect:
/sys/kernel/mm/transparent_hugepage/enabled, which is a tri-state value ("always", "madvise", "never"). THPs are available for the first two states.khugepagedis set in/sys/kernel/mm/transparent_hugepage/hpage_pmd_size. It can differ from the default page size used for static hugepages. For example, we could configure a system such that it uses 1G static hugepages, but the THP page size would still be 2M.About the patch:
This is a limited, minimally invasive patch to fix THP detection. The patch aims to be easy to downport. There is more work to do, which I will do in subsequent RFEs.
Functionally, for static (non-THP) pages nothing changes. THP-mode now correctly detects THP support in the OS, and uses the correct page size (see examples below).
Example 1: System has THPs disabled, but static hugepages (1g, 2m) configured:
Without patch, we incorrectly assume THPs are enabled, and that THP page size is 1G (!), which we then proceed and use as heap page size, causing the heap size to be rounded up from 512m -> 1G. But - even though it is printed as "1G page backed" in log output - in reality it will still 4K-page-backed: the
madvise(2)we use to set the THP page size will be ignored by the system, since THPs are disabled.With patch, we correctly refuse to use large pages (and we log more info):
Example 2: System has THPs enabled, but THP page size is just 2M, whereas the system uses a static default hugepage size of 1G:
Without patch, THP page size is not correctly recognized as 2M. Instead, we again use 1G as page size for the heap:
With patch, we correctly identify the THP page size as 2M, and use that for the heap:
Tests: GHAs all green. Local experiments on x64 Linux on machines with 1G pages succeeded.
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/14739/head:pull/14739$ git checkout pull/14739Update a local copy of the PR:
$ git checkout pull/14739$ git pull https://git.openjdk.org/jdk.git pull/14739/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 14739View PR using the GUI difftool:
$ git pr show -t 14739Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/14739.diff
Webrev
Link to Webrev Comment