Skip to content

v4.1.x: mpool/hugepage: fix sizing of hugepages #13220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2025
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
39 changes: 22 additions & 17 deletions opal/mca/mpool/hugepage/mpool_hugepage_component.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,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 @@ -223,6 +222,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 @@ -231,26 +242,20 @@ static void mca_mpool_hugepage_find_hugepages (void) {
tok = strtok_r (opts, ",", &ctx);

do {
if (0 == strncmp (tok, "pagesize", 8)) {
break;
if (NULL != tok && 0 == strncmp(tok, "pagesize", 8)) {
// 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