Hugetlb:Migrating the libhugetlbfs tests
v6 cover Hugetlb:Migrating the libhugetlbfs tests
Hi,
Libhugetlbfs is not being maintained actively, and some distro is dropping support for it. There are some tests that are good for testing hugetlb functionality in kernel.
As per previous dicussion in RFC[1], Here, this patch series consists of hugetlb tests taken from libhugetlbfs modified to work in ltp environment.
Based on suggestion[2], I am reposting the patches again. Also, I added suggested changes at [3].
ref:
1:https://lore.kernel.org/all/[email protected]/ 2:https://lore.kernel.org/all/[email protected]/ 3:https://lore.kernel.org/all/[email protected]/
v1 -> v2
1. In (brk near huge) test [PATCH 1/3] removed unused library function test_addr_huge() and read_maps().
v2 -> v3
1. Added a new patch commit for two new flags "needs_hugetlbfs" & "needs_unlinked_hugetlb_file" in tst_test and modified tests to use these flags.
2. Added taint check in test [PATCH 1/3].
3. Removed redundant Hopt and nr_opt option.
4. Corrected pre-processor ARCH based conditional flags in test [PATCH 1/3]
v3 -> v4
1. Removed the needs_unlinked_hugetlb_file option in PATCH[1/4].
2. Removed the redundant saved_oc_hugepages checks in PATCH[3/4].
3. Updated the mntpoint checks in PATCH[1/4].
v4 -> v5
1. Removed the needs_hugetlbfs check from needs_tmpdir function, because mntpoint is now mandatory option with needs_hugetlbfs. (PATCH[1/4])
v5 -> v6
1. Edited the comment for needs_hugetlbfs PATCH[1/4].
2. Changed TCID to tid and removed __func__ from tst_brk PATCH[1/4].
3. Removed SAFE_UMOUNT in do_cleanup PATCH[1/4].
4. Added the ARCH definition in Makefile PATCH[2/4].
5. Removed ALIGN and use LTP_ALIGN PATCH[2/4].
Tarun Sahu (4):
Hugetlb: Add new tst_test options for hugeltb test support
Hugetlb: Migrating libhugetlbfs brk_near_huge
Hugetlb: Migrating libhugetlbfs chunk-overcommit
Hugetlb: Migrating libhugetlbfs corrupt-by-cow-opt
include/tst_test.h | 10 ++ lib/tst_test.c | 32 +++- runtest/hugetlb | 3 + testcases/kernel/mem/.gitignore | 3 + .../kernel/mem/hugetlb/hugemmap/Makefile | 6 + .../kernel/mem/hugetlb/hugemmap/hugemmap07.c | 138 ++++++++++++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap08.c | 148 ++++++++++++++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap09.c | 80 ++++++++++ testcases/kernel/mem/hugetlb/lib/hugetlb.h | 2 + 9 files changed, 419 insertions(+), 3 deletions(-) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v6 1/4 Hugetlb: Add new tst_test options for hugeltb test support
Most of libhugetlbfs test require mounted hugetlbfs.
Here, this patch adds a new field in tst_test struct(include/tst_test.h) which user can set if the test requires mounted hugetlbfs. Also, this patch added support to create the unlinked file in the provided dirpath.
--- include/tst_test.h | 10 ++++++++++ lib/tst_test.c | 32 +++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-)
include/tst_test.h +10 -0
@@ -176,6 +176,10 @@ struct tst_test { int all_filesystems:1; int skip_in_lockdown:1; int skip_in_compat:1; +/* +* If set, the hugetlbfs will be mounted at .mntpoint. +*/ + int needs_hugetlbfs:1;/* * The skip_filesystems is a NULL terminated list of filesystems the
@@ -357,6 +361,12 @@ unsigned int tst_remaining_runtime(void);*/ void tst_set_max_runtime (int max_runtime); +/* +* Create and open a random file inside the given dir path. +* It unlinks the file after opening and return file descriptor. +*/ +int tst_creat_unlinked (const char *path); +/* * Returns path to the test temporary directory in a newly allocated buffer. */
lib/tst_test.c +29 -3
@@ -1021,6 +1021,28 @@ static void prepare_and_mount_dev_fs(const char *mntpoint) } } +static void prepare_and_mount_hugetlb_fs (void ) +{ +SAFE_MOUNT ("none" , tst_test->mntpoint,"hugetlbfs" ,0 ,NULL ); + mntpoint_mounted =1 ; +} + +int tst_creat_unlinked (const char *path) +{ +char template[PATH_MAX ]; +int fd; + +snprintf (template,PATH_MAX ,"%s/ltp_%.3sXXXXXX" , + path, tid); + + fd =mkstemp (template); +if (fd <0 ) +tst_brk (TBROK |TERRNO ,"mkstemp(%s) failed" , template); + +SAFE_UNLINK (template); +return fd; +} +static const char *limit_tmpfs_mount_size (const char *mnt_data,char *buf,size_t buf_size,const char *fs_type) {
@@ -1191,15 +1213,16 @@ static void do_setup(int argc, char *argv[])SAFE_MKDIR (tst_test->mntpoint,0777 );if ((tst_test->needs_devfs || tst_test->needs_rofs || - tst_test->mount_device || tst_test->all_filesystems) && + tst_test->mount_device || tst_test->all_filesystems || + tst_test->needs_hugetlbfs) && !tst_test->mntpoint) {tst_brk (TBROK ,"tst_test->mntpoint must be set!" ); }if (!!tst_test->needs_rofs + !!tst_test->needs_devfs + - !!tst_test->needs_device >1 ) { + !!tst_test->needs_device + !!tst_test->needs_hugetlbfs >1 ) {tst_brk (TBROK , -"Two or more of needs_{rofs, devfs, device} are set" ); +"Two or more of needs_{rofs, devfs, device, hugetlbfs} are set" ); }if (tst_test->needs_devfs)
@@ -1217,6 +1240,9 @@ static void do_setup(int argc, char *argv[]) } } +if (tst_test->needs_hugetlbfs) +prepare_and_mount_hugetlb_fs (); +if (tst_test->needs_device && !mntpoint_mounted) { tdev.dev =tst_acquire_device_ (NULL , tst_test->dev_min_size);
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v6 1/4] Hugetlb: Add new tst_test options for hugeltb test support
Tarun Sahu <[email protected]> wrote:
Most of libhugetlbfs test require mounted hugetlbfs.
Quoted 7 lines
Here, this patch adds a new field in
tst_teststruct(include/tst_test.h)which user can set if the test requires mounted hugetlbfs. Also, this patch added support to create the unlinked file in the provided dirpath.Signed-off-by Tarun Sahu <[email protected]>
Thanks for the patiently iteration. This looks pretty good.
Signature · 2 lines
Regards, Li Wang
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v6 1/4] Hugetlb: Add new tst_test options for hugeltb test support
Hello,
Thanks for reviewing.
I am thinking of adding following lines in "lib/hugetlb.h"
#define HUGEPAGE_TOTAL "HugePages_Total:"
#define HUGEPAGE_FREE "HugePages_Total:"
#define HUGEPAGE_RSVD "HugePages_Total:"
#define HUGEPAGE_Surp "HugePages_Total:"
There are all test that uses, TOTAL, MANY that uses FREE, few RSVD, SURP. If we change it now, we can update this series now and, proceed further for series of next tests.
What do you think?
Quoted 23 lines · Li Wang
Tarun Sahu <[email protected]> wrote:
Most of libhugetlbfs test require mounted hugetlbfs.
Quoted 7 lines
Here, this patch adds a new field in
tst_teststruct(include/tst_test.h)which user can set if the test requires mounted hugetlbfs. Also, this patch added support to create the unlinked file in the provided dirpath.Signed-off-by Tarun Sahu <[email protected]>Thanks for the patiently iteration. This looks pretty good.
Reviewed-by Li Wang <[email protected]>Signature · 6 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v6 1/4] Hugetlb: Add new tst_test options for hugeltb test support
Quoted 10 lines · Tarun Sahu
Hello,
Thanks for reviewing.I am thinking of adding following lines in "
lib/hugetlb.h"#define
HUGEPAGE_TOTAL"HugePages_Total:"
#defineHUGEPAGE_FREE"HugePages_Total:"
#defineHUGEPAGE_RSVD"HugePages_Total:"
#defineHUGEPAGE_Surp"HugePages_Total:"
Quoted 6 lines
There are all test that uses, TOTAL, MANY that uses FREE, few RSVD, SURP. If we change it now, we can update this series now and, proceed further for series of next tests.
What do you think?
I guess put in the top header file "inlucde/tst_hugepage.h" should be better,
it provides more scope(for the whole LTP) of use.
I ever thought to combine this hugetlb/lib there, especially for new cases, it would be easier to maintain only one library for hugetlb. (and also adding more definitions. e.g. "/proc/sys/vm/nr_overcommit_hugepages")
Signature · 2 lines
Regards, Li Wang
Signature · 2 lines
-- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v6 1/4] Hugetlb: Add new tst_test options for hugeltb test support
In reply to Tarun SahuHi!
Looks good now.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v6 2/4 Hugetlb: Migrating libhugetlbfs brk_near_huge
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/brk_near_huge.c test
Test Description:
Certain kernels have a bug where brk() does not perform the same checks that a MAP_FIXED mmap() will, allowing brk() to create a normal page VMA in a hugepage only address region. This can lead to oopses or other badness.
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/Makefile | 6 + .../kernel/mem/hugetlb/hugemmap/hugemmap07.c | 138 ++++++++++++++++++ testcases/kernel/mem/hugetlb/lib/hugetlb.h | 2 + 5 files changed, 148 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c
runtest/hugetlb +1 -0
@@ -3,6 +3,7 @@ hugemmap02 hugemmap02 hugemmap04 hugemmap04 hugemmap05 hugemmap05 hugemmap06 hugemmap06 +hugemmap07 hugemmap07 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -4,6 +4,7 @@ /hugetlb/hugemmap/hugemmap04 /hugetlb/hugemmap/hugemmap05 /hugetlb/hugemmap/hugemmap06 +/hugetlb/hugemmap/hugemmap07 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/Makefile +6 -0
@@ -9,3 +9,9 @@ include $(abs_srcdir)/../Makefile.inc include $(top_srcdir)/include/mk/generic_leaf_target.mk hugemmap06: CFLAGS+=-pthread + +ARCH ?= $(shell uname -m | sed -e s/i.86/i386/) +hugemmap07: +ifeq ($(ARCH),ppc) + CPPFLAGS += -DPPC_NO_SEGMENTS +endif
testcases/kernel/mem/hugetlb/hugemmap/hugemmap07.c new file +138 -0
138 lines not on this page · raw message
testcases/kernel/mem/hugetlb/lib/hugetlb.h +2 -0
@@ -20,6 +20,8 @@#include "old_tmpdir.h" #include "mem.h" +#define PALIGN (p, a) ((void *)LTP_ALIGN((unsigned long)(p), (a))) +#define SHM_RD 0400#define SHM_WR 0200#define SHM_RW (SHM_RD|SHM_WR)
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v6 2/4] Hugetlb: Migrating libhugetlbfs brk_near_huge
Hi!
testcases/kernel/mem/hugetlb/hugemmap/Makefile include $(abs_srcdir)/../Makefile.inc · line 13
Quoted 10 lines
testcases/kernel/mem/hugetlb/hugemmap/Makefile +2
-0@@ -9,3 +9,9 @@ include $(abs_srcdir)/../Makefile.inc include $(top_srcdir)/include/mk/generic_leaf_target.mk hugemmap06: CFLAGS+=-pthread + +ARCH ?= $(shell uname -m | sed -e s/i.86/i386/)
This will break cross-compilation. We cannot assume anything during compilation based on the system we compile LTP on.
What are we trying to detect here?
Looking at:
https://github.com/libhugetlbfs/libhugetlbfs/commit/cc0717ca0deee9dc0bb84acc8c80fd468b180f6f
it seems that we are looking for native 32bit PPC, that means that we have to check on runtime, because we don't know if we are going to run in 32bit compat mode or on native 32bit machine when we are compiling.
We do have tst_kernel_bits() function exactly for this purpose.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v6 2/4] Hugetlb: Migrating libhugetlbfs brk_near_huge
In reply to Tarun SahuHi!
Quoted 5 lines
+/*\
+ *
+ * [Description]
+ *
+ * brk near hugepage:
^
and this bit is still here
If you have asciidoc installed you can run make in the top level LTP directory which will generate docparse/metadata.html where you can check how the documentation is rendered.
Quoted 5 lines
+ * Certain kernels have a bug where
brk()does not perform the same
+ * checks that aMAP_FIXEDmmap()will, allowingbrk()to create a
+ * normal page VMA in a hugepage only address region. This can lead
+ * to oopses or other badness.
+ */
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v6 3/4 Hugetlb: Migrating libhugetlbfs chunk-overcommit
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/chunk-overcommit.c test
Test Description: Some kernel versions after hugepage demand allocation was added used a dubious heuristic to check if there was enough hugepage space available for a given mapping. The number of not-already-instantiated pages in the mapping was compared against the total hugepage free pool. It was very easy to confuse this heuristic into overcommitting by allocating hugepage memory in chunks, each less than the total available pool size but together more than available. This would generally lead to OOM SIGKILLs of one process or another when it tried to instantiate pages beyond the available pool.
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap08.c | 148 ++++++++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c
runtest/hugetlb +1 -0
@@ -4,6 +4,7 @@ hugemmap04 hugemmap04 hugemmap05 hugemmap05 hugemmap06 hugemmap06 hugemmap07 hugemmap07 +hugemmap08 hugemmap08 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -5,6 +5,7 @@ /hugetlb/hugemmap/hugemmap05 /hugetlb/hugemmap/hugemmap06 /hugetlb/hugemmap/hugemmap07 +/hugetlb/hugemmap/hugemmap08 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap08.c new file +148 -0
148 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v6 4/4 Hugetlb: Migrating libhugetlbfs corrupt-by-cow-opt
In reply to Tarun SahuMigrating the libhugetlbfs/testcases/corrupt-by-cow-opt.c test
Test Description: Test sanity of cow optimization on page cache. If a page in page cache has only 1 ref count, it is mapped for a private mapping directly and is overwritten freely, so next time we access the page, we can see corrupt data.
--- runtest/hugetlb | 1 + testcases/kernel/mem/.gitignore | 1 + .../kernel/mem/hugetlb/hugemmap/hugemmap09.c | 80 +++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c
runtest/hugetlb +1 -0
@@ -5,6 +5,7 @@ hugemmap05 hugemmap05 hugemmap06 hugemmap06 hugemmap07 hugemmap07 hugemmap08 hugemmap08 +hugemmap09 hugemmap09 hugemmap05_1 hugemmap05 -m hugemmap05_2 hugemmap05 -s hugemmap05_3 hugemmap05 -s -m
testcases/kernel/mem/.gitignore +1 -0
@@ -6,6 +6,7 @@ /hugetlb/hugemmap/hugemmap06 /hugetlb/hugemmap/hugemmap07 /hugetlb/hugemmap/hugemmap08 +/hugetlb/hugemmap/hugemmap09 /hugetlb/hugeshmat/hugeshmat01 /hugetlb/hugeshmat/hugeshmat02 /hugetlb/hugeshmat/hugeshmat03
testcases/kernel/mem/hugetlb/hugemmap/hugemmap09.c new file +80 -0
80 lines not on this page · raw message
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp