@@ -64,6 +64,7 @@ public int compareTo(ExplicitHugePageConfig o) {
6464
6565 Set <ExplicitHugePageConfig > _explicitHugePageConfigurations ;
6666 long _explicitDefaultHugePageSize = -1 ;
67+ long _explicitAvailableHugePageNumber = -1 ;
6768
6869 public enum THPMode {always , never , madvise }
6970 THPMode _thpMode ;
@@ -80,6 +81,10 @@ public long getExplicitDefaultHugePageSize() {
8081 return _explicitDefaultHugePageSize ;
8182 }
8283
84+ public long getExplicitAvailableHugePageNumber () {
85+ return _explicitAvailableHugePageNumber ;
86+ }
87+
8388 public THPMode getThpMode () {
8489 return _thpMode ;
8590 }
@@ -116,9 +121,10 @@ public boolean supportsExplicitHugePages() {
116121 return _explicitDefaultHugePageSize > 0 && _explicitHugePageConfigurations .size () > 0 ;
117122 }
118123
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 ) {
120125 this ._explicitHugePageConfigurations = explicitHugePageConfigurations ;
121126 this ._explicitDefaultHugePageSize = explicitDefaultHugePageSize ;
127+ this ._explicitAvailableHugePageNumber = explicitAvailableHugePageNumber ;
122128 this ._thpMode = _thpMode ;
123129 this ._thpPageSize = _thpPageSize ;
124130 this ._shmemThpMode = _shmemThpMode ;
@@ -129,6 +135,7 @@ public String toString() {
129135 return "Configuration{" +
130136 "_explicitHugePageConfigurations=" + _explicitHugePageConfigurations +
131137 ", _explicitDefaultHugePageSize=" + _explicitDefaultHugePageSize +
138+ ", _explicitAvailableHugePageNumber=" + _explicitAvailableHugePageNumber +
132139 ", _thpMode=" + _thpMode +
133140 ", _thpPageSize=" + _thpPageSize +
134141 ", _shmemThpMode=" + _shmemThpMode +
@@ -138,6 +145,7 @@ public String toString() {
138145 @ Override
139146 public int hashCode () {
140147 return Objects .hash (_explicitDefaultHugePageSize ,
148+ _explicitAvailableHugePageNumber ,
141149 _thpPageSize ,
142150 _explicitHugePageConfigurations ,
143151 _thpMode ,
@@ -149,6 +157,7 @@ public boolean equals(Object o) {
149157 if (this == o ) return true ;
150158 if (o == null || getClass () != o .getClass ()) return false ;
151159 HugePageConfiguration that = (HugePageConfiguration ) o ;
160+ // _explicitAvailableHugePageNumber is not compared here, because there is no direct counterpart on the JVM-side log.
152161 return _explicitDefaultHugePageSize == that ._explicitDefaultHugePageSize && _thpPageSize == that ._thpPageSize &&
153162 Objects .equals (_explicitHugePageConfigurations , that ._explicitHugePageConfigurations ) && _thpMode == that ._thpMode &&
154163 _shmemThpMode == that ._shmemThpMode ;
@@ -169,6 +178,21 @@ private static long readDefaultHugePageSizeFromOS() {
169178 return 0 ;
170179 }
171180
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+
172196 private static Set <ExplicitHugePageConfig > readSupportedHugePagesFromOS () throws IOException {
173197 TreeSet <ExplicitHugePageConfig > hugePageConfigs = new TreeSet <>();
174198 Pattern pat = Pattern .compile ("hugepages-(\\ d+)kB" );
@@ -263,6 +287,7 @@ private static ShmemTHPMode readShmemTHPModeFromOS() {
263287 public static HugePageConfiguration readFromOS () throws IOException {
264288 return new HugePageConfiguration (readSupportedHugePagesFromOS (),
265289 readDefaultHugePageSizeFromOS (),
290+ readAvailableHugePageNumberFromOS (),
266291 readTHPModeFromOS (),
267292 readTHPPageSizeFromOS (),
268293 readShmemTHPModeFromOS ());
@@ -333,7 +358,7 @@ public static HugePageConfiguration readFromJVMLog(OutputAnalyzer output) {
333358 }
334359 }
335360
336- return new HugePageConfiguration (explicitHugePageConfigs , defaultHugepageSize , thpMode , thpPageSize , shmemThpMode );
361+ return new HugePageConfiguration (explicitHugePageConfigs , defaultHugepageSize , - 1 , thpMode , thpPageSize , shmemThpMode );
337362 }
338363
339364}
0 commit comments