RFR: JDK-8312492: Remove THP sanity checks at VM startup
Thomas Stuefe
stuefe at openjdk.org
Fri Jul 21 08:18:04 UTC 2023
On Fri, 21 Jul 2023 08:05:47 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:
> 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 and has little merit.
>
> It will not detect if THPs are disabled on the system (C) - since madvise reports success even then.
>
> It 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 correct - and much cheaper - way is to check the proc fs whether THPs are enabled. We already do that since [JDK-8310233](https://bugs.openjdk.org/browse/JDK-8310233): "Fix THP detection on Linux". That check takes care of (A)(B)(C). Therefore we can remove the THP sanity check completely.
src/hotspot/os/linux/os_linux.cpp line 2808:
> 2806: #define MADV_HUGEPAGE 14
> 2807: #endif
> 2808:
Reviewer note: I remove this since I am sure nobody builds on Linux < 2.6.38 - and if we would, probably a lot of other stuff would break first. I am unemotional though and could leave it in if desired.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/14967#discussion_r1270374640
More information about the hotspot-runtime-dev
mailing list