@@ -64,6 +64,7 @@ public int compareTo(ExplicitHugePageConfig o) {
64
64
65
65
Set <ExplicitHugePageConfig > _explicitHugePageConfigurations ;
66
66
long _explicitDefaultHugePageSize = -1 ;
67
+ long _explicitAvailableHugePageNumber = -1 ;
67
68
68
69
public enum THPMode {always , never , madvise }
69
70
THPMode _thpMode ;
@@ -80,6 +81,10 @@ public long getExplicitDefaultHugePageSize() {
80
81
return _explicitDefaultHugePageSize ;
81
82
}
82
83
84
+ public long getExplicitAvailableHugePageNumber () {
85
+ return _explicitAvailableHugePageNumber ;
86
+ }
87
+
83
88
public THPMode getThpMode () {
84
89
return _thpMode ;
85
90
}
@@ -116,9 +121,10 @@ public boolean supportsExplicitHugePages() {
116
121
return _explicitDefaultHugePageSize > 0 && _explicitHugePageConfigurations .size () > 0 ;
117
122
}
118
123
119
- public HugePageConfiguration (Set <ExplicitHugePageConfig > explicitHugePageConfigurations , long explicitDefaultHugePageSize , THPMode _thpMode , long _thpPageSize , ShmemTHPMode _shmemThpMode ) {
124
+ public HugePageConfiguration (Set <ExplicitHugePageConfig > explicitHugePageConfigurations , long explicitDefaultHugePageSize , long explicitAvailableHugePageNumber , THPMode _thpMode , long _thpPageSize , ShmemTHPMode _shmemThpMode ) {
120
125
this ._explicitHugePageConfigurations = explicitHugePageConfigurations ;
121
126
this ._explicitDefaultHugePageSize = explicitDefaultHugePageSize ;
127
+ this ._explicitAvailableHugePageNumber = explicitAvailableHugePageNumber ;
122
128
this ._thpMode = _thpMode ;
123
129
this ._thpPageSize = _thpPageSize ;
124
130
this ._shmemThpMode = _shmemThpMode ;
@@ -129,6 +135,7 @@ public String toString() {
129
135
return "Configuration{" +
130
136
"_explicitHugePageConfigurations=" + _explicitHugePageConfigurations +
131
137
", _explicitDefaultHugePageSize=" + _explicitDefaultHugePageSize +
138
+ ", _explicitAvailableHugePageNumber=" + _explicitAvailableHugePageNumber +
132
139
", _thpMode=" + _thpMode +
133
140
", _thpPageSize=" + _thpPageSize +
134
141
", _shmemThpMode=" + _shmemThpMode +
@@ -138,6 +145,7 @@ public String toString() {
138
145
@ Override
139
146
public int hashCode () {
140
147
return Objects .hash (_explicitDefaultHugePageSize ,
148
+ _explicitAvailableHugePageNumber ,
141
149
_thpPageSize ,
142
150
_explicitHugePageConfigurations ,
143
151
_thpMode ,
@@ -149,6 +157,7 @@ public boolean equals(Object o) {
149
157
if (this == o ) return true ;
150
158
if (o == null || getClass () != o .getClass ()) return false ;
151
159
HugePageConfiguration that = (HugePageConfiguration ) o ;
160
+ // _explicitAvailableHugePageNumber is not compared here, because there is no direct counterpart on the JVM-side log.
152
161
return _explicitDefaultHugePageSize == that ._explicitDefaultHugePageSize && _thpPageSize == that ._thpPageSize &&
153
162
Objects .equals (_explicitHugePageConfigurations , that ._explicitHugePageConfigurations ) && _thpMode == that ._thpMode &&
154
163
_shmemThpMode == that ._shmemThpMode ;
@@ -169,6 +178,21 @@ private static long readDefaultHugePageSizeFromOS() {
169
178
return 0 ;
170
179
}
171
180
181
+ private static long readAvailableHugePageNumberFromOS () {
182
+ Pattern pat = Pattern .compile ("HugePages_Free: *(\\ d+)$" );
183
+ try (Scanner scanner = new Scanner (new File ("/proc/meminfo" ))) {
184
+ while (scanner .hasNextLine ()) {
185
+ Matcher mat = pat .matcher (scanner .nextLine ());
186
+ if (mat .matches ()) {
187
+ return Long .parseLong (mat .group (1 ));
188
+ }
189
+ }
190
+ } catch (FileNotFoundException e ) {
191
+ System .out .println ("Could not open /proc/meminfo" );
192
+ }
193
+ return 0 ;
194
+ }
195
+
172
196
private static Set <ExplicitHugePageConfig > readSupportedHugePagesFromOS () throws IOException {
173
197
TreeSet <ExplicitHugePageConfig > hugePageConfigs = new TreeSet <>();
174
198
Pattern pat = Pattern .compile ("hugepages-(\\ d+)kB" );
@@ -263,6 +287,7 @@ private static ShmemTHPMode readShmemTHPModeFromOS() {
263
287
public static HugePageConfiguration readFromOS () throws IOException {
264
288
return new HugePageConfiguration (readSupportedHugePagesFromOS (),
265
289
readDefaultHugePageSizeFromOS (),
290
+ readAvailableHugePageNumberFromOS (),
266
291
readTHPModeFromOS (),
267
292
readTHPPageSizeFromOS (),
268
293
readShmemTHPModeFromOS ());
@@ -333,7 +358,7 @@ public static HugePageConfiguration readFromJVMLog(OutputAnalyzer output) {
333
358
}
334
359
}
335
360
336
- return new HugePageConfiguration (explicitHugePageConfigs , defaultHugepageSize , thpMode , thpPageSize , shmemThpMode );
361
+ return new HugePageConfiguration (explicitHugePageConfigs , defaultHugepageSize , - 1 , thpMode , thpPageSize , shmemThpMode );
337
362
}
338
363
339
364
}
0 commit comments