extend .request_hugepages
v2 cover extend .request_hugepages
Changes from v1 to v2:
* rename .request_hugepages to .hugepages
* redefine tst_policy to TST_REQUEST, TST_NEEDS
* remove use array in struct tst_hugepage
* rename API funcion to tst_reserve_hugepages();
Li Wang (3):
lib: extend .request_hugepages to guarantee enough hpages
memfd_create03: make use of new .hugepages
hugetlb: make use of new .hugepages
doc/c-test-api.txt | 34 ++++++--- include/tst_hugepage.h | 14 +++- include/tst_test.h | 26 +++++-- lib/newlib_tests/test20.c | 14 ++-- lib/newlib_tests/test_zero_hugepage.c | 9 ++- lib/tst_hugepage.c | 22 +++++- lib/tst_test.c | 4 +- .../kernel/mem/hugetlb/hugemmap/hugemmap01.c | 2 +- .../kernel/mem/hugetlb/hugemmap/hugemmap02.c | 2 +- .../kernel/mem/hugetlb/hugemmap/hugemmap04.c | 2 +- .../kernel/mem/hugetlb/hugemmap/hugemmap05.c | 5 +- .../kernel/mem/hugetlb/hugemmap/hugemmap06.c | 4 +- .../mem/hugetlb/hugeshmat/hugeshmat01.c | 2 +- .../mem/hugetlb/hugeshmat/hugeshmat02.c | 2 +- .../mem/hugetlb/hugeshmat/hugeshmat03.c | 2 +- .../mem/hugetlb/hugeshmat/hugeshmat04.c | 12 +-- .../mem/hugetlb/hugeshmat/hugeshmat05.c | 5 +- .../mem/hugetlb/hugeshmctl/hugeshmctl01.c | 2 +- .../mem/hugetlb/hugeshmctl/hugeshmctl02.c | 2 +- .../mem/hugetlb/hugeshmctl/hugeshmctl03.c | 2 +- .../mem/hugetlb/hugeshmdt/hugeshmdt01.c | 2 +- .../mem/hugetlb/hugeshmget/hugeshmget01.c | 2 +- .../mem/hugetlb/hugeshmget/hugeshmget02.c | 2 +- .../mem/hugetlb/hugeshmget/hugeshmget03.c | 2 +- .../mem/hugetlb/hugeshmget/hugeshmget05.c | 2 +- .../kernel/syscalls/futex/futex_wake04.c | 5 +- .../kernel/syscalls/ipc/shmget/shmget02.c | 2 +- .../syscalls/memfd_create/memfd_create03.c | 74 +------------------ testcases/kernel/syscalls/pkeys/pkey01.c | 4 +- 29 files changed, 113 insertions(+), 149 deletions(-)
Signature · 5 lines
2.36.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/3 lib: extend .request_hugepages to guarantee enough hpages
This is to satisfy tests which need to reserve hugepage precisely for using, with eliminating other process side effects at the same time.
For example, if there are 'N' (N > 1) hpages reserved but all occupying. New '.request_hugepage = 1' in another test will only save the N and do echo 1 into hugetlbfs. That obviously may cause problems during test run.
Here, we introduce two policies to make hugepage reserve work fit for more requirements but no need to care about details. And simply rename .request_hugepages to .hugepages.
--- doc/c-test-api.txt | 34 +++++++++++++++++---------- include/tst_hugepage.h | 14 +++++++++-- include/tst_test.h | 26 +++++++++++++------- lib/newlib_tests/test20.c | 14 ++++++----- lib/newlib_tests/test_zero_hugepage.c | 9 +++---- lib/tst_hugepage.c | 22 +++++++++++++---- lib/tst_test.c | 4 ++-- 7 files changed, 85 insertions(+), 38 deletions(-)
doc/c-test-api.txt +22 -12
@@ -1998,15 +1998,24 @@ For full documentation see the comments in 'include/tst_fuzzy_sync.h'. ~~~~~~~~~~~~~~~~~~~~~~~~ Many of the LTP tests need to use hugepage in their testing, this allows the -test can reserve hugepages from system only via '.request_hugepages = xx'. +test can reserve hugepages from system via '.hugepages = {xx, TST_REQUEST}'. -If set non-zero number of 'request_hugepages', test will try to reserve the -expected number of hugepage for testing in setup phase. If system does not -have enough hpage for using, it will try the best to reserve 80% available -number of hpages. With success test stores the reserved hugepage number in -'tst_hugepages'. For the system without hugetlb supporting, variable -'tst_hugepages' will be set to 0. If the hugepage number needs to be set to 0 -on supported hugetlb system, please use '.request_hugepages = TST_NO_HUGEPAGES'. +We achieved two policies for hugepage reserving: + +TST_REQUEST: + If set non-zero number in .hugepages, ltp will try to reserve the expected + number of hugepage for testing in setup phase. If system doesn't have enough + memory for that, it will try the best to reserve 80% available huge pages. + +TST_NEEDS: + This is an enforced requirement for hugepage reserve, LTP should strictly do + hpages applying and guarantee the 'HugePages_Free' no less than pages which + gives that test can use these specified numbers correctly. + +With success test stores the reserved hugepage number in 'tst_hugepages'. For +system without hugetlb supporting, variable 'tst_hugepages' will be set to 0. +If the hugepage number needs to be set to 0 on supported hugetlb system, please +use '.hugepages = {TST_NO_HUGEPAGES, TST_REQUEST}'. Also, we do cleanup and restore work for the hpages resetting automatically.
@@ -2018,7 +2027,7 @@ static void run(void) { ... - if (tst_hugepages == test.request_hugepages) + if (tst_hugepages == test.hugepages.number) TEST(do_hpage_test); else ...
@@ -2027,7 +2036,7 @@ static void run(void) struct tst_test test = { .test_all = run, - .request_hugepages = 2, + .hugepages = {2, TST_REQUEST}, ... }; -------------------------------------------------------------------------------
@@ -2045,13 +2054,14 @@ static void run(void) static void setup(void) { - if (tst_hugepages != test.requested_hugepages) + /* TST_NEEDS achieved this automatically in the library */ + if (tst_hugepages != test.hugepages.number) tst_brk(TCONF, "..."); } struct tst_test test = { .test_all = run, - .request_hugepages = 2, + .hugepages = {2, TST_NEEDS}, ... }; -------------------------------------------------------------------------------
include/tst_hugepage.h +12 -2
@@ -12,6 +12,16 @@extern char *nr_opt;/* -s num Set the number of the been allocated hugepages */ extern char *Hopt;/* -H /.. Location of hugetlbfs, i.e. -H /var/hugetlbfs */ +enum tst_hp_policy { +TST_REQUEST , +TST_NEEDS , +}; + +struct tst_hugepage { +const unsigned long number; +enum tst_hp_policy policy; +}; +/* * Get the default hugepage size. Returns 0 if hugepages are not supported. */
@@ -23,11 +33,11 @@ size_t tst_get_hugepage_size(void);* * Note: this depend on the status of system memory fragmentation. */ -unsigned long tst_request_hugepages (unsigned long hpages); +unsigned long tst_reserve_hugepages (struct tst_hugepage *hp);/* * This variable is used for recording the number of hugepages which system can -* provides. It will be equal to 'hpages' if tst_request_hugepages on success, +* provides. It will be equal to 'hpages' if tst_reserve_hugepages on success, * otherwise set it to a number of hugepages that we were able to reserve. * * If system does not support hugetlb, then it will be set to 0.
include/tst_test.h +18 -8
@@ -191,17 +191,27 @@ struct tst_test {unsigned long min_mem_avail;/* -* If set non-zero number of request_hugepages, test will try to reserve the -* expected number of hugepage for testing in setup phase. If system does not -* have enough hpage for using, it will try the best to reserve 80% available -* number of hpages. With success test stores the reserved hugepage number in -* 'tst_hugepages. For the system without hugetlb supporting, variable -* 'tst_hugepages' will be set to 0. If the hugepage number needs to be set to -* 0 on supported hugetlb system, please use '.request_hugepages = TST_NO_HUGEPAGES'. +* Two policies for hugepage reserving: +* +* TST_REQUEST: +* If set non-zero number in .hugepages, ltp will try to reserve the expected +* number of hugepage for testing in setup phase. If system does not have enough +* memory for that, it will try the best to reserve 80% available huge pages. +* +* TST_NEEDS: +* This is an enforced requirement for huge page reserve, ltp should strictly do +* hpages applying and guarantee the 'HugePages_Free' no less than specified pages +* which gives that test can use these specified numbers correctly. +* +* +* With success test stores the reserved hugepage number in 'tst_hugepages. For +* the system without hugetlb supporting, variable 'tst_hugepages' will be set to 0. +* If the hugepage number needs to be set to 0 on supported hugetlb system, please +* use '.hugepages = {TST_NO_HUGEPAGES, TST_REQUEST}'. * * Also, we do cleanup and restore work for the hpages resetting automatically. */ -unsigned long request_hugepages; +struct tst_hugepage hugepages;/* * If set to non-zero, call tst_taint_init(taint_check) during setup
lib/newlib_tests/test20.c +8 -6
@@ -4,7 +4,7 @@*/ /* -* Tests .request_hugepages + .save_restore +* Tests .hugepages + .save_restore */ #include "tst_test.h"
@@ -18,24 +18,26 @@ static void do_test(void) {tst_res (TINFO ,"tst_hugepages = %lu" , tst_hugepages);SAFE_FILE_PRINTF ("/proc/sys/kernel/numa_balancing" ,"1" ); - hpages = test.request_hugepages; + hpages = test.hugepages.number;SAFE_FILE_SCANF (PATH_NR_HPAGES ,"%lu" , &val);if (val != hpages)tst_brk (TBROK ,"nr_hugepages = %lu, but expect %lu" , val, hpages);else -tst_res (TPASS ,"test .needs_hugepges" ); +tst_res (TPASS ,"test .hugepges" ); + +struct tst_hugepage hp = {1000000000000 ,TST_REQUEST }; + hpages =tst_reserve_hugepages (&hp); - hpages =tst_request_hugepages (3 );SAFE_FILE_SCANF (PATH_NR_HPAGES ,"%lu" , &val);if (val != hpages)tst_brk (TBROK ,"nr_hugepages = %lu, but expect %lu" , val, hpages);else -tst_res (TPASS ,"tst_request_hugepages" ); +tst_res (TPASS ,"tst_reserve_hugepages" ); }static struct tst_test test = { .test_all = do_test, - .request_hugepages =2 , + .hugepages = {2 ,TST_NEEDS }, .save_restore = (const struct tst_path_val []) { {"!/proc/sys/kernel/numa_balancing" ,"0" }, {}
lib/newlib_tests/test_zero_hugepage.c +5 -4
@@ -19,17 +19,18 @@ static void do_test(void)if (val !=0 )tst_brk (TBROK ,"nr_hugepages = %lu, but expect 0" , val);else -tst_res (TPASS ,"test .request_hugepages = TST_NO_HUGEPAGES" ); +tst_res (TPASS ,"test .hugepages = {TST_NO_HUGEPAGES, TST_REQUEST}" ); - hpages =tst_request_hugepages (3 ); +struct tst_hugepage hp = {3 ,TST_REQUEST }; + hpages =tst_reserve_hugepages (&hp);SAFE_FILE_SCANF (PATH_NR_HPAGES ,"%lu" , &val);if (val != hpages)tst_brk (TBROK ,"nr_hugepages = %lu, but expect %lu" , val, hpages);else -tst_res (TPASS ,"tst_request_hugepages" ); +tst_res (TPASS ,"tst_reserve_hugepages" ); }static struct tst_test test = { .test_all = do_test, - .request_hugepages =TST_NO_HUGEPAGES , + .hugepages = {TST_NO_HUGEPAGES ,TST_REQUEST }, };
lib/tst_hugepage.c +18 -4
@@ -20,11 +20,13 @@ size_t tst_get_hugepage_size(void)return SAFE_READ_MEMINFO ("Hugepagesize:" ) *1024 ; } -unsigned long tst_request_hugepages (unsigned long hpages) +unsigned long tst_reserve_hugepages (struct tst_hugepage *hp) {unsigned long val, max_hpages;if (access (PATH_HUGEPAGES ,F_OK )) { +if (hp->policy ==TST_NEEDS ) +tst_brk (TCONF ,"hugetlbfs is not supported" ); tst_hugepages =0 ; goto out; }
@@ -32,16 +34,20 @@ unsigned long tst_request_hugepages(unsigned long hpages)if (nr_opt) tst_hugepages =SAFE_STRTOL (nr_opt,1 ,LONG_MAX );else - tst_hugepages = hpages; + tst_hugepages = hp->number; -if (hpages ==TST_NO_HUGEPAGES ) { +if (hp->number ==TST_NO_HUGEPAGES ) { tst_hugepages =0 ; goto set_hugepages; }SAFE_FILE_PRINTF ("/proc/sys/vm/drop_caches" ,"3" ); - max_hpages =SAFE_READ_MEMINFO ("MemFree:" ) /SAFE_READ_MEMINFO ("Hugepagesize:" ); +if (hp->policy ==TST_NEEDS ) { + tst_hugepages +=SAFE_READ_MEMINFO ("HugePages_Total:" ); + goto set_hugepages; + } + max_hpages =SAFE_READ_MEMINFO ("MemFree:" ) /SAFE_READ_MEMINFO ("Hugepagesize:" );if (tst_hugepages > max_hpages) { tst_res(TINFO, "Requested number(%lu) of hugepages is too large, " "limiting to 80%% of the max hugepage count %lu",
@@ -61,6 +67,14 @@ set_hugepages:"Not enough hugepages for testing." , val, tst_hugepages); +if (hp->policy ==TST_NEEDS ) { +unsigned long free_hpages =SAFE_READ_MEMINFO ("HugePages_Free:" ); +if (hp->number > free_hpages) +tst_brk (TCONF ,"free_hpages = %lu, but expect %lu. " +"Not enough hugepages for testing." , + free_hpages, hp->number); + } +tst_res (TINFO ,"%lu hugepage(s) reserved" , tst_hugepages); out:return tst_hugepages;
lib/tst_test.c +2 -2
@@ -1164,8 +1164,8 @@ static void do_setup(int argc, char *argv[])if (tst_test->min_mem_avail > (unsigned long )(tst_available_mem () /1024 ))tst_brk (TCONF ,"Test needs at least %luMB MemAvailable" , tst_test->min_mem_avail); -if (tst_test->request_hugepages) -tst_request_hugepages (tst_test->request_hugepages); +if (tst_test->hugepages.number) +tst_reserve_hugepages (&tst_test->hugepages);setup_ipc ();
Signature · 5 lines
2.36.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 1/3] lib: extend .request_hugepages to guarantee enough hpages
Hi!
Quoted 31 lines
This is to satisfy tests which need to reserve hugepage precisely for using, with eliminating other process side effects at the same time.
For example, if there are 'N' (N > 1) hpages reserved but all occupying. New '.request_hugepage = 1' in another test will only save the N and do echo 1 into hugetlbfs. That obviously may cause problems during test run.
Here, we introduce two policies to make hugepage reserve work fit for more requirements but no need to care about details. And simply rename .request_hugepages to .hugepages.
Signed-off-by Li Wang <[email protected]>--- doc/c-test-api.txt | 34 +++++++++++++++++---------- include/tst_hugepage.h | 14 +++++++++-- include/tst_test.h | 26 +++++++++++++------- lib/newlib_tests/test20.c | 14 ++++++----- lib/newlib_tests/test_zero_hugepage.c | 9 +++---- lib/tst_hugepage.c | 22 +++++++++++++---- lib/tst_test.c | 4 ++-- 7 files changed, 85 insertions(+), 38 deletions(-)doc/c-test-api.txt +0
-1@@ -1998,15 +1998,24 @@ For full documentation see the comments in 'include/tst_fuzzy_sync.h'. ~~~~~~~~~~~~~~~~~~~~~~~~ Many of the LTP tests need to use hugepage in their testing, this allows the -test can reserve hugepages from system only via '.request_hugepages = xx'.
doc/c-test-api.txt For full documentation see the comments in 'include/tst_fuzzy_sync.h'. · line 2003
Quoted 10 lines
doc/c-test-api.txt +2
-7+test can reserve hugepages from system via '.hugepages = {xx, TST_REQUEST}'. -If set non-zero number of 'request_hugepages', test will try to reserve the -expected number of hugepage for testing in setup phase. If system does not -have enough hpage for using, it will try the best to reserve 80% available -number of hpages. With success test stores the reserved hugepage number in -'tst_hugepages'. For the system without hugetlb supporting, variable -'tst_hugepages' will be set to 0. If the hugepage number needs to be set to 0 -on supported hugetlb system, please use '.request_hugepages = TST_NO_HUGEPAGES'. +We achieved two policies for hugepage reserving:
^ reserving hugepages:
doc/c-test-api.txt For full documentation see the comments in 'include/tst_fuzzy_sync.h'. · line 2008
Quoted 5 lines
doc/c-test-api.txt +5
-0+ +TST_REQUEST: + If set non-zero number in .hugepages, ltp will try to reserve the expected + number of hugepage for testing in setup phase. If system doesn't have enough + memory for that, it will try the best to reserve 80% available huge pages.
Maybe just "it will try the best to reserver available huge pages and return the number of available hugepages in .hugepages.number, which may be 0 if hugepages are not supported at all."
doc/c-test-api.txt For full documentation see the comments in 'include/tst_fuzzy_sync.h'. · line 2013
Quoted 4 lines
doc/c-test-api.txt +4
-0+TST_NEEDS: + This is an enforced requirement for hugepage reserve, LTP should strictly do + hpages applying and guarantee the 'HugePages_Free' no less than pages which + gives that test can use these specified numbers correctly.
We should stress here that test exits with TCONF if the attempt to reserver hugepages fails or reserves less than requested.
doc/c-test-api.txt For full documentation see the comments in 'include/tst_fuzzy_sync.h'. · line 2018
Quoted 4 lines
doc/c-test-api.txt +4
-0+With success test stores the reserved hugepage number in 'tst_hugepages'. For +system without hugetlb supporting, variable 'tst_hugepages' will be set to 0. +If the hugepage number needs to be set to 0 on supported hugetlb system, please +use '.hugepages = {TST_NO_HUGEPAGES, TST_REQUEST}'.
I guess that we don't even set the second value here, we can as well simplify to: .hugepages = {TST_NO_HUGEPAGES}
Quoted 21 lines
doc/c-test-api.txt +2
-2Also, we do cleanup and restore work for the hpages resetting automatically.@@ -2018,7 +2027,7 @@ static void run(void) { - if (tst_hugepages == test.request_hugepages) + if (tst_hugepages == test.hugepages.number) TEST(do_hpage_test); else@@ -2027,7 +2036,7 @@ static void run(void) struct tst_test test = { .test_all = run, - .request_hugepages = 2, + .hugepages = {2, TST_REQUEST}, }; -------------------------------------------------------------------------------
doc/c-test-api.txt static void run(void) · line 2059
Quoted 7 lines
doc/c-test-api.txt +2
-1@@ -2045,13 +2054,14 @@ static void run(void) static void setup(void) { -?? ?? ?? ?? if (tst_hugepages != test.requested_hugepages) + /* TST_NEEDS achieved this automatically in the library */ +?? ?? ?? ?? if (tst_hugepages != test.hugepages.number) ?? ?? ?? ?? ?? ?? ?? ?? tst_brk(TCONF, "...");
^
Non ascii whitespaces?
Quoted 66 lines
doc/c-test-api.txt +1
-1} struct tst_test test = { .test_all = run, - .request_hugepages = 2, + .hugepages = {2, TST_NEEDS}, }; -------------------------------------------------------------------------------include/tst_hugepage.h +12
-2@@ -12,6 +12,16 @@extern char *nr_opt;/* -s num Set the number of the been allocated hugepages */ extern char *Hopt;/* -H /.. Location of hugetlbfs, i.e. -H /var/hugetlbfs */ +enum tst_hp_policy { +TST_REQUEST , +TST_NEEDS , +}; + +struct tst_hugepage { +const unsigned long number; +enum tst_hp_policy policy; +}; +/* * Get the default hugepage size. Returns 0 if hugepages are not supported. */ @@ -23,11 +33,11 @@ size_t tst_get_hugepage_size(void);* * Note: this depend on the status of system memory fragmentation. */ -unsigned long tst_request_hugepages (unsigned long hpages); +unsigned long tst_reserve_hugepages (struct tst_hugepage *hp);/* * This variable is used for recording the number of hugepages which system can -* provides. It will be equal to 'hpages' if tst_request_hugepages on success, +* provides. It will be equal to 'hpages' if tst_reserve_hugepages on success, * otherwise set it to a number of hugepages that we were able to reserve. * * If system does not support hugetlb, then it will be set to 0. include/tst_test.h +7
-7@@ -191,17 +191,27 @@ struct tst_test {unsigned long min_mem_avail;/* -* If set non-zero number of request_hugepages, test will try to reserve the -* expected number of hugepage for testing in setup phase. If system does not -* have enough hpage for using, it will try the best to reserve 80% available -* number of hpages. With success test stores the reserved hugepage number in -* 'tst_hugepages. For the system without hugetlb supporting, variable -* 'tst_hugepages' will be set to 0. If the hugepage number needs to be set to -* 0 on supported hugetlb system, please use '.request_hugepages = TST_NO_HUGEPAGES'. +* Two policies for hugepage reserving: +* +* TST_REQUEST: +* If set non-zero number in .hugepages, ltp will try to reserve the expected +* number of hugepage for testing in setup phase. If system does not have enough +* memory for that, it will try the best to reserve 80% available huge pages. +*
include/tst_test.h struct tst_test { · line 210
Quoted 10 lines
include/tst_test.h +10
-0+* TST_NEEDS: +* This is an enforced requirement for huge page reserve, ltp should strictly do +* hpages applying and guarantee the 'HugePages_Free' no less than specified pages +* which gives that test can use these specified numbers correctly. +* +* +* With success test stores the reserved hugepage number in 'tst_hugepages. For +* the system without hugetlb supporting, variable 'tst_hugepages' will be set to 0. +* If the hugepage number needs to be set to 0 on supported hugetlb system, please +* use '.hugepages = {TST_NO_HUGEPAGES, TST_REQUEST}'.
Here as well (update the docs).
Quoted 124 lines
include/tst_test.h +1
-1* Also, we do cleanup and restore work for the hpages resetting automatically. */ -unsigned long request_hugepages; +struct tst_hugepage hugepages;/* * If set to non-zero, call tst_taint_init(taint_check) during setup lib/newlib_tests/test20.c +8
-6@@ -4,7 +4,7 @@*/ /* -* Tests .request_hugepages + .save_restore +* Tests .hugepages + .save_restore */ #include "tst_test.h" @@ -18,24 +18,26 @@ static void do_test(void) {tst_res (TINFO ,"tst_hugepages = %lu" , tst_hugepages);SAFE_FILE_PRINTF ("/proc/sys/kernel/numa_balancing" ,"1" ); - hpages = test.request_hugepages; + hpages = test.hugepages.number;SAFE_FILE_SCANF (PATH_NR_HPAGES ,"%lu" , &val);if (val != hpages)tst_brk (TBROK ,"nr_hugepages = %lu, but expect %lu" , val, hpages);else -tst_res (TPASS ,"test .needs_hugepges" ); +tst_res (TPASS ,"test .hugepges" ); + +struct tst_hugepage hp = {1000000000000 ,TST_REQUEST }; + hpages =tst_reserve_hugepages (&hp); - hpages =tst_request_hugepages (3 );SAFE_FILE_SCANF (PATH_NR_HPAGES ,"%lu" , &val);if (val != hpages)tst_brk (TBROK ,"nr_hugepages = %lu, but expect %lu" , val, hpages);else -tst_res (TPASS ,"tst_request_hugepages" ); +tst_res (TPASS ,"tst_reserve_hugepages" ); }static struct tst_test test = { .test_all = do_test, - .request_hugepages =2 , + .hugepages = {2 ,TST_NEEDS }, .save_restore = (const struct tst_path_val []) { {"!/proc/sys/kernel/numa_balancing" ,"0" }, {}lib/newlib_tests/test_zero_hugepage.c +5
-4@@ -19,17 +19,18 @@ static void do_test(void)if (val !=0 )tst_brk (TBROK ,"nr_hugepages = %lu, but expect 0" , val);else -tst_res (TPASS ,"test .request_hugepages = TST_NO_HUGEPAGES" ); +tst_res (TPASS ,"test .hugepages = {TST_NO_HUGEPAGES, TST_REQUEST}" ); - hpages =tst_request_hugepages (3 ); +struct tst_hugepage hp = {3 ,TST_REQUEST }; + hpages =tst_reserve_hugepages (&hp);SAFE_FILE_SCANF (PATH_NR_HPAGES ,"%lu" , &val);if (val != hpages)tst_brk (TBROK ,"nr_hugepages = %lu, but expect %lu" , val, hpages);else -tst_res (TPASS ,"tst_request_hugepages" ); +tst_res (TPASS ,"tst_reserve_hugepages" ); }static struct tst_test test = { .test_all = do_test, - .request_hugepages =TST_NO_HUGEPAGES , + .hugepages = {TST_NO_HUGEPAGES ,TST_REQUEST }, };lib/tst_hugepage.c +10
-4@@ -20,11 +20,13 @@ size_t tst_get_hugepage_size(void)return SAFE_READ_MEMINFO ("Hugepagesize:" ) *1024 ; } -unsigned long tst_request_hugepages (unsigned long hpages) +unsigned long tst_reserve_hugepages (struct tst_hugepage *hp) {unsigned long val, max_hpages;if (access (PATH_HUGEPAGES ,F_OK )) { +if (hp->policy ==TST_NEEDS ) +tst_brk (TCONF ,"hugetlbfs is not supported" ); tst_hugepages =0 ; goto out; }@@ -32,16 +34,20 @@ unsigned long tst_request_hugepages(unsigned long hpages)if (nr_opt) tst_hugepages =SAFE_STRTOL (nr_opt,1 ,LONG_MAX );else - tst_hugepages = hpages; + tst_hugepages = hp->number; -if (hpages ==TST_NO_HUGEPAGES ) { +if (hp->number ==TST_NO_HUGEPAGES ) { tst_hugepages =0 ; goto set_hugepages; }SAFE_FILE_PRINTF ("/proc/sys/vm/drop_caches" ,"3" ); - max_hpages =SAFE_READ_MEMINFO ("MemFree:" ) /SAFE_READ_MEMINFO ("Hugepagesize:" ); +if (hp->policy ==TST_NEEDS ) { + tst_hugepages +=SAFE_READ_MEMINFO ("HugePages_Total:" ); + goto set_hugepages; + } + max_hpages =SAFE_READ_MEMINFO ("MemFree:" ) /SAFE_READ_MEMINFO ("Hugepagesize:" );if (tst_hugepages > max_hpages) { tst_res(TINFO, "Requested number(%lu) of hugepages is too large, " "limiting to 80%% of the max hugepage count %lu",@@ -61,6 +67,14 @@ set_hugepages: "Not enough hugepages for testing.",
lib/tst_hugepage.c set_hugepages: · line 77
Quoted 10 lines
lib/tst_hugepage.c +8
-0val, tst_hugepages); +if (hp->policy ==TST_NEEDS ) { +unsigned long free_hpages =SAFE_READ_MEMINFO ("HugePages_Free:" ); +if (hp->number > free_hpages) +tst_brk (TCONF ,"free_hpages = %lu, but expect %lu. " +"Not enough hugepages for testing." , + free_hpages, hp->number); + } +
Minus the minor comments the code looks good, with the small issues fixed:
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 2/3 memfd_create03: make use of new .hugepages
In reply to Li WangTo get rid of some failures like:
memfd_create03.c:179: TINFO: --TESTING PAGE SIZE OF CREATED FILE-- memfd_create03.c:184: TINFO: memfd_create() succeeded memfd_create03.c:47: TBROK: mmap((nil),1048576,2,2,3,0) failed: ENOMEM (12)
--- .../syscalls/memfd_create/memfd_create03.c | 74 +------------------ 1 file changed, 4 insertions(+), 70 deletions(-)
testcases/kernel/syscalls/memfd_create/memfd_create03.c +4 -70
@@ -32,14 +32,6 @@#include <stdio.h> #include <errno.h> -#define TOTAL_HP_PATH "/proc/sys/vm/nr_hugepages" -#define MEMINFO_PATH "/proc/meminfo" -#define FREE_HP "HugePages_Free:\t%ld" -#define DEFAULT_HPS "Hugepagesize:\t%ld kB" - -static int hugepages_allocated; -static long og_total_pages; -static void *check_huge_mmapable (int fd,unsigned long size) {void *mem;
@@ -88,7 +80,7 @@ static void test_def_pagesize(int fd)long hps;void *mem; -SAFE_FILE_LINES_SCANF (MEMINFO_PATH ,DEFAULT_HPS , &hps); + hps =SAFE_READ_MEMINFO ("Hugepagesize:" ); hps = hps <<10 ; unmap_size = hps /4 ; mem =check_huge_mmapable (fd, hps);
@@ -128,8 +120,8 @@ static void test_max_hugepages(int fd)void *mem;void *new_mem; -SAFE_FILE_LINES_SCANF (MEMINFO_PATH ,FREE_HP , &free_pages); -SAFE_FILE_LINES_SCANF (MEMINFO_PATH ,DEFAULT_HPS , &hps); + free_pages =SAFE_READ_MEMINFO ("HugePages_Free:" ); + hps =SAFE_READ_MEMINFO ("Hugepagesize:" ); hps = hps <<10 ; mem =check_huge_mmapable (fd, free_pages * hps);
@@ -188,68 +180,10 @@ static void memfd_huge_controller(unsigned int n)SAFE_CLOSE (fd); } -static void setup (void ) -{ -char buf[8 ]; -int fd; -long free_pages; -long total_pages; - -if (access (MEMINFO_PATH ,F_OK ) || -access ("/sys/kernel/mm/hugepages" ,F_OK ) || -access (TOTAL_HP_PATH ,F_OK )) -tst_brk (TCONF ,"Huge page is not supported" ); - -SAFE_FILE_LINES_SCANF (MEMINFO_PATH ,FREE_HP , &free_pages); -if (free_pages >0 ) -return ; - -SAFE_FILE_LINES_SCANF (TOTAL_HP_PATH ,"%ld" , &og_total_pages); -sprintf (buf,"%ld" , og_total_pages +1 ); - - fd =SAFE_OPEN (TOTAL_HP_PATH ,O_RDWR |O_TRUNC ); - -if (write (fd, buf,strlen (buf)) ==-1 ) -tst_brk (TCONF |TERRNO , -"write() fail: Hugepage allocation failed" ); - -SAFE_CLOSE (fd); - -SAFE_FILE_LINES_SCANF (TOTAL_HP_PATH ,"%ld" , &total_pages); -if (total_pages != (og_total_pages +1 )) -tst_brk (TCONF ,"Hugepage allocation failed" ); - - hugepages_allocated =1 ; -} - -static void cleanup (void ) -{ -char buf[8 ]; -int fd; -long total_pages; - -if (hugepages_allocated ==0 ) -return ; - -sprintf (buf,"%ld" , og_total_pages); - - fd =SAFE_OPEN (TOTAL_HP_PATH ,O_RDWR |O_TRUNC ); - -if (write (fd, buf,strlen (buf)) ==-1 ) -tst_brk (TCONF |TERRNO ,"Clean-up failed: write() failed" ); - -SAFE_CLOSE (fd); - -SAFE_FILE_LINES_SCANF (TOTAL_HP_PATH ,"%ld" , &total_pages); -if (og_total_pages != total_pages) -tst_brk (TCONF ,"Clean-up failed" ); -} -static struct tst_test test = { - .setup = setup, .test = memfd_huge_controller, .tcnt =ARRAY_SIZE (tcases), .needs_root =1 , .min_kver ="4.14" , - .cleanup = cleanup, + .hugepages = {1 ,TST_NEEDS }, };
Signature · 5 lines
2.36.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 2/3] memfd_create03: make use of new .hugepages
Hi!
Nice cleanup.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 3/3 hugetlb: make use of new .hugepages
In reply to Li Wang--- testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c | 2 +- testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c | 2 +- testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c | 2 +- testcases/kernel/mem/hugetlb/hugemmap/hugemmap05.c | 5 +---- testcases/kernel/mem/hugetlb/hugemmap/hugemmap06.c | 4 +--- testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat01.c | 2 +- testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat02.c | 2 +- testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat03.c | 2 +- testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c | 12 +++--------- testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat05.c | 5 +---- .../kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c | 2 +- .../kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c | 2 +- .../kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c | 2 +- testcases/kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c | 2 +- .../kernel/mem/hugetlb/hugeshmget/hugeshmget01.c | 2 +- .../kernel/mem/hugetlb/hugeshmget/hugeshmget02.c | 2 +- .../kernel/mem/hugetlb/hugeshmget/hugeshmget03.c | 2 +- .../kernel/mem/hugetlb/hugeshmget/hugeshmget05.c | 2 +- testcases/kernel/syscalls/futex/futex_wake04.c | 5 +---- testcases/kernel/syscalls/ipc/shmget/shmget02.c | 2 +- testcases/kernel/syscalls/pkeys/pkey01.c | 4 ++-- 21 files changed, 24 insertions(+), 41 deletions(-)
testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c +1 -1
@@ -98,5 +98,5 @@ static struct tst_test test = { .setup = setup, .cleanup = cleanup, .test_all = test_hugemmap, - .request_hugepages = 128, + .hugepages = {128, TST_REQUEST}, };
testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c +1 -1
@@ -145,5 +145,5 @@ static struct tst_test test = { .setup = setup, .cleanup = cleanup, .test_all = test_hugemmap, - .request_hugepages = 128, + .hugepages = {128, TST_REQUEST}, };
testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c +1 -1
@@ -116,5 +116,5 @@ static struct tst_test test = { .setup = setup, .cleanup = cleanup, .test_all = test_hugemmap, - .request_hugepages = 128, + .hugepages = {128, TST_REQUEST}, };
testcases/kernel/mem/hugetlb/hugemmap/hugemmap05.c +1 -4
@@ -185,9 +185,6 @@ static void setup(void) {unsigned long hpages; -if (tst_hugepages !=NR_HPAGES ) -tst_brk (TCONF ,"Not enough hugepages for testing!" ); - hugepagesize =SAFE_READ_MEMINFO ("Hugepagesize:" ) *1024 ;init_sys_sz_paths ();
@@ -307,5 +304,5 @@ static struct tst_test test = { .setup = setup, .cleanup = cleanup, .test_all = test_overcommit, - .request_hugepages = NR_HPAGES, + .hugepages = {NR_HPAGES, TST_NEEDS}, };
testcases/kernel/mem/hugetlb/hugemmap/hugemmap06.c +1 -3
@@ -39,8 +39,6 @@ struct mp {static void setup (void ) { -if (tst_hugepages != test.request_hugepages) -tst_brk (TCONF ,"System RAM is not enough to test." ); hpage_size =SAFE_READ_MEMINFO ("Hugepagesize:" ) *1024 ; }
@@ -122,7 +120,7 @@ static struct tst_test test = { .needs_tmpdir = 1, .test = do_mmap, .setup = setup, - .request_hugepages = (ARSZ + 1) * LOOP, + .hugepages = {(ARSZ + 1) * LOOP, TST_NEEDS}, .tags = (const struct tst_tag[]) { {"linux-git" ,"f522c3ac00a4" }, {"linux-git", "9119a41e9091"},
testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat01.c +1 -1
@@ -180,5 +180,5 @@ static struct tst_test test = { .test = verify_hugeshmat, .setup = setup, .cleanup = cleanup, - .request_hugepages = 128, + .hugepages = {128, TST_REQUEST}, };
testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat02.c +1 -1
@@ -107,5 +107,5 @@ static struct tst_test test = { .test = verify_hugeshmat, .setup = setup, .cleanup = cleanup, - .request_hugepages = 128, + .hugepages = {128, TST_REQUEST}, };
testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat03.c +1 -1
@@ -101,5 +101,5 @@ static struct tst_test test = { .test_all = verify_hugeshmat, .setup = setup, .cleanup = cleanup, - .request_hugepages = 128, + .hugepages = {128, TST_REQUEST}, };
testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c +3 -9
@@ -27,7 +27,6 @@static long huge_free;static long huge_free2; -static long hugepages;static long orig_shmmax =-1 , new_shmmax;static void shared_hugepage (void );
@@ -83,9 +82,6 @@ static void setup(void) {long hpage_size, orig_hugepages; -if (tst_hugepages ==0 ) -tst_brk (TCONF ,"Not enough hugepages for testing." ); - orig_hugepages =get_sys_tune ("nr_hugepages" );SAFE_FILE_SCANF (PATH_SHMMAX ,"%ld" , &orig_shmmax);SAFE_FILE_PRINTF (PATH_SHMMAX ,"%ld" , (long )SIZE );
@@ -96,10 +92,8 @@ static void setup(void) hpage_size =SAFE_READ_MEMINFO ("Hugepagesize:" ) *1024 ; - hugepages = orig_hugepages +SIZE / hpage_size; -tst_request_hugepages (hugepages); -if (tst_hugepages != (unsigned long )hugepages) -tst_brk (TCONF ,"No enough hugepages for testing." ); +struct tst_hugepage hp = { orig_hugepages +SIZE / hpage_size,TST_NEEDS }; +tst_reserve_hugepages (&hp); }static void cleanup (void )
@@ -121,5 +115,5 @@ static struct tst_test test = { .min_mem_avail = 2048, .setup = setup, .cleanup = cleanup, - .request_hugepages = 1, + .hugepages = {1, TST_NEEDS}, };
testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat05.c +1 -4
@@ -35,9 +35,6 @@ static long hpage_size;void setup (void ) { -if (tst_hugepages != test.request_hugepages) -tst_brk (TCONF ,"Not enough hugepages for testing." ); - page_size =getpagesize (); hpage_size =SAFE_READ_MEMINFO ("Hugepagesize:" ) *1024 ; }
@@ -91,7 +88,7 @@ static struct tst_test test = { .needs_tmpdir = 1, .test_all = test_hugeshmat, .setup = setup, - .request_hugepages = N + 1, + .hugepages = {N+1, TST_NEEDS}, .tags = (const struct tst_tag[]) { {"linux-git" ,"091d0d55b286" }, {"linux-git", "af73e4d9506d"},
testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c +1 -1
@@ -310,5 +310,5 @@ static struct tst_test test = { .cleanup = cleanup, .test = test_hugeshmctl, .needs_checkpoints = 1, - .request_hugepages = 128, + .hugepages = {128, TST_REQUEST}, };
testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c +1 -1
@@ -110,5 +110,5 @@ static struct tst_test test = { }, .setup = setup, .cleanup = cleanup, - .request_hugepages = 128, + .hugepages = {128, TST_REQUEST}, };
testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c +1 -1
@@ -134,5 +134,5 @@ static struct tst_test test = { .setup = setup, .cleanup = cleanup, .test_all = test_hugeshmctl, - .request_hugepages = 128, + .hugepages = {128, TST_REQUEST}, };
testcases/kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c +1 -1
@@ -152,5 +152,5 @@ static struct tst_test test = { .setup = setup, .cleanup = cleanup, .test_all = hugeshmdt_test, - .request_hugepages = 128, + .hugepages = {128, TST_REQUEST}, };
testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget01.c +1 -1
@@ -78,5 +78,5 @@ static struct tst_test test = { .setup = setup, .cleanup = cleanup, .test_all = test_hugeshmget, - .request_hugepages = 128, + .hugepages = {128, TST_REQUEST}, };
testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c +1 -1
@@ -98,5 +98,5 @@ static struct tst_test test = { .cleanup = cleanup, .test = test_hugeshmget, .tcnt = ARRAY_SIZE(tcases), - .request_hugepages = 128, + .hugepages = {128, TST_REQUEST}, };
testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c +1 -1
@@ -96,5 +96,5 @@ static struct tst_test test = { .setup = setup, .cleanup = cleanup, .test_all = test_hugeshmget, - .request_hugepages = 128, + .hugepages = {128, TST_REQUEST}, };
testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c +1 -1
@@ -92,5 +92,5 @@ static struct tst_test test = { .setup = setup, .cleanup = cleanup, .test_all = test_hugeshmget, - .request_hugepages = 128, + .hugepages = {128, TST_REQUEST}, };
testcases/kernel/syscalls/futex/futex_wake04.c +1 -4
@@ -48,9 +48,6 @@ static struct futex_test_variants variants[] = {static void setup (void ) { -if (tst_hugepages ==0 ) -tst_brk (TCONF ,"No enough hugepages for testing." ); -struct futex_test_variants *tv = &variants[tst_variant];tst_res (TINFO ,"Testing variant: %s" , tv->desc);
@@ -135,5 +132,5 @@ static struct tst_test test = { .needs_root = 1, .min_kver = "2.6.32", .needs_tmpdir = 1, - .request_hugepages = 1, + .hugepages = {1, TST_NEEDS}, };
testcases/kernel/syscalls/ipc/shmget/shmget02.c +1 -1
@@ -148,5 +148,5 @@ static struct tst_test test = { .cleanup = cleanup, .test = do_test, .tcnt = ARRAY_SIZE(tcases), - .request_hugepages = TST_NO_HUGEPAGES, + .hugepages = {TST_NO_HUGEPAGES, TST_REQUEST}, };
testcases/kernel/syscalls/pkeys/pkey01.c +2 -2
@@ -52,7 +52,7 @@ static void setup(void)check_pkey_support (); -if (tst_hugepages == test.request_hugepages) +if (tst_hugepages == test.hugepages.number) size =SAFE_READ_MEMINFO ("Hugepagesize:" ) *1024 ;else size =getpagesize ();
@@ -221,5 +221,5 @@ static struct tst_test test = { .forks_child = 1, .test = verify_pkey, .setup = setup, - .request_hugepages = 1, + .hugepages = {1, TST_REQUEST}, };
Signature · 5 lines
2.36.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 3/3] hugetlb: make use of new .hugepages
Hi!
This looks good, but should be part of the first patch so that we do not break compilation during a bisection.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp