diff --git a/src/hotspot/os/linux/os_linux.cpp b/src/hotspot/os/linux/os_linux.cpp index d1447dc2f68..4e76b0c0cf3 100644 --- a/src/hotspot/os/linux/os_linux.cpp +++ b/src/hotspot/os/linux/os_linux.cpp @@ -3977,6 +3977,17 @@ void os::Linux::large_page_init() { // Query OS information first. HugePages::initialize(); + // SapMachine 2025-12-10 Enable UseTransparentHugePages if supported and the huge pages + // are not extremely large and no other configuration is selected by flags. + // Some GCs have additional requirements, are optimized for ultra-low latency or + // have limitations regarding configuration parameters with small heap sizes. + if (FLAG_IS_DEFAULT(UseLargePages) && FLAG_IS_DEFAULT(UseTransparentHugePages) && + HugePages::supports_thp() && HugePages::thp_pagesize() <= 2*M && + !UseZGC && !UseShenandoahGC && + (FLAG_IS_DEFAULT(MaxHeapSize) || MaxHeapSize > 128*M)) { + _thp_requested = UseTransparentHugePages = true; + } + // If THPs are unconditionally enabled (THP mode "always"), khugepaged may attempt to // coalesce small pages in thread stacks to huge pages. That costs a lot of memory and // is usually unwanted for thread stacks. Therefore we attempt to prevent THP formation in diff --git a/src/java.base/share/man/java.md b/src/java.base/share/man/java.md index 8517e161e3f..c2b14b37fd2 100644 --- a/src/java.base/share/man/java.md +++ b/src/java.base/share/man/java.md @@ -20,6 +20,8 @@ # or visit www.oracle.com if you need additional information or have any # questions. # +# SapMachine 2025-12-10 Changed description of UseTransparentHugePages which is +# tested by us. title: 'JAVA(1) JDK @@VERSION_SHORT@@ | JDK Commands' date: @@COPYRIGHT_YEAR@@ @@ -1576,9 +1578,11 @@ These `java` options control the runtime behavior of the Java HotSpot VM. `-XX:+UseTransparentHugePages` : **Linux only:** Enables the use of large pages that can dynamically grow or - shrink. This option is disabled by default. You may encounter performance - problems with transparent huge pages as the OS moves other pages around to - create huge pages; this option is made available for experimentation. + shrink. The VM may enable this option by default in some environments. You + may encounter performance problems with transparent huge pages as the OS + moves other pages around to create huge pages. You may encounter other + performance problems when only small pages are used as the OS needs to + maintain a large page table and address translations may become slow. `-XX:+AllowUserSignalHandlers` : **Non-Windows:** Enables installation of signal handlers by the application. By default, diff --git a/test/hotspot/jtreg/compiler/codecache/CheckSegmentedCodeCache.java b/test/hotspot/jtreg/compiler/codecache/CheckSegmentedCodeCache.java index 06b51b1641d..f271af64cdd 100644 --- a/test/hotspot/jtreg/compiler/codecache/CheckSegmentedCodeCache.java +++ b/test/hotspot/jtreg/compiler/codecache/CheckSegmentedCodeCache.java @@ -231,12 +231,13 @@ public static void main(String[] args) throws Exception { // Reserved code cache is set, NonNmethod segment size is set, two other segments is automatically // adjusted to half of the remaining space + // SapMachine 2025-12-10 We support 2MB transparent huge pages, so we need a multiple of it. pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:+SegmentedCodeCache", - "-XX:ReservedCodeCacheSize=100M", + "-XX:ReservedCodeCacheSize=102M", // original: 100M "-XX:NonNMethodCodeHeapSize=10M", "-XX:+PrintFlagsFinal", "-version"); - verifyCodeHeapSize(pb, " ProfiledCodeHeapSize", 47185920); + verifyCodeHeapSize(pb, " ProfiledCodeHeapSize", 48234496); // = 46M, original: 47185920 // Reserved code cache is set but NonNmethodCodeHeapSize is not set. // It's calculated based on the number of compiler threads diff --git a/test/hotspot/jtreg/compiler/codecache/cli/codeheapsize/GenericCodeHeapSizeRunner.java b/test/hotspot/jtreg/compiler/codecache/cli/codeheapsize/GenericCodeHeapSizeRunner.java index e7c68e71ab3..e02d69b1cea 100644 --- a/test/hotspot/jtreg/compiler/codecache/cli/codeheapsize/GenericCodeHeapSizeRunner.java +++ b/test/hotspot/jtreg/compiler/codecache/cli/codeheapsize/GenericCodeHeapSizeRunner.java @@ -44,7 +44,8 @@ public void run(CodeCacheCLITestCase.Description testCaseDescription, Long.toString(expectedValues.reserved), String.format("%s should have value %d.", BlobType.All.sizeOptionName, expectedValues.reserved), - testCaseDescription.getTestOptions(options)); + // SapMachine 2025-12-10 We don't get exact matches when rounding to large page sizes. + testCaseDescription.getTestOptions(options, "-XX:-UseLargePages")); CommandLineOptionTest.verifyOptionValueForSameVM( BlobType.NonNMethod.sizeOptionName, @@ -52,7 +53,8 @@ public void run(CodeCacheCLITestCase.Description testCaseDescription, String.format("%s should have value %d.", BlobType.NonNMethod.sizeOptionName, expectedValues.nonNmethods), - testCaseDescription.getTestOptions(options)); + // SapMachine 2025-12-10 We don't get exact matches when rounding to large page sizes. + testCaseDescription.getTestOptions(options, "-XX:-UseLargePages")); CommandLineOptionTest.verifyOptionValueForSameVM( BlobType.MethodNonProfiled.sizeOptionName, @@ -60,7 +62,8 @@ public void run(CodeCacheCLITestCase.Description testCaseDescription, String.format("%s should have value %d.", BlobType.MethodNonProfiled.sizeOptionName, expectedValues.nonProfiled), - testCaseDescription.getTestOptions(options)); + // SapMachine 2025-12-10 We don't get exact matches when rounding to large page sizes. + testCaseDescription.getTestOptions(options, "-XX:-UseLargePages")); CommandLineOptionTest.verifyOptionValueForSameVM( BlobType.MethodProfiled.sizeOptionName, @@ -68,6 +71,7 @@ public void run(CodeCacheCLITestCase.Description testCaseDescription, String.format("%s should have value %d.", BlobType.MethodProfiled.sizeOptionName, expectedValues.profiled), - testCaseDescription.getTestOptions(options)); + // SapMachine 2025-12-10 We don't get exact matches when rounding to large page sizes. + testCaseDescription.getTestOptions(options, "-XX:-UseLargePages")); } } diff --git a/test/hotspot/jtreg/runtime/os/TestHugePageDecisionsAtVMStartup.java b/test/hotspot/jtreg/runtime/os/TestHugePageDecisionsAtVMStartup.java index 7c0dfb2f3bb..7b118d4ab30 100644 --- a/test/hotspot/jtreg/runtime/os/TestHugePageDecisionsAtVMStartup.java +++ b/test/hotspot/jtreg/runtime/os/TestHugePageDecisionsAtVMStartup.java @@ -22,6 +22,7 @@ * questions. */ +// SapMachine 2025-12-10 We use UseTransparentHugePages in some configurations. /* * @test id=Default * @summary Test JVM large page setup (default options) @@ -29,7 +30,7 @@ * @requires os.family == "linux" * @modules java.base/jdk.internal.misc * java.management - * @run driver TestHugePageDecisionsAtVMStartup + * @run driver TestHugePageDecisionsAtVMStartup -XX:-UseTransparentHugePages */ /*