1
1
/*
2
- * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
39
39
import jdk .test .lib .process .OutputAnalyzer ;
40
40
import jdk .test .lib .process .ProcessTools ;
41
41
import jdk .test .whitebox .WhiteBox ;
42
+ import java .util .Scanner ;
43
+ import java .io .File ;
44
+ import java .io .FileNotFoundException ;
42
45
43
46
import java .util .Arrays ;
44
47
import java .util .List ;
@@ -47,6 +50,7 @@ public class CheckLargePages {
47
50
private final static long LP_1G = 1024 * 1024 * 1024 ;
48
51
private final static boolean LARGE_PAGES_ENABLED ;
49
52
private final static long LARGE_PAGE_SIZE ;
53
+ private final static String LARGE_PAGE_NUMBER_FILE_BASE = "/sys/kernel/mm/hugepages/hugepages-%skB/nr_hugepages" ;
50
54
51
55
static {
52
56
WhiteBox whiteBox = WhiteBox .getWhiteBox ();
@@ -58,6 +62,16 @@ private static boolean isLargePageSizeEqual(long size) {
58
62
return LARGE_PAGE_SIZE == size ;
59
63
}
60
64
65
+ private static int numberOfLargePages (long size ) {
66
+ String largePageNumberFile = String .format (LARGE_PAGE_NUMBER_FILE_BASE , size / 1024 );
67
+ try (Scanner scanner = new Scanner (new File (largePageNumberFile ))) {
68
+ if (scanner .hasNextInt ()) {
69
+ return scanner .nextInt ();
70
+ }
71
+ } catch (FileNotFoundException e ) { };
72
+ return 0 ;
73
+ }
74
+
61
75
private static void testSegmented2GbCodeCacheWith1GbPage () throws Exception {
62
76
ProcessBuilder pb = ProcessTools .createLimitedTestJavaProcessBuilder (
63
77
"-XX:+UseLargePages" ,
@@ -113,11 +127,17 @@ private static void testNonSegmented1GbCodeCacheWith1GbLargePages() throws Excep
113
127
out .shouldContain ("UseLargePages=1, UseTransparentHugePages=0" );
114
128
out .shouldMatch ("CodeCache: min=1[gG] max=1[gG] base=[^ ]+ size=1[gG] page_size=1[gG]" );
115
129
}
130
+
116
131
public static void main (String [] args ) throws Exception {
117
132
if (isLargePageSizeEqual (LP_1G )) {
118
133
testSegmented2GbCodeCacheWith1GbPage ();
119
- testDefaultCodeCacheWith1GbLargePages ();
120
- testNonSegmented1GbCodeCacheWith1GbLargePages ();
134
+ if (numberOfLargePages (LP_1G ) >= 1 ) {
135
+ testDefaultCodeCacheWith1GbLargePages ();
136
+ testNonSegmented1GbCodeCacheWith1GbLargePages ();
137
+ } else {
138
+ System .out .println ("Skipping testDefaultCodeCacheWith1GbLargePages and " +
139
+ "testNonSegmented1GbCodeCacheWith1GbLargePages, no 1Gb pages available" );
140
+ }
121
141
} else {
122
142
System .out .println ("1GB large pages not supported: UseLargePages=" + LARGE_PAGES_ENABLED +
123
143
(LARGE_PAGES_ENABLED ? ", largePageSize=" + LARGE_PAGE_SIZE : "" ) + ". Skipping" );
0 commit comments