Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions opal/mca/mpool/hugepage/mpool_hugepage_component.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ static void mca_mpool_hugepage_find_hugepages(void)
mca_mpool_hugepage_hugepage_t *hp;
FILE *fh;
struct mntent *mntent;
char *opts, *tok, *ctx;

fh = setmntent("/proc/mounts", "r");
if (NULL == fh) {
Expand All @@ -232,6 +231,18 @@ static void mca_mpool_hugepage_find_hugepages(void)
continue;
}

#if defined(USE_STATFS)
struct statfs info;
statfs(mntent->mnt_dir, &info);
page_size = info.f_bsize;
#elif defined(HAVE_STATVFS)
struct statvfs info;
statvfs(mntent->mnt_dir, &info);
page_size = info.f_bsize;
#else
// Fallback for extremely old systems that do not have
// statfs().
char *opts, *tok, *ctx;
opts = strdup(mntent->mnt_opts);
if (NULL == opts) {
break;
Expand All @@ -240,25 +251,19 @@ static void mca_mpool_hugepage_find_hugepages(void)
tok = strtok_r(opts, ",", &ctx);
do {
if (NULL != tok && 0 == strncmp(tok, "pagesize", 8)) {
break;
// It is expected that pagesize=X will be an integer
// number with no units qualifier following it.
// Specifically: Linux circa 2025 has /proc/mounts
// output like "... rw,relatime,pagesize=2M". But if
// your system is signifncantly older than that
// (statfs() was introduced around 1994), we're
// assuming that there is no units qualifier.
(void) sscanf(tok, "pagesize=%lu", &page_size);
}
tok = strtok_r(NULL, ",", &ctx);
} while (tok);

if (!tok) {
# if defined(USE_STATFS)
struct statfs info;

statfs(mntent->mnt_dir, &info);
# elif defined(HAVE_STATVFS)
struct statvfs info;
statvfs(mntent->mnt_dir, &info);
# endif
page_size = info.f_bsize;
} else {
(void) sscanf(tok, "pagesize=%lu", &page_size);
}
free(opts);
#endif

if (0 == page_size) {
/* could not get page size */
Expand Down