The correct nr_overcommit_hugepages tunable for the currently used page size can be easily checked and modified thanks to get|set_pool_counter().
Fix up the get_huge_pages test to turn off huge page overcommit when testing GHP_FALLBACK. Without this fix, the test will always fail when overcommit is enabled. By moving the overcommit tuning into the counters test and out of run_tests.sh, we avoid having to duplicate the complexity of get|set_pool_counter() in a shell script. Signed-off-by: Adam Litke <[EMAIL PROTECTED]> --- tests/counters.c | 14 +++++++------- tests/get_huge_pages.c | 13 +++++++++++++ tests/run_tests.sh | 15 --------------- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/tests/counters.c b/tests/counters.c index 57105f6..f97d68a 100644 --- a/tests/counters.c +++ b/tests/counters.c @@ -46,6 +46,7 @@ extern int errno; /* Global test configuration */ #define DYNAMIC_SYSCTL "/proc/sys/vm/nr_overcommit_hugepages" static long saved_nr_hugepages; +static long saved_oc_hugepages; static long hpage_size; static int private_resv; @@ -70,17 +71,16 @@ static long prev_surp; /* Restore original nr_hugepages */ void cleanup(void) { set_pool_counter(HUGEPAGES_TOTAL, saved_nr_hugepages, 0); + if (saved_oc_hugepages >= 0) + set_pool_counter(HUGEPAGES_OC, saved_oc_hugepages, 0); } void verify_dynamic_pool_support(void) { - unsigned long val; - - val = get_pool_counter(HUGEPAGES_OC, 0); - if (val < 0) - FAIL("Unable to test for dynamic hugetlb pool support"); - if (val == 0) - CONFIG("Dynamic hugetlb pool support present, but disabled"); + saved_oc_hugepages = get_pool_counter(HUGEPAGES_OC, 0); + if (saved_oc_hugepages < 0) + FAIL("Kernel appears to lack dynamic hugetlb pool support"); + set_pool_counter(HUGEPAGES_OC, 10, 0); } void bad_value(int line, const char *name, long expect, long actual) diff --git a/tests/get_huge_pages.c b/tests/get_huge_pages.c index 318791a..c55be8e 100644 --- a/tests/get_huge_pages.c +++ b/tests/get_huge_pages.c @@ -25,6 +25,15 @@ #include "hugetests.h" +long oc_hugepages = -1; + +/* Restore nr_overcommit_hugepages */ +void cleanup(void) +{ + if (oc_hugepages != -1) + set_pool_counter(HUGEPAGES_OC, oc_hugepages, 0); +} + /* Confirm a region really frees, only really important for GHP_FALLBACK */ void free_and_confirm_region_free(void *p, int line) { unsigned char vec = 0; @@ -61,6 +70,10 @@ void test_GHP_FALLBACK(void) long num_hugepages = get_pool_counter(HUGEPAGES_TOTAL, 0) - rsvd_hugepages; + /* We must disable overcommitted huge pages to test this */ + oc_hugepages = get_pool_counter(HUGEPAGES_OC, 0); + set_pool_counter(HUGEPAGES_OC, 0, 0); + /* We should be able to allocate the whole pool */ void *p = get_huge_pages(num_hugepages * hpage_size, GHP_DEFAULT); if (p == NULL) diff --git a/tests/run_tests.sh b/tests/run_tests.sh index a40c9d5..580b040 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -211,19 +211,6 @@ restore_shm_sysctl() { fi } -setup_dynamic_pool_sysctl() { - if [ -f /proc/sys/vm/nr_overcommit_hugepages ]; then - DYNAMIC_POOL=`cat /proc/sys/vm/nr_overcommit_hugepages` - echo 10 > /proc/sys/vm/nr_overcommit_hugepages - fi -} - -restore_dynamic_pool_sysctl() { - if [ -f /proc/sys/vm/nr_overcommit_hugepages ]; then - echo "$DYNAMIC_POOL" > /proc/sys/vm/nr_overcommit_hugepages - fi -} - functional_tests () { # Kernel background tests not requiring hugepage support run_test zero_filesize_segment @@ -308,9 +295,7 @@ check_linkhuge_tests # Test accounting of HugePages_{Total|Free|Resv|Surp} # Alters the size of the hugepage pool so should probably be run last - setup_dynamic_pool_sysctl run_test counters - restore_dynamic_pool_sysctl } stress_tests () { ------------------------------------------------------------------------- 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