By default, libhugetlbfs will fall back to using base pages when huge pages are not available. In some situations such as benchmarking this may not be desirable as the user would be using base pages when they believed huge pages were in use. This patch enables the user to specify that hugepages must be used by setting the HUGETLB_STRICT environment variable.
Signed-off-by: mel <[EMAIL PROTECTED]> --- HOWTO | 2 ++ alloc.c | 3 +++ debug.c | 5 +++++ elflink.c | 8 +++++++- hugeutils.c | 10 ++++++++++ libhugetlbfs_internal.h | 2 ++ morecore.c | 5 +++++ shm.c | 1 + 8 files changed, 35 insertions(+), 1 deletions(-) diff --git a/HOWTO b/HOWTO index 4cd94dd..1fe30ca 100644 --- a/HOWTO +++ b/HOWTO @@ -493,6 +493,8 @@ libhugetlbfs: HUGETLB_NO_PREFAULT Explained in "Using hugepages for malloc() (morecore)" + HUGETLB_STRICT + Exit the application if hugepages cannot be used HUGETLB_VERBOSE Specify the verbosity level of debugging output from 1 diff --git a/alloc.c b/alloc.c index 197c1ce..8d77ddb 100644 --- a/alloc.c +++ b/alloc.c @@ -84,6 +84,7 @@ void *get_huge_pages(size_t len, ghp_t flags) heap_fd = hugetlbfs_unlinked_fd(); if (heap_fd < 0) { ERROR("Couldn't open hugetlbfs file for %zd-sized heap\n", len); + __lh_exit_if_strict("get_huge_pages create", len); return NULL; } @@ -99,6 +100,7 @@ void *get_huge_pages(size_t len, ghp_t flags) WARNING("get_huge_pages: New region mapping failed (flags: 0x%lX): %s\n", flags, strerror(errno)); + __lh_exit_if_strict("get_huge_pages map", len); return NULL; } @@ -116,6 +118,7 @@ void *get_huge_pages(size_t len, ghp_t flags) if (close(heap_fd) != 0) { WARNING("Failed to close new heap fd: %s\n", strerror(errno)); munmap(buf, len); + __lh_exit_if_strict("get_huge_pages closing", len); return NULL; } diff --git a/debug.c b/debug.c index bd54d58..b8a35a0 100644 --- a/debug.c +++ b/debug.c @@ -30,6 +30,7 @@ int __hugetlbfs_verbose = VERBOSITY_DEFAULT; int __hugetlbfs_debug = 0; int __hugetlbfs_prefault = 1; +int __hugetlbfs_strict = 0; char __hugetlbfs_hostname[64]; static int initialized; @@ -53,6 +54,10 @@ static void __hugetlbfs_init_debug(void) if (env) __hugetlbfs_prefault = 0; + env = getenv("HUGETLB_STRICT"); + if (env) + __hugetlbfs_strict = 1; + gethostname(__hugetlbfs_hostname, sizeof(__hugetlbfs_hostname)-1); initialized = 1; diff --git a/elflink.c b/elflink.c index 6f55c02..93c63bc 100644 --- a/elflink.c +++ b/elflink.c @@ -1203,6 +1203,7 @@ void __lh_hugetlbfs_setup_elflink(void) ERROR("Hugepage size too large\n"); else ERROR("Hugepage size (%s)\n", strerror(errno)); + __lh_exit_if_strict("elflink hugepagesize", 0); return; } @@ -1211,8 +1212,10 @@ void __lh_hugetlbfs_setup_elflink(void) /* Do we need to find a share directory */ if (sharing) { ret = find_or_create_share_path(); - if (ret != 0) + if (ret != 0) { + __lh_exit_if_strict("elflink sharepath", 0); return; + } } /* Step 1. Obtain hugepage files with our program data */ @@ -1220,11 +1223,14 @@ void __lh_hugetlbfs_setup_elflink(void) ret = obtain_prepared_file(&htlb_seg_table[i]); if (ret < 0) { DEBUG("Failed to setup hugetlbfs file for segment %d\n", i); + __lh_exit_if_strict("elflink file setup", + htlb_seg_table[i].filesz); /* Close files we have already prepared */ for (; i >= 0; i--) close(htlb_seg_table[i].fd); + DEBUG("Failed to setup hugetlbfs file\n"); return; } } diff --git a/hugeutils.c b/hugeutils.c index 64083ac..fb2d581 100644 --- a/hugeutils.c +++ b/hugeutils.c @@ -314,6 +314,16 @@ int __lh_hugetlbfs_prefault(int fd, void *addr, size_t length) return 0; } +void __lh_exit_if_strict(char *name, size_t length) +{ + if (!__hugetlbfs_strict) + return; + + ERROR("%s failed for size %d. Exiting due to HUGETLB_STRICT\n", + name, length); + exit(EXIT_FAILURE); +} + /********************************************************************/ /* Library user visible DIAGNOSES/DEBUGGING ONLY functions */ /********************************************************************/ diff --git a/libhugetlbfs_internal.h b/libhugetlbfs_internal.h index 7baf9b2..5c611b8 100644 --- a/libhugetlbfs_internal.h +++ b/libhugetlbfs_internal.h @@ -43,11 +43,13 @@ extern int __hugetlbfs_verbose; extern int __hugetlbfs_debug; extern int __hugetlbfs_prefault; +extern int __hugetlbfs_strict; extern void __lh_hugetlbfs_setup_elflink(); extern void __lh_hugetlbfs_setup_morecore(); extern void __lh_hugetlbfs_setup_debug(); extern char __hugetlbfs_hostname[]; extern int __lh_hugetlbfs_prefault(int fd, void *addr, size_t length); +extern void __lh_exit_if_strict(char *name, size_t length); #ifndef REPORT #define REPORT(level, prefix, format, ...) \ diff --git a/morecore.c b/morecore.c index 013ba90..eed573e 100644 --- a/morecore.c +++ b/morecore.c @@ -98,6 +98,7 @@ static void *hugetlbfs_morecore(ptrdiff_t increment) if (p == MAP_FAILED) { WARNING("New heap segment map at %p failed: %s\n", heapbase+mapsize, strerror(errno)); + __lh_exit_if_strict("morecore map", delta); return NULL; } @@ -118,12 +119,14 @@ static void *hugetlbfs_morecore(ptrdiff_t increment) p, heapbase + mapsize); if (__hugetlbfs_debug) __lh_dump_proc_pid_maps(); + __lh_exit_if_strict("morecore place", delta); return NULL; } /* Fault the region to ensure accesses succeed */ if (__lh_hugetlbfs_prefault(zero_fd, p, delta) != 0) { munmap(p, delta); + __lh_exit_if_strict("morecore prefault", delta); return NULL; } @@ -235,6 +238,7 @@ void __lh_hugetlbfs_setup_morecore(void) heap_fd = hugetlbfs_unlinked_fd(); if (heap_fd < 0) { ERROR("Couldn't open hugetlbfs file for morecore\n"); + __lh_exit_if_strict("morecore fd", 0); return; } @@ -244,6 +248,7 @@ void __lh_hugetlbfs_setup_morecore(void) if (*ep != '\0') { ERROR("Can't parse HUGETLB_MORECORE_HEAPBASE: %s\n", env); + __lh_exit_if_strict("morecore fd", 0); return; } } else { diff --git a/shm.c b/shm.c index cc9995d..fdb9d56 100644 --- a/shm.c +++ b/shm.c @@ -73,6 +73,7 @@ int shmget(key_t key, size_t size, int shmflg) if (retval == -1 && hugetlbshm_enabled) { WARNING("While overriding shmget(%zd) to add SHM_HUGETLB: %s\n", aligned_size, strerror(errno)); + __lh_exit_if_strict("shmget override", size); shmflg &= ~SHM_HUGETLB; retval = real_shmget(key, size, shmflg); DEBUG("Using small pages for shmget despite HUGETLB_SHM\n"); -- 1.5.6 ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Libhugetlbfs-devel mailing list Libhugetlbfs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel