lib/tst_hugepage: Fix .request_hugepages = 0 bug
PATCH 1/2 lib/tst_hugepage: Fix .request_hugepages = 0 bug
Since ltp library doesn't call tst_request_hugepages when using zero value, we don't set this value successfully.
Fix this by introducing TST_NO_HUGEPAGES flag. If you want to keep zero hugepage for some ENOMEM case(like shmget02), please use this flag instead of using 0 directly.
--- doc/c-test-api.txt | 3 ++- include/tst_test.h | 5 +++- lib/newlib_tests/.gitignore | 1 + lib/newlib_tests/test_zero_hugepage.c | 35 ++++++++++++++++++++++++++ lib/newlib_tests/test_zero_hugepage.sh | 13 ++++++++++ lib/tst_hugepage.c | 6 +++++ 6 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 lib/newlib_tests/test_zero_hugepage.c create mode 100755 lib/newlib_tests/test_zero_hugepage.sh
doc/c-test-api.txt +2 -1
@@ -1908,7 +1908,8 @@ 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. +'tst_hugepages' will be set to 0. If need zero hugepage on supported hugetlb +system, please use '.request_hugepages = TST_NO_HUGEPAGES'. Also, we do cleanup and restore work for the hpages resetting automatically.
include/tst_test.h +4 -1
@@ -125,6 +125,8 @@ struct tst_tag {extern unsigned int tst_variant; +#define TST_NO_HUGEPAGES ((unsigned long)-1) +struct tst_test {/* number of tests available in test() function */ unsigned int tcnt;
@@ -175,7 +177,8 @@ struct tst_test {* 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. +* 'tst_hugepages' will be set to 0. If need zero hugepage on supported hugetlb +* system, please use '.request_hugepages = TST_NO_HUGEPAGES'. * * Also, we do cleanup and restore work for the hpages resetting automatically. */
lib/newlib_tests/.gitignore +1 -0
@@ -44,3 +44,4 @@ test_macros04 tst_fuzzy_sync01 tst_fuzzy_sync02 tst_fuzzy_sync03 +test_zero_hugepage
lib/newlib_tests/test_zero_hugepage.c new file +35 -0
@@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2021 Yang Xu <[email protected]> +*/ + +/* +* Tests .request_hugepages = TST_NO_HUGEPAGES +*/ + +#include "tst_test.h" +#include "tst_hugepage.h" +#include "tst_sys_conf.h" + +static void do_test (void ) +{ +unsigned long val, hpages; + +SAFE_FILE_SCANF (PATH_NR_HPAGES ,"%lu" , &val); +if (val !=0 ) +tst_brk (TBROK ,"nr_hugepages = %lu, but expect 0" , val); +else +tst_res (TPASS ,"test .request_hugepages = TST_NO_HUGEPAGES" ); + + 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" ); +} + +static struct tst_test test = { + .test_all = do_test, + .request_hugepages =TST_NO_HUGEPAGES , +};
lib/newlib_tests/test_zero_hugepage.sh new file +13 -0
@@ -0,0 +1,13 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2021 Yang Xu <[email protected]> + +echo "Testing .request_hugepages = TST_NO_HUGEPAGES" + +orig_value=`cat /proc/sys/vm/nr_hugepages` + +echo "128" > /proc/sys/vm/nr_hugepages + +./test_zero_hugepage + +echo $orig_value > /proc/sys/vm/nr_hugepages
lib/tst_hugepage.c +6 -0
@@ -34,6 +34,11 @@ unsigned long tst_request_hugepages(unsigned long hpages)else tst_hugepages = hpages; +if (hpages ==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:" );
@@ -47,6 +52,7 @@ unsigned long tst_request_hugepages(unsigned long hpages) goto out; } +set_hugepages:tst_sys_conf_save ("?/proc/sys/vm/nr_hugepages" );SAFE_FILE_PRINTF (PATH_NR_HPAGES ,"%lu" , tst_hugepages);SAFE_FILE_SCANF (PATH_NR_HPAGES ,"%lu" , &val);
Signature · 1 line
2.23.0
PATCH 2/2 syscalls/shmget02: Use TST_NO_HUGEPAGES instead of 0
--- testcases/kernel/syscalls/ipc/shmget/shmget02.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/syscalls/ipc/shmget/shmget02.c +1 -1
@@ -110,5 +110,5 @@ static struct tst_test test = { .cleanup = cleanup, .test = do_test, .tcnt = ARRAY_SIZE(tcases), - .request_hugepages = 0, + .request_hugepages = TST_NO_HUGEPAGES, };
Signature · 1 line
2.23.0
PATCH 2/2 syscalls/shmget02: Use TST_NO_HUGEPAGES instead of 0
PATCH 1/2 lib/tst_hugepage: Fix .request_hugepages = 0 bug
In reply to Yang XuHi!
Quoted 1 line
+'tst_hugepages' will be set to 0. If need zero hugepage on supported hugetlb
^ If the hugepage size needs to be set to 0 on ...
Quoted 18 lines
doc/c-test-api.txt +1
-0+system, please use '.request_hugepages = TST_NO_HUGEPAGES'. Also, we do cleanup and restore work for the hpages resetting automatically.include/tst_test.h +2
-0@@ -125,6 +125,8 @@ struct tst_tag {extern unsigned int tst_variant; +#define TST_NO_HUGEPAGES ((unsigned long)-1) +struct tst_test {/* number of tests available in test() function */ unsigned int tcnt;
include/tst_test.h struct tst_test { · line 181
Quoted 6 lines
include/tst_test.h +2
-1@@ -175,7 +177,8 @@ struct tst_test {* 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. +* 'tst_hugepages' will be set to 0. If need zero hugepage on supported hugetlb +* system, please use '.request_hugepages = TST_NO_HUGEPAGES'.
Here as well.
Other than that it looks good.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/2 lib/tst_hugepage: Fix .request_hugepages = 0 bug
Hi Cyril
Quoted 6 lines
Hi!
Quoted 1 line
+'tst_hugepages' will be set to 0. If need zero hugepage on supported hugetlb
^ If the hugepage size needs to be set to 0 on ...Quoted 1 line
+system, please use '.request_hugepages =
TST_NO_HUGEPAGES'.
I use number instead of size and then push this patchset. Thanks for your review.
Best Regards
Yang Xu
Quoted 29 lines
Quoted 17 lines
Also, we do cleanup and restore work for the hpages resetting automatically.
include/tst_test.h +2
-0@@ -125,6 +125,8 @@ struct tst_tag {extern unsigned int tst_variant; +#define TST_NO_HUGEPAGES ((unsigned long)-1) +struct tst_test {/* number of tests available in test() function */ unsigned int tcnt;include/tst_test.h struct tst_test { · line 181
Quoted 6 lines
include/tst_test.h +2
-1@@ -175,7 +177,8 @@ struct tst_test {* 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. +* 'tst_hugepages' will be set to 0. If need zero hugepage on supported hugetlb +* system, please use '.request_hugepages = TST_NO_HUGEPAGES'. Here as well.
Other than that it looks good.
PATCH 1/2 lib/tst_hugepage: Fix .request_hugepages = 0 bug
In reply to Cyril HrubisHi Xu,
thanks for fixing it! I updated also wiki (ltp.wiki.git repository).
Kind regards,
Petr
PATCH 1/2 lib/tst_hugepage: Fix .request_hugepages = 0 bug
Hi Petr
Quoted 3 lines
Hi Xu,
thanks for fixing it! I updated also wiki (ltp.wiki.git repository).
Thanks. Sorry, I forgot this.
Best Regards
Yang Xu
Quoted 3 lines
Kind regards,
Petr