path: root/tests
diff options
authorAndrew Hastings <abh@cray.com>2011-02-02 11:57:22 -0600
committerEric B Munson <emunson@mgebm.net>2011-02-23 14:29:07 -0500
commit8b55918e470927522a2e30e938c791bf4bbfa8df (patch)
tree26adf20582db4ea27021389544780a02b6d99538 /tests
parent319122ba1f31cf5804901ec078dab5491f9202be (diff)
Allow actions to be restricted to certain programs
By default, libhugetlbfs will act on any program that it is loaded with, either via LD_PRELOAD or by explicitly linking with -lhugetlbfs. There are situations in which it is desirable to restrict libhugetlbfs' actions to specific programs. For example, some ISV applications are wrapped in a series of scripts that invoke bash, python, and/or perl. It is more convenient to set the environment variables related to libhugetlbfs outside of the wrapper scripts, yet this has the unintended and undesirable consequence of causing the script interpreters to use and consume hugepages. Often there is no obvious benefit to causing the script interpreters to use hugepages, and there is a clear disadvantage: fewer hugepages are available to the actual application. To address this scenario, add a HUGETLB_RESTRICT_EXE environment variable. If this variable is set, libhugetlbfs will restrict its actions to only those programs named in HUGETLB_RESTRICT_EXE. (If not set, libhugetlbfs will attempt to apply the requested actions to all programs.) For example, HUGETLB_RESTRICT_EXE="hpcc:long_hpcc" will restrict libhugetlbfs' actions to programs named /home/fred/hpcc and /bench/long_hpcc but will not affect /usr/bin/hpcc_no. Based on a patch originally authored by Dean Luick <luick@cray.com>. Signed-off-by: Andrew Hastings <abh@cray.com> on behalf of Cray Inc. Signed-off-by: Eric B Munson <emunson@mgebm.net>
Diffstat (limited to 'tests')
2 files changed, 16 insertions, 4 deletions
diff --git a/tests/malloc.c b/tests/malloc.c
index a50c99b..a1af5e1 100644
--- a/tests/malloc.c
+++ b/tests/malloc.c
@@ -42,16 +42,24 @@ static int block_sizes[] = {
int main(int argc, char *argv[])
int i;
- char *env;
+ char *env1, *env2, *exe;
int expect_hugepage = 0;
char *p;
test_init(argc, argv);
+ exe = strrchr(test_name, '/');
+ if (exe)
+ exe++; /* skip over "/" */
+ else
+ exe = test_name;
- env = getenv("HUGETLB_MORECORE");
- verbose_printf("HUGETLB_MORECORE=%s\n", env);
- if (env)
+ env1 = getenv("HUGETLB_MORECORE");
+ verbose_printf("HUGETLB_MORECORE=%s\n", env1);
+ env2 = getenv("HUGETLB_RESTRICT_EXE");
+ verbose_printf("HUGETLB_RESTRICT_EXE=%s\n", env2);
+ if (env1 && (!env2 || strstr(env2, exe)))
expect_hugepage = 1;
+ verbose_printf("expect_hugepage=%d\n", expect_hugepage);
for (i = 0; i < NUM_SIZES; i++) {
int size = block_sizes[i];
diff --git a/tests/run_tests.py b/tests/run_tests.py
index 27a94cb..8055940 100755
--- a/tests/run_tests.py
+++ b/tests/run_tests.py
@@ -554,6 +554,10 @@ def functional_tests():
do_test("malloc", LD_PRELOAD="libhugetlbfs.so", HUGETLB_MORECORE="yes")
+ do_test("malloc", LD_PRELOAD="libhugetlbfs.so", HUGETLB_MORECORE="yes",
+ HUGETLB_RESTRICT_EXE="unknown:none")
+ do_test("malloc", LD_PRELOAD="libhugetlbfs.so", HUGETLB_MORECORE="yes",
+ HUGETLB_RESTRICT_EXE="unknown:malloc")
do_test("malloc_manysmall", LD_PRELOAD="libhugetlbfs.so",