RFR: JDK-8312492: Remove THP sanity checks at VM startup [v3]

Thomas Stuefe stuefe at openjdk.org
Fri Jul 28 20:03:04 UTC 2023


> When starting the JVM with -XX:+UseTransparentHugePages, we need to know if the OS supports THPs:
> 
> A) We could run on a super-old kernel (very unlikely, THPs are supported since 2.6.38 which is EOL since 2011)
> B) We could run on a kernel built without THP support, e.g. an embedded device
> C) We could run on a system with THPs disabled by the admin
> 
> The JVM does a little sanity test at startup: it mmaps an area the size of a huge page - but in small pages - then calls madvise(MADV_HUGEPAGE) on it. The JVM assumes if the madvise() worked, all is fine.
> 
> That sanity test is expensive since we allocate (reserve AND commit) an area, then signal khugepaged by advising to fold it into a huge page. That area could be large if the kernel supports 1 GB THP pages. We may end up committing 1 GB space at startup. And depending on the THP defrag settings, that allocation may have to wait for the khugepaged to allocate a 1 GB page. Even if it does not wait but relies on khugepaged to work concurrently its a bad idea.
> 
> The sanity test is also of not much use since it does not detect if THPs are disabled on the system (case (C)). Arguably, that is the majority of cases on existing Linux installations.
> 
> The correct - and much cheaper - way is to check the proc fs whether THPs are enabled. But we already do that since [JDK-8310233](https://bugs.openjdk.org/browse/JDK-8310233): "Fix THP detection on Linux" [[1]](https://github.com/openjdk/jdk/blob/37ca9024ef59d99cae0bd7e25b2e6d3c1e085f97/src/hotspot/os/linux/os_linux.cpp#L3762). And that test detects all cases (A)(B)(C). Therefore we can completely remove the sanity checks for THPs.
> 
> I tested the patch manually in a number of settings with THPs enabled, disabled, and not compiled into the kernel at all. There is no behavioral difference because since [JDK-8310233](https://bugs.openjdk.org/browse/JDK-8310233) we catch all relevant cases before ever entering this sanity test.
> 
> [1] https://github.com/openjdk/jdk/blob/37ca9024ef59d99cae0bd7e25b2e6d3c1e085f97/src/hotspot/os/linux/os_linux.cpp#L3762

Thomas Stuefe has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains three additional commits since the last revision:

 - Merge branch 'master' into JDK-8312492-Remove-THP-sanity-checks-at-VM-startup
 - Fix regression in tests
 - remove-thp-sanity-tests

-------------

Changes:
  - all: https://git.openjdk.org/jdk/pull/14967/files
  - new: https://git.openjdk.org/jdk/pull/14967/files/c3ce46f4..400e8d93

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=14967&range=02
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=14967&range=01-02

  Stats: 25055 lines in 445 files changed: 11364 ins; 11614 del; 2077 mod
  Patch: https://git.openjdk.org/jdk/pull/14967.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/14967/head:pull/14967

PR: https://git.openjdk.org/jdk/pull/14967


More information about the hotspot-runtime-dev mailing list