Skip to content

mpool/hugepage: set mntent API instead of manually parsing /proc/mounts #1846

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
Aug 1, 2016
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
38 changes: 22 additions & 16 deletions opal/mca/mpool/hugepage/mpool_hugepage_component.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif
#ifdef HAVE_MNTENT_H
#include <mntent.h>
#endif

#include <fcntl.h>

Expand Down Expand Up @@ -200,33 +203,34 @@ static int page_compare (opal_list_item_t **a, opal_list_item_t **b) {
}

static void mca_mpool_hugepage_find_hugepages (void) {
#ifdef HAVE_MNTENT_H
mca_mpool_hugepage_hugepage_t *hp;
FILE *fh;
char *path;
char buffer[1024];
char *ctx, *tok;
struct mntent *mntent;
char *opts, *tok, *ctx;

fh = fopen ("/proc/mounts", "r");
fh = setmntent ("/proc/mounts", "r");
if (NULL == fh) {
return;
}

while (fgets (buffer, 1024, fh)) {
while (NULL != (mntent = getmntent(fh))) {
unsigned long page_size = 0;

(void) strtok_r (buffer, " ", &ctx);
path = strtok_r (NULL, " ", &ctx);
tok = strtok_r (NULL, " ", &ctx);

if (0 != strcmp (tok, "hugetlbfs")) {
if (0 != strcmp(mntent->mnt_type, "hugetlbfs")) {
continue;
}

tok = strtok_r (NULL, " ", &ctx);
tok = strtok_r (tok, ",", &ctx);
opts = strdup(mntent->mnt_opts);
if (NULL == opts) {
break;
}

tok = strtok_r (opts, ",", &ctx);

do {
if (0 == strncmp (tok, "pagesize", 8)) {
free(opts);
break;
}
tok = strtok_r (NULL, ",", &ctx);
Expand All @@ -236,15 +240,16 @@ static void mca_mpool_hugepage_find_hugepages (void) {
#if defined(USE_STATFS)
struct statfs info;

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

if (0 == page_size) {
/* could not get page size */
Expand All @@ -256,7 +261,7 @@ static void mca_mpool_hugepage_find_hugepages (void) {
break;
}

hp->path = strdup (path);
hp->path = strdup (mntent->mnt_dir);
hp->page_size = page_size;

OPAL_OUTPUT_VERBOSE((MCA_BASE_VERBOSE_INFO, opal_mpool_base_framework.framework_output,
Expand All @@ -268,7 +273,8 @@ static void mca_mpool_hugepage_find_hugepages (void) {

opal_list_sort (&mca_mpool_hugepage_component.huge_pages, page_compare);

fclose (fh);
endmntent (fh);
#endif
}

static int mca_mpool_hugepage_query (const char *hints, int *priority_out,
Expand Down