Skip to content

Commit 2db0c7c

Browse files
TheRealMDoerrRealCLanger
authored andcommitted
SapMachine SAP#2137: Linux: We should use transparent huge pages in some configurations (SAP#2138)
Linux: Enable UseTransparentHugePages if - UseLargePages and UseTransparentHugePages are not set explicitly - transparent huge pages are supported by the system configuration and the huge pages size is not above 2MB - UseZGC or UseShenandoahGC are not selected - the Java Heap is not set to 128MB or lower
1 parent 11b4552 commit 2db0c7c

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

src/hotspot/os/linux/os_linux.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3977,6 +3977,17 @@ void os::Linux::large_page_init() {
39773977
// Query OS information first.
39783978
HugePages::initialize();
39793979

3980+
// SapMachine 2025-12-10 Enable UseTransparentHugePages if supported and the huge pages
3981+
// are not extremely large and no other configuration is selected by flags.
3982+
// Some GCs have additional requirements, are optimized for ultra-low latency or
3983+
// have limitations regarding configuration parameters with small heap sizes.
3984+
if (FLAG_IS_DEFAULT(UseLargePages) && FLAG_IS_DEFAULT(UseTransparentHugePages) &&
3985+
HugePages::supports_thp() && HugePages::thp_pagesize() <= 2*M &&
3986+
!UseZGC && !UseShenandoahGC &&
3987+
(FLAG_IS_DEFAULT(MaxHeapSize) || MaxHeapSize > 128*M)) {
3988+
_thp_requested = UseTransparentHugePages = true;
3989+
}
3990+
39803991
// If THPs are unconditionally enabled (THP mode "always"), khugepaged may attempt to
39813992
// coalesce small pages in thread stacks to huge pages. That costs a lot of memory and
39823993
// is usually unwanted for thread stacks. Therefore we attempt to prevent THP formation in

src/java.base/share/man/java.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
# or visit www.oracle.com if you need additional information or have any
2121
# questions.
2222
#
23+
# SapMachine 2025-12-10 Changed description of UseTransparentHugePages which is
24+
# tested by us.
2325

2426
title: 'JAVA(1) JDK @@VERSION_SHORT@@ | JDK Commands'
2527
date: @@COPYRIGHT_YEAR@@
@@ -1576,9 +1578,11 @@ These `java` options control the runtime behavior of the Java HotSpot VM.
15761578

15771579
`-XX:+UseTransparentHugePages`
15781580
: **Linux only:** Enables the use of large pages that can dynamically grow or
1579-
shrink. This option is disabled by default. You may encounter performance
1580-
problems with transparent huge pages as the OS moves other pages around to
1581-
create huge pages; this option is made available for experimentation.
1581+
shrink. The VM may enable this option by default in some environments. You
1582+
may encounter performance problems with transparent huge pages as the OS
1583+
moves other pages around to create huge pages. You may encounter other
1584+
performance problems when only small pages are used as the OS needs to
1585+
maintain a large page table and address translations may become slow.
15821586

15831587
`-XX:+AllowUserSignalHandlers`
15841588
: **Non-Windows:** Enables installation of signal handlers by the application. By default,

test/hotspot/jtreg/compiler/codecache/CheckSegmentedCodeCache.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,13 @@ public static void main(String[] args) throws Exception {
231231

232232
// Reserved code cache is set, NonNmethod segment size is set, two other segments is automatically
233233
// adjusted to half of the remaining space
234+
// SapMachine 2025-12-10 We support 2MB transparent huge pages, so we need a multiple of it.
234235
pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:+SegmentedCodeCache",
235-
"-XX:ReservedCodeCacheSize=100M",
236+
"-XX:ReservedCodeCacheSize=102M", // original: 100M
236237
"-XX:NonNMethodCodeHeapSize=10M",
237238
"-XX:+PrintFlagsFinal",
238239
"-version");
239-
verifyCodeHeapSize(pb, " ProfiledCodeHeapSize", 47185920);
240+
verifyCodeHeapSize(pb, " ProfiledCodeHeapSize", 48234496); // = 46M, original: 47185920
240241

241242
// Reserved code cache is set but NonNmethodCodeHeapSize is not set.
242243
// It's calculated based on the number of compiler threads

test/hotspot/jtreg/compiler/codecache/cli/codeheapsize/GenericCodeHeapSizeRunner.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,30 +44,34 @@ public void run(CodeCacheCLITestCase.Description testCaseDescription,
4444
Long.toString(expectedValues.reserved),
4545
String.format("%s should have value %d.",
4646
BlobType.All.sizeOptionName, expectedValues.reserved),
47-
testCaseDescription.getTestOptions(options));
47+
// SapMachine 2025-12-10 We don't get exact matches when rounding to large page sizes.
48+
testCaseDescription.getTestOptions(options, "-XX:-UseLargePages"));
4849

4950
CommandLineOptionTest.verifyOptionValueForSameVM(
5051
BlobType.NonNMethod.sizeOptionName,
5152
Long.toString(expectedValues.nonNmethods),
5253
String.format("%s should have value %d.",
5354
BlobType.NonNMethod.sizeOptionName,
5455
expectedValues.nonNmethods),
55-
testCaseDescription.getTestOptions(options));
56+
// SapMachine 2025-12-10 We don't get exact matches when rounding to large page sizes.
57+
testCaseDescription.getTestOptions(options, "-XX:-UseLargePages"));
5658

5759
CommandLineOptionTest.verifyOptionValueForSameVM(
5860
BlobType.MethodNonProfiled.sizeOptionName,
5961
Long.toString(expectedValues.nonProfiled),
6062
String.format("%s should have value %d.",
6163
BlobType.MethodNonProfiled.sizeOptionName,
6264
expectedValues.nonProfiled),
63-
testCaseDescription.getTestOptions(options));
65+
// SapMachine 2025-12-10 We don't get exact matches when rounding to large page sizes.
66+
testCaseDescription.getTestOptions(options, "-XX:-UseLargePages"));
6467

6568
CommandLineOptionTest.verifyOptionValueForSameVM(
6669
BlobType.MethodProfiled.sizeOptionName,
6770
Long.toString(expectedValues.profiled),
6871
String.format("%s should have value %d.",
6972
BlobType.MethodProfiled.sizeOptionName,
7073
expectedValues.profiled),
71-
testCaseDescription.getTestOptions(options));
74+
// SapMachine 2025-12-10 We don't get exact matches when rounding to large page sizes.
75+
testCaseDescription.getTestOptions(options, "-XX:-UseLargePages"));
7276
}
7377
}

test/hotspot/jtreg/runtime/os/TestHugePageDecisionsAtVMStartup.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@
2222
* questions.
2323
*/
2424

25+
// SapMachine 2025-12-10 We use UseTransparentHugePages in some configurations.
2526
/*
2627
* @test id=Default
2728
* @summary Test JVM large page setup (default options)
2829
* @library /test/lib
2930
* @requires os.family == "linux"
3031
* @modules java.base/jdk.internal.misc
3132
* java.management
32-
* @run driver TestHugePageDecisionsAtVMStartup
33+
* @run driver TestHugePageDecisionsAtVMStartup -XX:-UseTransparentHugePages
3334
*/
3435

3536
/*

0 commit comments

Comments
 (0)