@@ -218,7 +218,6 @@ static void mca_mpool_hugepage_find_hugepages(void)
218
218
mca_mpool_hugepage_hugepage_t * hp ;
219
219
FILE * fh ;
220
220
struct mntent * mntent ;
221
- char * opts , * tok , * ctx ;
222
221
223
222
fh = setmntent ("/proc/mounts" , "r" );
224
223
if (NULL == fh ) {
@@ -232,6 +231,18 @@ static void mca_mpool_hugepage_find_hugepages(void)
232
231
continue ;
233
232
}
234
233
234
+ #if defined(USE_STATFS )
235
+ struct statfs info ;
236
+ statfs (mntent -> mnt_dir , & info );
237
+ page_size = info .f_bsize ;
238
+ #elif defined(HAVE_STATVFS )
239
+ struct statvfs info ;
240
+ statvfs (mntent -> mnt_dir , & info );
241
+ page_size = info .f_bsize ;
242
+ #else
243
+ // Fallback for extremely old systems that do not have
244
+ // statfs().
245
+ char * opts , * tok , * ctx ;
235
246
opts = strdup (mntent -> mnt_opts );
236
247
if (NULL == opts ) {
237
248
break ;
@@ -240,25 +251,19 @@ static void mca_mpool_hugepage_find_hugepages(void)
240
251
tok = strtok_r (opts , "," , & ctx );
241
252
do {
242
253
if (NULL != tok && 0 == strncmp (tok , "pagesize" , 8 )) {
243
- break ;
254
+ // It is expected that pagesize=X will be an integer
255
+ // number with no units qualifier following it.
256
+ // Specifically: Linux circa 2025 has /proc/mounts
257
+ // output like "... rw,relatime,pagesize=2M". But if
258
+ // your system is signifncantly older than that
259
+ // (statfs() was introduced around 1994), we're
260
+ // assuming that there is no units qualifier.
261
+ (void ) sscanf (tok , "pagesize=%lu" , & page_size );
244
262
}
245
263
tok = strtok_r (NULL , "," , & ctx );
246
264
} while (tok );
247
-
248
- if (!tok ) {
249
- # if defined(USE_STATFS )
250
- struct statfs info ;
251
-
252
- statfs (mntent -> mnt_dir , & info );
253
- # elif defined(HAVE_STATVFS )
254
- struct statvfs info ;
255
- statvfs (mntent -> mnt_dir , & info );
256
- # endif
257
- page_size = info .f_bsize ;
258
- } else {
259
- (void ) sscanf (tok , "pagesize=%lu" , & page_size );
260
- }
261
265
free (opts );
266
+ #endif
262
267
263
268
if (0 == page_size ) {
264
269
/* could not get page size */
0 commit comments