@@ -218,7 +218,6 @@ static void mca_mpool_hugepage_find_hugepages(void)
218218 mca_mpool_hugepage_hugepage_t * hp ;
219219 FILE * fh ;
220220 struct mntent * mntent ;
221- char * opts , * tok , * ctx ;
222221
223222 fh = setmntent ("/proc/mounts" , "r" );
224223 if (NULL == fh ) {
@@ -232,6 +231,18 @@ static void mca_mpool_hugepage_find_hugepages(void)
232231 continue ;
233232 }
234233
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 ;
235246 opts = strdup (mntent -> mnt_opts );
236247 if (NULL == opts ) {
237248 break ;
@@ -240,25 +251,19 @@ static void mca_mpool_hugepage_find_hugepages(void)
240251 tok = strtok_r (opts , "," , & ctx );
241252 do {
242253 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 );
244262 }
245263 tok = strtok_r (NULL , "," , & ctx );
246264 } 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- }
261265 free (opts );
266+ #endif
262267
263268 if (0 == page_size ) {
264269 /* could not get page size */
0 commit comments