diff --git a/runtime/src/comm/ofi/Makefile.share b/runtime/src/comm/ofi/Makefile.share index a35af175e271..aa4c134b3b80 100644 --- a/runtime/src/comm/ofi/Makefile.share +++ b/runtime/src/comm/ofi/Makefile.share @@ -47,11 +47,12 @@ ifneq (, $(findstring pmi2, $(COMM_SRCS))) endif endif + # -# Use hugepages on Cray XC and HPE Cray EX systems. +# Use hugepages if requested. # -ifneq (, $(findstring $(CHPL_MAKE_TARGET_PLATFORM), cray-xc hpe-cray-ex)) +ifneq (, $(call isTrue, $(CHPL_COMM_OFI_USE_HUGEPAGES))) COMM_SRCS += comm-ofi-hugepages.c else COMM_SRCS += comm-ofi-no-hugepages.c diff --git a/runtime/src/comm/ofi/comm-ofi-hugepages.c b/runtime/src/comm/ofi/comm-ofi-hugepages.c index 6d81d224ff1c..d22ee9bb9783 100644 --- a/runtime/src/comm/ofi/comm-ofi-hugepages.c +++ b/runtime/src/comm/ofi/comm-ofi-hugepages.c @@ -39,3 +39,7 @@ void* chpl_comm_ofi_hp_get_huge_pages(size_t size) { size_t chpl_comm_ofi_hp_gethugepagesize(void) { return gethugepagesize(); } + +chpl_bool chpl_comm_ofi_hp_supported(void) { + return true; +} \ No newline at end of file diff --git a/runtime/src/comm/ofi/comm-ofi-internal.h b/runtime/src/comm/ofi/comm-ofi-internal.h index 2e4e10ee2df9..5e7cf9ec7b83 100644 --- a/runtime/src/comm/ofi/comm-ofi-internal.h +++ b/runtime/src/comm/ofi/comm-ofi-internal.h @@ -290,6 +290,7 @@ int chpl_comm_ofi_oob_locales_on_node(int *localRank); void* chpl_comm_ofi_hp_get_huge_pages(size_t); size_t chpl_comm_ofi_hp_gethugepagesize(void); +chpl_bool chpl_comm_ofi_hp_supported(void); // diff --git a/runtime/src/comm/ofi/comm-ofi-no-hugepages.c b/runtime/src/comm/ofi/comm-ofi-no-hugepages.c index 4069f27096a6..78553ef96130 100644 --- a/runtime/src/comm/ofi/comm-ofi-no-hugepages.c +++ b/runtime/src/comm/ofi/comm-ofi-no-hugepages.c @@ -33,3 +33,5 @@ void* chpl_comm_ofi_hp_get_huge_pages(size_t size) { return NULL; } size_t chpl_comm_ofi_hp_gethugepagesize(void) { return 0; } + +chpl_bool chpl_comm_ofi_hp_supported(void) {return false; } diff --git a/runtime/src/comm/ofi/comm-ofi.c b/runtime/src/comm/ofi/comm-ofi.c index 5cd41b0669ad..88fe6dfa1450 100644 --- a/runtime/src/comm/ofi/comm-ofi.c +++ b/runtime/src/comm/ofi/comm-ofi.c @@ -3479,6 +3479,10 @@ void init_fixedHeap(void) { if ((page_size = get_hugepageSize()) == 0) { have_hugepages = false; + } else { + have_hugepages = true; + } + if (!have_hugepages) { page_size = chpl_getSysPageSize(); // // We'll make a fixed heap, on whole pages. @@ -3510,7 +3514,6 @@ void init_fixedHeap(void) { if (start == NULL) chpl_error("cannot create fixed heap: cannot get memory", 0, 0); } else { - have_hugepages = true; // // We'll make a fixed heap on whole hugepages. // @@ -3562,11 +3565,22 @@ size_t get_hugepageSize(void) { static void init_hugepageSize(void) { - if (chpl_numNodes > 1 - && getenv("HUGETLB_DEFAULT_PAGE_SIZE") != NULL) { + chpl_bool use_hugepages = chpl_env_rt_get_bool("COMM_OFI_USE_HUGEPAGES", + false); + if ((chpl_numNodes > 1) && use_hugepages && + (getenv("HUGETLB_DEFAULT_PAGE_SIZE") != NULL)) { hugepageSize = chpl_comm_ofi_hp_gethugepagesize(); } + if (use_hugepages && (hugepageSize == 0)) { + if (chpl_comm_ofi_hp_supported()) { + chpl_error("Unable to get hugepage size. " + "Ensure that a hugepage module is loaded.", 0, 0); + } else { + chpl_error("Chapel was not built with hugepage support.", 0, 0); + } + } + DBG_PRINTF(DBG_HUGEPAGES, "setting hugepage info: use hugepages %s, sz %#zx", (hugepageSize > 0) ? "YES" : "NO", hugepageSize);