Get rid of testcases/kernel/mem/lib library
cover Get rid of testcases/kernel/mem/lib library
This patchset slowly untangles the mess called kernel/mem/lib/ library.
The library is split into several places, functions that are used by more than one group of tests are either reimplemented in the top level library or in the case of numa moved into numa_helper library in testcases/kerne/include/ and testcases/kernel/lib/.
The rest of the code is either moved into respective test directories or in the case of unused code removed.
This is not a coplete cleanup of the mem/ testcases as it mostly just moves code, but it's a nice first step that removes most of the unneeded dependencies and prepares for a possible refactoring later on.
The CI run:
https://github.com/metan-ucw/ltp
Cyril Hrubis (13):
lib: tst_sys_conf: Add two functions
lib: Replace path_exist() with tst_path_exists()
lib: Add tst_mapping_in_range() testcases/kernel/mem: Move get_a_numa_node() testcases/kernel/mem: Move update_shm_size() testcases/kernel/mem: Move check_hugepage() + PATH_THP testcases/kernel/mem: Move NUMA bits to numa_helper.h testcases/kernel/mem: Move oom() fucntions to oom tests testcases/kernel/mem: Move KSM bits to ksm tests mem/swapping: Remove mem/lib refrence
mem/vma: Remove mem/lib dependency mem/hugetlb: Remove mem/lib depenency testcases/kernel/mem: Remove library
include/tst_fs.h | 10 + include/tst_memutils.h | 11 + include/tst_sys_conf.h | 31 + lib/tst_memutils.c | 31 + lib/tst_path_exists.c | 23 + lib/tst_sys_conf.c | 29 + testcases/kernel/include/numa_helper.h | 21 + testcases/kernel/lib/numa_cpuset.c | 64 ++ testcases/kernel/mem/cpuset/Makefile | 2 +- testcases/kernel/mem/cpuset/cpuset01.c | 4 +- testcases/kernel/mem/hugetlb/Makefile.inc | 3 - .../kernel/mem/hugetlb/hugemmap/hugemmap02.c | 4 +- .../kernel/mem/hugetlb/hugemmap/hugemmap05.c | 1 - .../kernel/mem/hugetlb/hugemmap/hugemmap13.c | 4 +- .../kernel/mem/hugetlb/hugemmap/hugemmap14.c | 6 +- .../mem/hugetlb/hugeshmat/hugeshmat04.c | 4 +- testcases/kernel/mem/hugetlb/lib/Makefile | 1 - testcases/kernel/mem/hugetlb/lib/hugetlb.c | 11 + testcases/kernel/mem/hugetlb/lib/hugetlb.h | 6 +- testcases/kernel/mem/include/libmem.mk | 43 -- testcases/kernel/mem/include/mem.h | 81 -- testcases/kernel/mem/ksm/Makefile | 2 +- testcases/kernel/mem/ksm/ksm01.c | 2 +- testcases/kernel/mem/ksm/ksm02.c | 4 +- testcases/kernel/mem/ksm/ksm03.c | 2 +- testcases/kernel/mem/ksm/ksm04.c | 4 +- testcases/kernel/mem/ksm/ksm05.c | 2 +- testcases/kernel/mem/ksm/ksm06.c | 4 +- testcases/kernel/mem/ksm/ksm07.c | 3 +- testcases/kernel/mem/ksm/ksm_common.h | 36 + testcases/kernel/mem/ksm/ksm_test.h | 299 ++++++++ testcases/kernel/mem/lib/Makefile | 27 - testcases/kernel/mem/lib/mem.c | 711 ------------------ testcases/kernel/mem/oom/Makefile | 7 +- testcases/kernel/mem/oom/oom.h | 231 ++++++ testcases/kernel/mem/oom/oom01.c | 13 +- testcases/kernel/mem/oom/oom02.c | 5 +- testcases/kernel/mem/oom/oom03.c | 11 +- testcases/kernel/mem/oom/oom04.c | 7 +- testcases/kernel/mem/oom/oom05.c | 11 +- testcases/kernel/mem/swapping/Makefile | 1 - testcases/kernel/mem/swapping/swapping01.c | 2 +- testcases/kernel/mem/thp/Makefile | 2 +- testcases/kernel/mem/thp/thp.h | 17 + testcases/kernel/mem/thp/thp01.c | 1 - testcases/kernel/mem/thp/thp02.c | 3 +- testcases/kernel/mem/thp/thp03.c | 5 +- testcases/kernel/mem/tunable/Makefile | 1 - testcases/kernel/mem/tunable/max_map_count.c | 17 +- .../kernel/mem/tunable/min_free_kbytes.c | 27 +- .../kernel/mem/tunable/overcommit_memory.c | 23 +- testcases/kernel/mem/vma/Makefile | 2 +- 52 files changed, 922 insertions(+), 950 deletions(-) create mode 100644 lib/tst_path_exists.c create mode 100644 testcases/kernel/lib/numa_cpuset.c delete mode 100644 testcases/kernel/mem/include/libmem.mk delete mode 100644 testcases/kernel/mem/include/mem.h create mode 100644 testcases/kernel/mem/ksm/ksm_test.h delete mode 100644 testcases/kernel/mem/lib/Makefile delete mode 100644 testcases/kernel/mem/lib/mem.c create mode 100644 testcases/kernel/mem/oom/oom.h create mode 100644 testcases/kernel/mem/thp/thp.h
Signature · 5 lines
2.45.2 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 1/13 lib: tst_sys_conf: Add two functions
Add two functions to read/write integer values from/to sysfs or procfs files.
With that we replace the get_sys_tune() and set_sys_tune() from testcases/kernel/mem/lib/mem.c with a better implementation.
We also remove the inclusion of the mem library from tunables, since it's no longer needed there.
--- include/tst_sys_conf.h | 31 +++++++++++++++++++ lib/tst_sys_conf.c | 29 +++++++++++++++++ .../mem/hugetlb/hugeshmat/hugeshmat04.c | 2 +- testcases/kernel/mem/include/mem.h | 2 -- testcases/kernel/mem/lib/mem.c | 29 ----------------- testcases/kernel/mem/oom/oom01.c | 10 +++--- testcases/kernel/mem/tunable/Makefile | 1 - testcases/kernel/mem/tunable/max_map_count.c | 17 +++++----- .../kernel/mem/tunable/min_free_kbytes.c | 27 ++++++++-------- .../kernel/mem/tunable/overcommit_memory.c | 23 ++++++++------ 10 files changed, 104 insertions(+), 67 deletions(-)
include/tst_sys_conf.h +31 -0
@@ -28,4 +28,35 @@ int tst_sys_conf_save(const struct tst_path_val *conf);void tst_sys_conf_restore (int verbose);void tst_sys_conf_dump (void ); +/** +* TST_SYS_CONF_LONG_SET() +* +* Sets a sysfs or procfs file and optionally checks that it was set correctly. +* +* @param path A path to a sysfs or a procfs file. +* @param val A long int value to be written to the file. +* @param check If non-zero the library reads the file back and checks that the +* value is the one we have written there. If not the library calls +* tst_brk(TBROK, ...). +*/ +#define TST_SYS_CONF_LONG_SET (path, val, check) \ + tst_sys_conf_long_set_(__FILE__, __LINE__, path, val, check) + +void tst_sys_conf_long_set_ (const char *file,const int lineno, +const char *path,long val,int check); + + +/** +* TST_SYS_CONF_LONG_GET() +* +* Gets a sysfs or procfs file value and converts it to long. +* +* @param path A path to a sysfs or a procfs file. +*/ +#define TST_SYS_CONF_LONG_GET (path) \ + tst_sys_conf_long_get_(__FILE__, __LINE__, path) + +long tst_sys_conf_long_get_ (const char *file,const int lineno, +const char *path); +#endif
lib/tst_sys_conf.c +29 -0
@@ -145,3 +145,32 @@ void tst_sys_conf_restore(int verbose) } } +long tst_sys_conf_long_get_ (const char *file,const int lineno, +const char *path) +{ +long ret; + +safe_file_scanf (file, lineno,NULL , path,"%ld" , &ret); + +return ret; +} + +void tst_sys_conf_long_set_ (const char *file,const int lineno, +const char *path,long val,int check) +{ +tst_res_ (file, lineno,TINFO ,"Setting %s to %ld" , path, val); + +safe_file_printf (file, lineno,NULL , path,"%ld" , val); + +if (check) { +long read_val; + +safe_file_scanf (file, lineno,NULL , path,"%ld" , &read_val); + +if (val != read_val) +tst_brk_ (file, lineno,TBROK , +"Wrote %ld to %s but read back %ld" , + val, path, read_val); + } + +}
testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c +1 -1
@@ -82,7 +82,7 @@ static void setup(void)long hpage_size, orig_hugepages;unsigned long new_shmmax; - orig_hugepages =get_sys_tune ("nr_hugepages" ); + orig_hugepages =TST_SYS_CONF_LONG_GET ("/proc/sys/vm/nr_hugepages" );SAFE_FILE_SCANF (PATH_SHMMAX ,"%lu" , &new_shmmax);if (new_shmmax <SIZE )
testcases/kernel/mem/include/mem.h +0 -2
@@ -71,8 +71,6 @@ void write_cpusets(const struct tst_cg_group *cg, long nd);/* shared */ unsigned int get_a_numa_node (void );int path_exist (const char *path, ...); -void set_sys_tune (char *sys_file,long tune,int check); -long get_sys_tune (char *sys_file);void update_shm_size (size_t *shm_size);
testcases/kernel/mem/lib/mem.c +0 -29
@@ -638,35 +638,6 @@ int path_exist(const char *path, ...)return access (pathbuf,F_OK ) ==0 ; } -void set_sys_tune (char *sys_file,long tune,int check) -{ -long val; -char path[BUFSIZ ]; - -tst_res (TINFO ,"set %s to %ld" , sys_file, tune); - -snprintf (path,BUFSIZ ,PATH_SYSVM "%s" , sys_file); -SAFE_FILE_PRINTF (path,"%ld" , tune); - -if (check) { - val =get_sys_tune (sys_file); -if (val != tune) -tst_brk (TBROK ,"%s = %ld, but expect %ld" , - sys_file, val, tune); - } -} - -long get_sys_tune (char *sys_file) -{ -char path[BUFSIZ ]; -long tune; - -snprintf (path,BUFSIZ ,PATH_SYSVM "%s" , sys_file); -SAFE_FILE_SCANF (path,"%ld" , &tune); - -return tune; -} -void update_shm_size (size_t * shm_size) {size_t shmmax;
testcases/kernel/mem/oom/oom01.c +6 -4
@@ -18,18 +18,20 @@#include <unistd.h> #include "mem.h" +#define OVERCOMMIT_MEMORY "/proc/sys/vm/overcommit_memory" +static void verify_oom (void ) {/* we expect mmap to fail before OOM is hit */ -set_sys_tune ("overcommit_memory" ,2 ,1 ); +TST_SYS_CONF_LONG_SET (OVERCOMMIT_MEMORY ,2 ,1 );oom (NORMAL ,0 ,ENOMEM ,0 );/* with overcommit_memory set to 0 or 1 there's no * guarantee that mmap fails before OOM */ -set_sys_tune ("overcommit_memory" ,0 ,1 ); +TST_SYS_CONF_LONG_SET (OVERCOMMIT_MEMORY ,0 ,1 );oom (NORMAL ,0 ,ENOMEM ,1 ); -set_sys_tune ("overcommit_memory" ,1 ,1 ); +TST_SYS_CONF_LONG_SET (OVERCOMMIT_MEMORY ,1 ,1 );testoom (0 ,0 ,ENOMEM ,1 ); }
@@ -40,7 +42,7 @@ static struct tst_test test = { .test_all = verify_oom, .skip_in_compat = 1, .save_restore = (const struct tst_path_val []) { - {"/proc/sys/vm/overcommit_memory" ,NULL ,TST_SR_TBROK }, + {OVERCOMMIT_MEMORY ,NULL ,TST_SR_TBROK }, {} }, };
testcases/kernel/mem/tunable/Makefile +0 -1
@@ -4,5 +4,4 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk -include $(top_srcdir)/testcases/kernel/mem/include/libmem.mk include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/mem/tunable/max_map_count.c +10 -7
@@ -48,10 +48,13 @@#include <stdio.h> #include <stdlib.h> #include <sys/utsname.h> -#include "mem.h" +#include "tst_test.h" #define MAP_COUNT_DEFAULT 1024 -#define MAX_MAP_COUNT 65536L +#define MAX_MAP_COUNT_MAX 65536L + +#define OVERCOMMIT_MEMORY "/proc/sys/vm/overcommit_memory" +#define MAX_MAP_COUNT "/proc/sys/vm/max_map_count"/* This is a filter to exclude map entries which aren't accounted * for in the vm_area_struct's map_count.
@@ -140,15 +143,15 @@ static void max_map_count_test(void) memfree =SAFE_READ_MEMINFO ("CommitLimit:" ) -SAFE_READ_MEMINFO ("Committed_AS:" );/* 64 used as a bias to make sure no overflow happen */ max_iters = memfree /sysconf (_SC_PAGESIZE) *1024 -64 ; -if (max_iters >MAX_MAP_COUNT ) - max_iters =MAX_MAP_COUNT ; +if (max_iters >MAX_MAP_COUNT_MAX ) + max_iters =MAX_MAP_COUNT_MAX ; max_maps =MAP_COUNT_DEFAULT ;if (max_iters < max_maps)tst_brk (TCONF ,"test requires more free memory" );while (max_maps <= max_iters) { -set_sys_tune ("max_map_count" , max_maps,1 ); +TST_SYS_CONF_LONG_SET (MAX_MAP_COUNT , max_maps,1 );switch (pid =SAFE_FORK ()) {case 0 :
@@ -192,8 +195,8 @@ static struct tst_test test = { .forks_child = 1, .test_all = max_map_count_test, .save_restore = (const struct tst_path_val []) { - {"/proc/sys/vm/overcommit_memory" ,"0" ,TST_SR_TBROK }, - {"/proc/sys/vm/max_map_count" ,NULL ,TST_SR_TBROK }, + {OVERCOMMIT_MEMORY ,"0" ,TST_SR_TBROK }, + {MAX_MAP_COUNT ,NULL ,TST_SR_TBROK }, {} }, };
testcases/kernel/mem/tunable/min_free_kbytes.c +14 -13
@@ -35,10 +35,14 @@#include <stdio.h> #include <stdlib.h> #include "lapi/abisize.h" -#include "mem.h" +#include "tst_test.h" #define MAP_SIZE (1UL<<20) +#define OVERCOMMIT_MEMORY "/proc/sys/vm/overcommit_memory" +#define MIN_FREE_KBYTES "/proc/sys/vm/min_free_kbytes" +#define PANIC_ON_OOM "/proc/sys/vm/panic_on_oom" +volatile int end;static long default_tune =-1 ;static unsigned long total_mem;
@@ -88,16 +92,13 @@ static void test_tune(unsigned long overcommit_policy)int ret, i;unsigned long tune, memfree, memtotal; -set_sys_tune ("overcommit_memory" , overcommit_policy,1 ); +TST_SYS_CONF_LONG_SET (OVERCOMMIT_MEMORY , overcommit_policy,1 );for (i =0 ; i <3 ; i++) { -/* case1 */ if (i ==0 ) -set_sys_tune ("min_free_kbytes" , default_tune,1 ); -/* case2 */ +TST_SYS_CONF_LONG_SET (MIN_FREE_KBYTES , default_tune,1 );else if (i ==1 ) { -set_sys_tune ("min_free_kbytes" ,2 * default_tune,1 ); -/* case3 */ +TST_SYS_CONF_LONG_SET (MIN_FREE_KBYTES ,2 * default_tune,1 ); }else { memfree =SAFE_READ_MEMINFO ("MemFree:" ); memtotal =SAFE_READ_MEMINFO ("MemTotal:" );
@@ -105,7 +106,7 @@ static void test_tune(unsigned long overcommit_policy)if (tune > (memtotal /50 )) tune = memtotal /50 ; -set_sys_tune ("min_free_kbytes" , tune,1 ); +TST_SYS_CONF_LONG_SET (MIN_FREE_KBYTES , tune,1 ); }fflush (stdout);
@@ -189,7 +190,7 @@ static void check_monitor(void)while (end) { memfree =SAFE_READ_MEMINFO ("MemFree:" ); - tune =get_sys_tune ("min_free_kbytes" ); + tune =TST_SYS_CONF_LONG_GET (MIN_FREE_KBYTES );if (memfree < tune) { tst_res(TINFO, "MemFree is %lu kB, "
@@ -208,14 +209,14 @@ static void sighandler(int signo LTP_ATTRIBUTE_UNUSED)static void setup (void ) { -if (get_sys_tune ("panic_on_oom" )) { +if (TST_SYS_CONF_LONG_GET (PANIC_ON_OOM )) {tst_brk (TCONF ,"panic_on_oom is set, disable it to run these testcases" ); } total_mem =SAFE_READ_MEMINFO ("MemTotal:" ) +SAFE_READ_MEMINFO ("SwapTotal:" ); - default_tune =get_sys_tune ("min_free_kbytes" ); + default_tune =TST_SYS_CONF_LONG_GET (MIN_FREE_KBYTES ); }static struct tst_test test = {
@@ -225,8 +226,8 @@ static struct tst_test test = { .setup = setup, .test_all = min_free_kbytes_test, .save_restore = (const struct tst_path_val []) { - {"/proc/sys/vm/overcommit_memory" ,NULL ,TST_SR_TBROK }, - {"/proc/sys/vm/min_free_kbytes" ,NULL ,TST_SR_TBROK }, + {OVERCOMMIT_MEMORY ,NULL ,TST_SR_TBROK }, + {MIN_FREE_KBYTES ,NULL ,TST_SR_TBROK }, {} }, };
testcases/kernel/mem/tunable/overcommit_memory.c +13 -10
@@ -62,12 +62,15 @@#include <stdio.h> #include <stdlib.h> #include <limits.h> -#include "mem.h" +#include "tst_test.h" #define DEFAULT_OVER_RATIO 50L#define EXPECT_PASS 0#define EXPECT_FAIL 1 +#define OVERCOMMIT_MEMORY "/proc/sys/vm/overcommit_memory" +#define OVERCOMMIT_RATIO "/proc/sys/vm/overcommit_ratio" +static char *R_opt;static long old_overcommit_ratio =-1 ;static long overcommit_ratio;
@@ -93,7 +96,7 @@ static void setup(void)else overcommit_ratio =DEFAULT_OVER_RATIO ; - old_overcommit_ratio =get_sys_tune ("overcommit_ratio" ); + old_overcommit_ratio =TST_SYS_CONF_LONG_GET (OVERCOMMIT_RATIO ); mem_total =SAFE_READ_MEMINFO ("MemTotal:" );tst_res (TINFO ,"MemTotal is %ld kB" , mem_total);
@@ -115,7 +118,7 @@ static void setup(void)SAFE_SETRLIMIT (RLIMIT_AS , &lim); } -set_sys_tune ("overcommit_ratio" , overcommit_ratio,1 ); +TST_SYS_CONF_LONG_SET (OVERCOMMIT_RATIO , overcommit_ratio,1 );calculate_total_batch_size ();tst_res (TINFO ,"TotalBatchSize is %ld kB" , total_batch_size);
@@ -124,7 +127,7 @@ static void setup(void)static void overcommit_memory_test (void ) {/* start to test overcommit_memory=2 */ -set_sys_tune ("overcommit_memory" ,2 ,1 ); +TST_SYS_CONF_LONG_SET (OVERCOMMIT_MEMORY ,2 ,1 );update_mem_commit ();alloc_and_check (commit_left *2 ,EXPECT_FAIL );
@@ -133,14 +136,14 @@ static void overcommit_memory_test(void)alloc_and_check (commit_left /2 ,EXPECT_PASS );/* start to test overcommit_memory=0 */ -set_sys_tune ("overcommit_memory" ,0 ,1 ); +TST_SYS_CONF_LONG_SET (OVERCOMMIT_MEMORY ,0 ,1 );update_mem ();alloc_and_check (free_total /2 ,EXPECT_PASS );alloc_and_check (sum_total *2 ,EXPECT_FAIL );/* start to test overcommit_memory=1 */ -set_sys_tune ("overcommit_memory" ,1 ,1 ); +TST_SYS_CONF_LONG_SET (OVERCOMMIT_MEMORY ,1 ,1 );alloc_and_check (sum_total /2 ,EXPECT_PASS );alloc_and_check (sum_total,EXPECT_PASS );
@@ -152,7 +155,7 @@ static int heavy_malloc(long size) {char *p; - p =malloc (size *KB ); + p =malloc (size *TST_KB );if (p !=NULL ) {tst_res (TINFO ,"malloc %ld kB successfully" , size);free (p);
@@ -240,7 +243,7 @@ static void calculate_total_batch_size(void)/* there are ncpu separate counters, that can all grow up to * batch_size. So the maximum error for __vm_enough_memory is * batch_size * ncpus. */ - total_batch_size = (batch_size * ncpus * pagesize) /KB ; + total_batch_size = (batch_size * ncpus * pagesize) /TST_KB ; }static struct tst_test test = {
@@ -253,8 +256,8 @@ static struct tst_test test = { .test_all = overcommit_memory_test, .skip_in_compat = 1, .save_restore = (const struct tst_path_val []) { - {"/proc/sys/vm/overcommit_memory" ,NULL ,TST_SR_TBROK }, - {"/proc/sys/vm/overcommit_ratio" ,NULL ,TST_SR_TBROK }, + {OVERCOMMIT_MEMORY ,NULL ,TST_SR_TBROK }, + {OVERCOMMIT_RATIO ,NULL ,TST_SR_TBROK }, {} }, };
Signature · 5 lines
2.45.2 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 01/13] lib: tst_sys_conf: Add two functions
Quoted 9 lines · Cyril Hrubis
Add two functions to read/write integer values from/to sysfs or procfs files.
With that we replace the
get_sys_tune()andset_sys_tune()fromtestcases/kernel/mem/lib/mem.cwith a better implementation.We also remove the inclusion of the mem library from tunables, since it's no longer needed there.
Thanks for doing this, all touched tests pass on RHEL 9&10 from my side.
Quoted 464 lines
Signed-off-by Cyril Hrubis <[email protected]>--- include/tst_sys_conf.h | 31 +++++++++++++++++++ lib/tst_sys_conf.c | 29 +++++++++++++++++ .../mem/hugetlb/hugeshmat/hugeshmat04.c | 2 +- testcases/kernel/mem/include/mem.h | 2 -- testcases/kernel/mem/lib/mem.c | 29 ----------------- testcases/kernel/mem/oom/oom01.c | 10 +++--- testcases/kernel/mem/tunable/Makefile | 1 - testcases/kernel/mem/tunable/max_map_count.c | 17 +++++----- .../kernel/mem/tunable/min_free_kbytes.c | 27 ++++++++-------- .../kernel/mem/tunable/overcommit_memory.c | 23 ++++++++------ 10 files changed, 104 insertions(+), 67 deletions(-)include/tst_sys_conf.h +4
-0@@ -28,4 +28,35 @@ int tst_sys_conf_save(const struct tst_path_val *conf);void tst_sys_conf_restore (int verbose);void tst_sys_conf_dump (void ); +/** +* TST_SYS_CONF_LONG_SET() +* +* Sets a sysfs or procfs file and optionally checks that it was set correctly.
+ *
+ * @param path A path to a sysfs or a procfs file.
+ * @param val A long int value to be written to the file.
+ * @param check If non-zero the library reads the file back and checks that the
+ * value is the one we have written there. If not the
library calls
+ *tst_brk(TBROK, ...).
+ */include/tst_sys_conf.h +20
-0+#define TST_SYS_CONF_LONG_SET (path, val, check) \ + tst_sys_conf_long_set_(__FILE__, __LINE__, path, val, check) + +void tst_sys_conf_long_set_ (const char *file,const int lineno, +const char *path,long val,int check); + + +/** +* TST_SYS_CONF_LONG_GET() +* +* Gets a sysfs or procfs file value and converts it to long. +* +* @param path A path to a sysfs or a procfs file. +*/ +#define TST_SYS_CONF_LONG_GET (path) \ + tst_sys_conf_long_get_(__FILE__, __LINE__, path) + +long tst_sys_conf_long_get_ (const char *file,const int lineno, +const char *path); +#endif lib/tst_sys_conf.c +21
-0@@ -145,3 +145,32 @@ void tst_sys_conf_restore(int verbose) } } +long tst_sys_conf_long_get_ (const char *file,const int lineno, +const char *path) +{ +long ret; + +safe_file_scanf (file, lineno,NULL , path,"%ld" , &ret); + +return ret; +} + +void tst_sys_conf_long_set_ (const char *file,const int lineno, +const char *path,long val,int check) +{ +tst_res_ (file, lineno,TINFO ,"Setting %s to %ld" , path, val); + +safe_file_printf (file, lineno,NULL , path,"%ld" , val); + +if (check) { +long read_val; + + safe_file_scanf(file, lineno, NULL, path, "%ld",
&read_val);lib/tst_sys_conf.c +8
-0+ +if (val != read_val) +tst_brk_ (file, lineno,TBROK , +"Wrote %ld to %s but read back %ld" , + val, path, read_val); + } + +}testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c +1
-1@@ -82,7 +82,7 @@ static void setup(void)long hpage_size, orig_hugepages;unsigned long new_shmmax; - orig_hugepages =get_sys_tune ("nr_hugepages" ); + orig_hugepages =TST_SYS_CONF_LONG_GET ("/proc/sys/vm/nr_hugepages" );SAFE_FILE_SCANF (PATH_SHMMAX ,"%lu" , &new_shmmax);if (
new_shmmax< SIZE)testcases/kernel/mem/include/mem.h +0
-2@@ -71,8 +71,6 @@ void write_cpusets(const struct tst_cg_group *cg, long nd);/* shared */ unsigned int get_a_numa_node (void );int path_exist (const char *path, ...); -void set_sys_tune (char *sys_file,long tune,int check); -long get_sys_tune (char *sys_file);void update_shm_size (size_t *shm_size);testcases/kernel/mem/lib/mem.c +0
-29@@ -638,35 +638,6 @@ int path_exist(const char *path, ...)return access (pathbuf,F_OK ) ==0 ; } -void set_sys_tune (char *sys_file,long tune,int check) -{ -long val; -char path[BUFSIZ ]; - -tst_res (TINFO ,"set %s to %ld" , sys_file, tune); - -snprintf (path,BUFSIZ ,PATH_SYSVM "%s" , sys_file); -SAFE_FILE_PRINTF (path,"%ld" , tune); - -if (check) { - val =get_sys_tune (sys_file); -if (val != tune) -tst_brk (TBROK ,"%s = %ld, but expect %ld" , - sys_file, val, tune); - } -} - -long get_sys_tune (char *sys_file) -{ -char path[BUFSIZ ]; -long tune; - -snprintf (path,BUFSIZ ,PATH_SYSVM "%s" , sys_file); -SAFE_FILE_SCANF (path,"%ld" , &tune); - -return tune; -} -void update_shm_size (size_t * shm_size) {size_t shmmax;testcases/kernel/mem/oom/oom01.c +6
-4@@ -18,18 +18,20 @@#include <unistd.h> #include "mem.h" +#define OVERCOMMIT_MEMORY "/proc/sys/vm/overcommit_memory" +static void verify_oom (void ) {/* we expect mmap to fail before OOM is hit */ -set_sys_tune ("overcommit_memory" ,2 ,1 ); +TST_SYS_CONF_LONG_SET (OVERCOMMIT_MEMORY ,2 ,1 );oom (NORMAL ,0 ,ENOMEM ,0 );/* with overcommit_memory set to 0 or 1 there's no * guarantee that mmap fails before OOM */ -set_sys_tune ("overcommit_memory" ,0 ,1 ); +TST_SYS_CONF_LONG_SET (OVERCOMMIT_MEMORY ,0 ,1 );oom (NORMAL ,0 ,ENOMEM ,1 ); -set_sys_tune ("overcommit_memory" ,1 ,1 ); +TST_SYS_CONF_LONG_SET (OVERCOMMIT_MEMORY ,1 ,1 );testoom (0 ,0 ,ENOMEM ,1 ); }@@ -40,7 +42,7 @@ static struct tst_test test = { .test_all = verify_oom, .skip_in_compat = 1, .save_restore = (const struct tst_path_val []) { - {"/proc/sys/vm/overcommit_memory" ,NULL ,TST_SR_TBROK }, + {OVERCOMMIT_MEMORY ,NULL ,TST_SR_TBROK }, {} }, };testcases/kernel/mem/tunable/Makefile +0
-1@@ -4,5 +4,4 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk -include $(top_srcdir)/testcases/kernel/mem/include/libmem.mk include $(top_srcdir)/include/mk/generic_leaf_target.mktestcases/kernel/mem/tunable/max_map_count.c +8
-5@@ -48,10 +48,13 @@#include <stdio.h> #include <stdlib.h> #include <sys/utsname.h> -#include "mem.h" +#include "tst_test.h" #define MAP_COUNT_DEFAULT 1024 -#define MAX_MAP_COUNT 65536L +#define MAX_MAP_COUNT_MAX 65536L + +#define OVERCOMMIT_MEMORY "/proc/sys/vm/overcommit_memory" +#define MAX_MAP_COUNT "/proc/sys/vm/max_map_count"/* This is a filter to exclude map entries which aren't accounted * for in the vm_area_struct's map_count. @@ -140,15 +143,15 @@ static void max_map_count_test(void) memfree =SAFE_READ_MEMINFO ("CommitLimit:" ) -SAFE_READ_MEMINFO ("Committed_AS:" );/* 64 used as a bias to make sure no overflow happen */ max_iters = memfree /sysconf (_SC_PAGESIZE) *1024 -64 ; -if (max_iters >MAX_MAP_COUNT ) - max_iters =MAX_MAP_COUNT ; +if (max_iters >MAX_MAP_COUNT_MAX ) + max_iters =MAX_MAP_COUNT_MAX ; max_maps =MAP_COUNT_DEFAULT ;if (max_iters < max_maps)tst_brk (TCONF ,"test requires more free memory" );while (max_maps <= max_iters) { -set_sys_tune ("max_map_count" , max_maps,1 ); +TST_SYS_CONF_LONG_SET (MAX_MAP_COUNT , max_maps,1 );switch (pid =SAFE_FORK ()) {case 0:testcases/kernel/mem/tunable/max_map_count.c +2
-2@@ -192,8 +195,8 @@ static struct tst_test test = { .forks_child = 1, .test_all = max_map_count_test, .save_restore = (const struct tst_path_val []) { - {"/proc/sys/vm/overcommit_memory" ,"0" ,TST_SR_TBROK }, - {"/proc/sys/vm/max_map_count" ,NULL ,TST_SR_TBROK }, + {OVERCOMMIT_MEMORY ,"0" ,TST_SR_TBROK }, + {MAX_MAP_COUNT ,NULL ,TST_SR_TBROK }, {} }, };testcases/kernel/mem/tunable/min_free_kbytes.c +8
-7@@ -35,10 +35,14 @@#include <stdio.h> #include <stdlib.h> #include "lapi/abisize.h" -#include "mem.h" +#include "tst_test.h" #define MAP_SIZE (1UL<<20) +#define OVERCOMMIT_MEMORY "/proc/sys/vm/overcommit_memory" +#define MIN_FREE_KBYTES "/proc/sys/vm/min_free_kbytes" +#define PANIC_ON_OOM "/proc/sys/vm/panic_on_oom" +volatile int end;static long default_tune =-1 ;static unsigned long total_mem;@@ -88,16 +92,13 @@ static void test_tune(unsigned long overcommit_policy)int ret, i;unsigned long tune, memfree, memtotal; -set_sys_tune ("overcommit_memory" , overcommit_policy,1 ); +TST_SYS_CONF_LONG_SET (OVERCOMMIT_MEMORY , overcommit_policy,1 );for (i =0 ; i <3 ; i++) { -/* case1 */ if (i ==0 ) -set_sys_tune ("min_free_kbytes" , default_tune,1 ); -/* case2 */ +TST_SYS_CONF_LONG_SET (MIN_FREE_KBYTES , default_tune,1 );else if (i ==1 ) { -set_sys_tune ("min_free_kbytes" ,2 * default_tune, 1); -/* case3 */ +TST_SYS_CONF_LONG_SET (MIN_FREE_KBYTES ,2 * default_tune,1 );} else { memfree = SAFE_READ_MEMINFO("MemFree:"); memtotal = SAFE_READ_MEMINFO("MemTotal:");testcases/kernel/mem/tunable/min_free_kbytes.c +4
-4@@ -105,7 +106,7 @@ static void test_tune(unsigned long overcommit_policy)if (tune > (memtotal /50 )) tune = memtotal /50 ; -set_sys_tune ("min_free_kbytes" , tune,1 ); +TST_SYS_CONF_LONG_SET (MIN_FREE_KBYTES , tune,1 ); }fflush (stdout);@@ -189,7 +190,7 @@ static void check_monitor(void)while (end) { memfree =SAFE_READ_MEMINFO ("MemFree:" ); - tune =get_sys_tune ("min_free_kbytes" ); + tune =TST_SYS_CONF_LONG_GET (MIN_FREE_KBYTES );if (memfree < tune) { tst_res(TINFO, "MemFree is %lu kB, "@@ -208,14 +209,14 @@ static void sighandler(int signo LTP_ATTRIBUTE_UNUSED) static void setup(void) { -if (get_sys_tune ("panic_on_oom" )) { +if (TST_SYS_CONF_LONG_GET (PANIC_ON_OOM )) {tst_brk (TCONF ,"panic_on_oom is set, disable it to run these testcases"); } total_mem =SAFE_READ_MEMINFO ("MemTotal:" ) +SAFE_READ_MEMINFO ("SwapTotal:" ); - default_tune =get_sys_tune ("min_free_kbytes" ); + default_tune =TST_SYS_CONF_LONG_GET (MIN_FREE_KBYTES );}
static struct
tst_testtest = {testcases/kernel/mem/tunable/min_free_kbytes.c +2
-2@@ -225,8 +226,8 @@ static struct tst_test test = { .setup = setup, .test_all = min_free_kbytes_test, .save_restore = (const struct tst_path_val []) { - {"/proc/sys/vm/overcommit_memory" ,NULL ,TST_SR_TBROK }, - {"/proc/sys/vm/min_free_kbytes" ,NULL ,TST_SR_TBROK }, + {OVERCOMMIT_MEMORY ,NULL ,TST_SR_TBROK }, + {MIN_FREE_KBYTES ,NULL ,TST_SR_TBROK }, {} }, };testcases/kernel/mem/tunable/overcommit_memory.c +13
-11@@ -62,12 +62,15 @@#include <stdio.h> #include <stdlib.h> #include <limits.h> -#include "mem.h" +#include "tst_test.h" #define DEFAULT_OVER_RATIO 50L#define EXPECT_PASS 0#define EXPECT_FAIL 1 +#define OVERCOMMIT_MEMORY "/proc/sys/vm/overcommit_memory" +#define OVERCOMMIT_RATIO "/proc/sys/vm/overcommit_ratio" +static char *R_opt;static long old_overcommit_ratio =-1 ;static long overcommit_ratio;@@ -93,7 +96,7 @@ static void setup(void)else overcommit_ratio =DEFAULT_OVER_RATIO ; - old_overcommit_ratio =get_sys_tune ("overcommit_ratio" ); + old_overcommit_ratio =TST_SYS_CONF_LONG_GET (OVERCOMMIT_RATIO ); mem_total =SAFE_READ_MEMINFO ("MemTotal:" );tst_res (TINFO ,"MemTotal is %ld kB" , mem_total);@@ -115,7 +118,7 @@ static void setup(void)SAFE_SETRLIMIT (RLIMIT_AS , &lim); } -set_sys_tune ("overcommit_ratio" , overcommit_ratio,1 ); +TST_SYS_CONF_LONG_SET (OVERCOMMIT_RATIO , overcommit_ratio,1 );calculate_total_batch_size ();tst_res (TINFO ,"TotalBatchSize is %ld kB" , total_batch_size);@@ -124,7 +127,7 @@ static void setup(void)static void overcommit_memory_test (void ) {/* start to test overcommit_memory=2 */ -set_sys_tune ("overcommit_memory" ,2 ,1 ); +TST_SYS_CONF_LONG_SET (OVERCOMMIT_MEMORY ,2 ,1 );update_mem_commit ();alloc_and_check (commit_left *2 ,EXPECT_FAIL );@@ -133,14 +136,14 @@ static void overcommit_memory_test(void)alloc_and_check (commit_left /2 ,EXPECT_PASS );/* start to test overcommit_memory=0 */ -set_sys_tune ("overcommit_memory" ,0 ,1 ); +TST_SYS_CONF_LONG_SET (OVERCOMMIT_MEMORY ,0 ,1 );update_mem ();alloc_and_check (free_total /2 ,EXPECT_PASS );alloc_and_check (sum_total *2 ,EXPECT_FAIL );/* start to test overcommit_memory=1 */ -set_sys_tune ("overcommit_memory" ,1 ,1 ); +TST_SYS_CONF_LONG_SET (OVERCOMMIT_MEMORY ,1 ,1 );alloc_and_check (sum_total /2 ,EXPECT_PASS );alloc_and_check (sum_total,EXPECT_PASS );@@ -152,7 +155,7 @@ static int heavy_malloc(long size) {char *p; - p =malloc (size *KB ); + p =malloc (size *TST_KB );if (p !=NULL ) {tst_res (TINFO ,"malloc %ld kB successfully" , size);free (p);@@ -240,7 +243,7 @@ static void calculate_total_batch_size(void)/* there are ncpu separate counters, that can all grow up to * batch_size. So the maximum error for __vm_enough_memory is * batch_size * ncpus. */ - total_batch_size = (batch_size * ncpus * pagesize) /KB ; + total_batch_size = (batch_size * ncpus * pagesize) /TST_KB ; }static struct tst_test test = {@@ -253,8 +256,8 @@ static struct tst_test test = { .test_all = overcommit_memory_test, .skip_in_compat = 1, .save_restore = (const struct tst_path_val []) { - {"/proc/sys/vm/overcommit_memory" ,NULL ,TST_SR_TBROK }, - {"/proc/sys/vm/overcommit_ratio" ,NULL ,TST_SR_TBROK }, + {OVERCOMMIT_MEMORY ,NULL ,TST_SR_TBROK }, + {OVERCOMMIT_RATIO ,NULL ,TST_SR_TBROK }, {} }, }; --2.45.2
--
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 01/13] lib: tst_sys_conf: Add two functions
In reply to Cyril HrubisHi Cyril,
Quoted 8 lines
Add two functions to read/write integer values from/to sysfs or procfs files.
With that we replace the
get_sys_tune()andset_sys_tune()fromtestcases/kernel/mem/lib/mem.cwith a better implementation.We also remove the inclusion of the mem library from tunables, since it's no longer needed there.
+1
Minor formatting notes below.
Quoted 2 lines
+/**
+ *TST_SYS_CONF_LONG_SET()
I wonder how to silence warning when there is no short description.
include/tst_sys_conf.h:32: [kernel-doc WARN] : missing initial short description of 'TST_SYS_CONF_LONG_SET'
Quoted 6 lines
+ *
+ * Sets a sysfs or procfs file and optionally checks that it was set correctly.
+ *
+ * @param path A path to a sysfs or a procfs file.
+ * @param val A long int value to be written to the file.
+ * @param check If non-zero the library reads the file back and checks that the
nit: please fix these before merge (doxygen => sphinx syntax):
include/tst_sys_conf.h:32: [kernel-doc WARN] : no description found for parameter 'path' include/tst_sys_conf.h:32: [kernel-doc WARN] : no description found for parameter 'val' include/tst_sys_conf.h:32: [kernel-doc WARN] : no description found for parameter 'check'
Quoted 8 lines
+ * value is the one we have written there. If not the library calls
+ *tst_brk(TBROK, ...).
+ */include/tst_sys_conf.h +3
-0+#define TST_SYS_CONF_LONG_SET (path, val, check) \ + tst_sys_conf_long_set_(__FILE__, __LINE__, path, val, check) +
include/tst_sys_conf.h int tst_sys_conf_save(const struct tst_path_val *conf); · line 54
Quoted 10 lines
include/tst_sys_conf.h +10
-0+void tst_sys_conf_long_set_ (const char *file,const int lineno, +const char *path,long val,int check); + + +/** +* TST_SYS_CONF_LONG_GET() +* +* Gets a sysfs or procfs file value and converts it to long. +* +* @param path A path to a sysfs or a procfs file.
And here:
include/tst_sys_conf.h:50: [kernel-doc WARN] : no description found for parameter 'path'
Quoted 13 lines
+ */
include/tst_sys_conf.h +6
-0+#define TST_SYS_CONF_LONG_GET (path) \ + tst_sys_conf_long_get_(__FILE__, __LINE__, path) + +long tst_sys_conf_long_get_ (const char *file,const int lineno, +const char *path); +#endif lib/tst_sys_conf.c +0
-0
lib/tst_sys_conf.c void tst_sys_conf_restore(int verbose) · line 149
Quoted 5 lines
lib/tst_sys_conf.c +2
-0@@ -145,3 +145,32 @@ void tst_sys_conf_restore(int verbose) } } +long tst_sys_conf_long_get_ (const char *file,const int lineno, +const char *path)
nit: could you please use tabs instead of spaces?
Because it triggers warnings:
$ make check-tst_sys_conf CHECK lib/tst_sys_conf.c tst_sys_conf.c:149: ERROR: code indent should use tabs where possible tst_sys_conf.c:149: WARNING: please, no spaces at the start of a line tst_sys_conf.c:159: ERROR: code indent should use tabs where possible tst_sys_conf.c:159: WARNING: please, no spaces at the start of a line tst_sys_conf.c:161: ERROR: code indent should use tabs where possible tst_sys_conf.c:161: WARNING: please, no spaces at the start of a line tst_sys_conf.c:163: ERROR: code indent should use tabs where possible tst_sys_conf.c:163: WARNING: please, no spaces at the start of a line tst_sys_conf.c:165: ERROR: code indent should use tabs where possible tst_sys_conf.c:165: WARNING: please, no spaces at the start of a line tst_sys_conf.c:170: ERROR: code indent should use tabs where possible tst_sys_conf.c:170: WARNING: please, no spaces at the start of a line tst_sys_conf.c:171: ERROR: code indent should use tabs where possible tst_sys_conf.c:171: WARNING: please, no spaces at the start of a line tst_sys_conf.c:172: ERROR: code indent should use tabs where possible tst_sys_conf.c:173: ERROR: code indent should use tabs where possible tst_sys_conf.c:173: WARNING: please, no spaces at the start of a line tst_sys_conf.c:174: ERROR: code indent should use tabs where possible tst_sys_conf.c:174: WARNING: please, no spaces at the start of a line
Quoted 7 lines
lib/tst_sys_conf.c +7
-0+{ +long ret; + +safe_file_scanf (file, lineno,NULL , path,"%ld" , &ret); + +return ret; +}
lib/tst_sys_conf.c void tst_sys_conf_restore(int verbose) · line 166
Quoted 10 lines
lib/tst_sys_conf.c +10
-0+ +void tst_sys_conf_long_set_ (const char *file,const int lineno, +const char *path,long val,int check) +{ +tst_res_ (file, lineno,TINFO ,"Setting %s to %ld" , path, val); + +safe_file_printf (file, lineno,NULL , path,"%ld" , val); + +if (check) { +long read_val;
nit: obviously also here are tabs and spaces mixed. Minor, but worth to fix before merge.
Maybe we would benefit to add .editorconfig [1] (see examples [2] [3]).
Also maybe to save indent?
if (!check)
return;
Kind regards,
Petr
lib/tst_sys_conf.c void tst_sys_conf_restore(int verbose) · line 176
Quoted 10 lines
lib/tst_sys_conf.c +10
-0+ +safe_file_scanf (file, lineno,NULL , path,"%ld" , &read_val); + +if (val != read_val) +tst_brk_ (file, lineno,TBROK , +"Wrote %ld to %s but read back %ld" , + val, path, read_val); + } + +}
[1] https://editorconfig.org/
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/.editorconfig
[3] https://git.busybox.net/buildroot/tree/.editorconfig
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 2/13 lib: Replace path_exist() with tst_path_exists()
In reply to Cyril HrubisMove and rename the path_exist() function from testcases/kernel/mem/lib/ to the to level library.
This removes mem.h dependency from mem/cpuset/ test.
--- include/tst_fs.h | 10 ++++++++++ lib/tst_path_exists.c | 23 +++++++++++++++++++++++ testcases/kernel/mem/cpuset/Makefile | 2 +- testcases/kernel/mem/cpuset/cpuset01.c | 4 ++-- testcases/kernel/mem/include/mem.h | 1 - testcases/kernel/mem/lib/mem.c | 18 +++--------------- 6 files changed, 39 insertions(+), 19 deletions(-) create mode 100644 lib/tst_path_exists.c
include/tst_fs.h +10 -0
@@ -145,6 +145,16 @@ int tst_dir_is_empty_(void (*cleanup)(void), const char *name, int verbose);*/ int tst_get_path (const char *prog_name,char *buf,size_t buf_len); +/** +* tst_path_exists() +* +* @param fmt A printf-like format used to construct the path. +* @param ... A printf-like parameter list. +* @return Non-zero if path exists, zero otherwise. +*/ +int tst_path_exists (const char *fmt, ...) + __attribute__ ((format (printf,1 ,2 ))); +/* * Fill a file with specified pattern * @fd: file descriptor
lib/tst_path_exists.c new file +23 -0
@@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) Linux Test Project, 2011-2021 +* Copyright (c) Cyril Hrubis <[email protected]> 2024 +*/ + +#include <stdio.h> +#include <stdarg.h> +#include <unistd.h> +#include <limits.h> +#include "tst_fs.h" + +int tst_path_exists (const char *fmt, ...) +{ +va_list ap; +char pathbuf[PATH_MAX ]; + +va_start (ap, fmt); +vsnprintf (pathbuf,sizeof (pathbuf), fmt, ap); +va_end (ap); + +return access (pathbuf,F_OK ) ==0 ; +}
testcases/kernel/mem/cpuset/Makefile +1 -1
@@ -20,5 +20,5 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk -include $(top_srcdir)/testcases/kernel/mem/include/libmem.mk +include $(top_srcdir)/testcases/kernel/include/lib.mk include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/mem/cpuset/cpuset01.c +2 -2
@@ -30,7 +30,7 @@#include <numaif.h> #endif -#include "mem.h" +#include "tst_test.h" #include "numa_helper.h" #ifdef HAVE_NUMA_V2
@@ -164,7 +164,7 @@ static long count_cpu(void) {int ncpus =0 ; -while (path_exist (PATH_SYS_SYSTEM "/cpu/cpu%d" , ncpus)) +while (tst_path_exists (PATH_SYS_SYSTEM "/cpu/cpu%d" , ncpus)) ncpus++;return ncpus;
testcases/kernel/mem/include/mem.h +0 -1
@@ -70,7 +70,6 @@ void write_cpusets(const struct tst_cg_group *cg, long nd);/* shared */ unsigned int get_a_numa_node (void ); -int path_exist (const char *path, ...);void update_shm_size (size_t *shm_size);
testcases/kernel/mem/lib/mem.c +3 -15
@@ -545,19 +545,19 @@ static void gather_node_cpus(char *cpus, long nd)char buf[BUFSIZ ];char path[BUFSIZ ], path1[BUFSIZ ]; -while (path_exist (PATH_SYS_SYSTEM "/cpu/cpu%d" , ncpus)) +while (tst_path_exists (PATH_SYS_SYSTEM "/cpu/cpu%d" , ncpus)) ncpus++;for (i =0 ; i < ncpus; i++) {snprintf (path,BUFSIZ ,PATH_SYS_SYSTEM "/node/node%ld/cpu%d" , nd, i); -if (path_exist (path)) { +if (tst_path_exists ("%s" , path)) {snprintf (path1,BUFSIZ ,"%s/online" , path);/* * if there is no online knob, then the cpu cannot * be taken offline */ -if (path_exist (path1)) { +if (tst_path_exists ("%s" , path1)) {SAFE_FILE_SCANF (path1,"%ld" , &online);if (online ==0 )continue ;
@@ -626,18 +626,6 @@ unsigned int get_a_numa_node(void)abort (); } -int path_exist (const char *path, ...) -{ -va_list ap; -char pathbuf[PATH_MAX ]; - -va_start (ap, path); -vsnprintf (pathbuf,sizeof (pathbuf), path, ap); -va_end (ap); - -return access (pathbuf,F_OK ) ==0 ; -} -void update_shm_size (size_t * shm_size) {size_t shmmax;
Signature · 5 lines
2.45.2 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 02/13] lib: Replace path_exist() with tst_path_exists()
Hi Cyril,
Quoted 2 lines
Move and rename the
path_exist()function from testcases/kernel/mem/lib/ to the to level library.
+1
Quoted 1 line
This removes
mem.hdependency from mem/cpuset/ test.
+1
include/tst_fs.h int tst_dir_is_empty_(void (*cleanup)(void), const char *name, int verbose); · line 149
Quoted 10 lines
include/tst_fs.h +2
-0@@ -145,6 +145,16 @@ int tst_dir_is_empty_(void (*cleanup)(void), const char *name, int verbose);*/ int tst_get_path (const char *prog_name,char *buf,size_t buf_len); +/** +* tst_path_exists()
nit: any short desc?
include/tst_fs.h int tst_dir_is_empty_(void (*cleanup)(void), const char *name, int verbose); · line 154
Quoted 5 lines
include/tst_fs.h +5
-0+* +* @param fmt A printf-like format used to construct the path. +* @param ... A printf-like parameter list. +* @return Non-zero if path exists, zero otherwise. +*/
Thanks for taking care of the docs. I guess this is doxygen syntax right? Could you please before merge fix doc syntax - use kernel doc formatting? (no param, return: and add short desc for the function).
/**
* tst_path_exists() - check path exists
*
* @fmt: A printf-like format used to construct the path.
* @... A printf-like parameter list.
* return: Non-zero if path exists, zero otherwise. */
This will apply at least to the first commit as well.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 02/13] lib: Replace path_exist() with tst_path_exists()
Hi!
Quoted 11 lines
include/tst_fs.h int tst_dir_is_empty_(void (*cleanup)(void), const char *name, int verbose); · line 149
Quoted 10 lines
include/tst_fs.h +2
-0@@ -145,6 +145,16 @@ int tst_dir_is_empty_(void (*cleanup)(void), const char *name, int verbose);*/ int tst_get_path (const char *prog_name,char *buf,size_t buf_len); +/** +* tst_path_exists() nit: any short desc?
I kind of do not like repeating the same sentence we have in the return description here.
Quoted 9 lines
include/tst_fs.h int tst_dir_is_empty_(void (*cleanup)(void), const char *name, int verbose); · line 154
Quoted 5 lines
include/tst_fs.h +5
-0+* +* @param fmt A printf-like format used to construct the path. +* @param ... A printf-like parameter list. +* @return Non-zero if path exists, zero otherwise. +*/ Thanks for taking care of the docs. I guess this is doxygen syntax right? Could you please before merge fix doc syntax - use kernel doc formatting? (no param, return: and add short desc for the function).
Sigh, yes. Will fix.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 02/13] lib: Replace path_exist() with tst_path_exists()
Quoted 9 lines
Hi!
Quoted 7 lines
Quoted 7 lines
include/tst_fs.h +0
-0@@ -145,6 +145,16 @@ int tst_dir_is_empty_(void (*cleanup)(void), const char *name, int verbose);*/ int tst_get_path (const char *prog_name,char *buf,size_t buf_len);
Quoted 5 lines
Quoted 3 lines
include/tst_fs.h int tst_dir_is_empty_(void (*cleanup)(void), const char *name, int verbose); · line 149
Quoted 2 lines
include/tst_fs.h +2
-0+/** +* tst_path_exists() nit: any short desc?
I kind of do not like repeating the same sentence we have in the return description here.
Sure. It triggers warning:
[kernel-doc WARN] : missing initial short description of 'tst_path_exists'
I'll just ignore them (some warning mean wrong docs, this one is innocent, also we have 145x warnings about duplicate label, thus it's not easy to see if newly added source has proper syntax or not).
Quoted 11 lines
Quoted 9 lines
include/tst_fs.h int tst_dir_is_empty_(void (*cleanup)(void), const char *name, int verbose); · line 154
Quoted 5 lines
include/tst_fs.h +5
-0+* +* @param fmt A printf-like format used to construct the path. +* @param ... A printf-like parameter list. +* @return Non-zero if path exists, zero otherwise. +*/ Thanks for taking care of the docs. I guess this is doxygen syntax right? Could you please before merge fix doc syntax - use kernel doc formatting? (no param, return: and add short desc for the function).
Sigh, yes. Will fix.
Thanks (this mean missing docs).
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 3/13 lib: Add tst_mapping_in_range()
In reply to Cyril HrubisThis moves the range_is_mapped() function from testcases/kernel/mem/lib/mem.c to a top level library and renames the function to a better fitting name.
--- include/tst_memutils.h | 11 +++++++ lib/tst_memutils.c | 31 ++++++++++++++++++ .../kernel/mem/hugetlb/hugemmap/hugemmap02.c | 4 +-- .../kernel/mem/hugetlb/hugemmap/hugemmap13.c | 4 +-- .../kernel/mem/hugetlb/hugemmap/hugemmap14.c | 6 ++-- .../mem/hugetlb/hugeshmat/hugeshmat04.c | 2 +- testcases/kernel/mem/include/mem.h | 2 -- testcases/kernel/mem/lib/mem.c | 32 ------------------- 8 files changed, 50 insertions(+), 42 deletions(-)
include/tst_memutils.h +11 -0
@@ -60,4 +60,15 @@ void tst_disable_oom_protection(pid_t pid);#define TST_PRINT_MEMINFO () safe_print_file(__FILE__, __LINE__, "/proc/meminfo") +/** +* tst_mapping_in_range() +* +* @low A lower address inside of the processe address space. +* @high A higher address inside of the processe address space. +* +* @return Returns true if there is a mapping between low and high addresses in +* the process address space. +*/ +int tst_mapping_in_range (unsigned long low,unsigned long high); +#endif /* TST_MEMUTILS_H__ */
lib/tst_memutils.c +31 -0
@@ -14,6 +14,7 @@#include "tst_test.h" #include "tst_memutils.h" #include "tst_capability.h" +#include "tst_safe_stdio.h" #include "lapi/syscalls.h" #define BLOCKSIZE (16 * 1024 * 1024)
@@ -184,3 +185,33 @@ void tst_disable_oom_protection(pid_t pid) {set_oom_score_adj (pid,0 ); } + +int tst_mapping_in_range (unsigned long low,unsigned long high) +{ +FILE *fp; + + fp =SAFE_FOPEN ("/proc/self/maps" ,"r" ); + +while (!feof (fp)) { +unsigned long start, end; +int ret; + + ret =fscanf (fp,"%lx-%lx %*[^\n]\n" , &start, &end); +if (ret !=2 ) { +fclose (fp); +tst_brk (TBROK |TERRNO ,"Couldn't parse /proc/self/maps line." ); + } + +if ((start >= low) && (start < high)) { +fclose (fp); +return 1 ; + } +if ((end >= low) && (end < high)) { +fclose (fp); +return 1 ; + } + } + +fclose (fp); +return 0 ; +}
testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c +2 -2
@@ -62,7 +62,7 @@ static void test_hugemmap(void) addrlist[i] = addr; } -while (range_is_mapped (low_addr, low_addr + map_sz) ==1 ) { +while (tst_mapping_in_range (low_addr, low_addr + map_sz) ==1 ) { low_addr = low_addr +0x10000000 ;if (low_addr <LOW_ADDR )
@@ -74,7 +74,7 @@ static void test_hugemmap(void)if (addr ==MAP_FAILED )tst_brk (TBROK |TERRNO ,"mmap failed on nfildes" ); -while (range_is_mapped (low_addr2, low_addr2 + map_sz) ==1 ) { +while (tst_mapping_in_range (low_addr2, low_addr2 + map_sz) ==1 ) { low_addr2 = low_addr2 +0x10000000 ;if (low_addr2 <LOW_ADDR2 )
testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c +2 -2
@@ -45,7 +45,7 @@ static void run_test(void) below_start =FOURGB ; above_end =1024ULL *1024 *1024 *1024 ; -if (range_is_mapped (below_start, above_end) ==1 ) { +if (tst_mapping_in_range (below_start, above_end) ==1 ) {tst_res (TINFO |TERRNO ,"region 4G-IT is not free & " "mmap() failed expected" );tst_res (TPASS ,"Successful but inconclusive" );
@@ -70,7 +70,7 @@ static void run_test(void) below_start =FOURGB -MMAP_GRANULARITY ; above_end =FOURGB ; -if (range_is_mapped (below_start, above_end) ==1 ) { +if (tst_mapping_in_range (below_start, above_end) ==1 ) {tst_res (TINFO |TERRNO ,"region (4G-MMAP_GRANULARITY)-4G is not free & " "mmap() failed expected" );tst_res (TPASS ,"Successful but inconclusive" );
testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c +3 -3
@@ -50,7 +50,7 @@ static void run_test(void) below_start =FOURGB -256ULL *1024 *1024 ; above_end =FOURGB ; -if (range_is_mapped (below_start, above_end) ==1 ) { +if (tst_mapping_in_range (below_start, above_end) ==1 ) {tst_res (TINFO |TERRNO ,"region (4G-256M)-4G is not free & " "mmap() failed expected" );tst_res (TPASS ,"Successful but inconclusive" );
@@ -73,7 +73,7 @@ static void run_test(void) below_start =FOURGB ; above_end =FOURGB + page_size; -if (range_is_mapped (below_start, above_end) ==1 ) { +if (tst_mapping_in_range (below_start, above_end) ==1 ) {tst_res (TINFO |TERRNO ,"region 4G-(4G+page) is not free & " "mmap() failed expected" );tst_res (TPASS ,"Successful but inconclusive" );
@@ -101,7 +101,7 @@ static void run_test(void) below_start = highaddr; above_end = highaddr + page_size; -if (range_is_mapped (below_start, above_end) ==1 ) { +if (tst_mapping_in_range (below_start, above_end) ==1 ) {tst_res (TINFO |TERRNO ,"region haddr-(haddr+page) not free & " "mmap() failed unexpected" );tst_res (TPASS ,"Successful but inconclusive" );
testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c +1 -1
@@ -55,7 +55,7 @@ static void shared_hugepage(void)tst_brk (TBROK |TERRNO ,"shmget" );while (boundary <=BOUNDARY_MAX - &&range_is_mapped (boundary, boundary+SIZE )) + &&tst_mapping_in_range (boundary, boundary+SIZE )) boundary +=128 *1024 *1024 ;if (boundary >BOUNDARY_MAX )tst_brk (TCONF ,"failed to find free unmapped range" );
testcases/kernel/mem/include/mem.h +0 -2
@@ -73,6 +73,4 @@ unsigned int get_a_numa_node(void);void update_shm_size (size_t *shm_size); -/* MMAP */ -int range_is_mapped (unsigned long low,unsigned long high);#endif
testcases/kernel/mem/lib/mem.c +0 -32
@@ -636,35 +636,3 @@ void update_shm_size(size_t * shm_size) *shm_size = shmmax; } } - -int range_is_mapped (unsigned long low,unsigned long high) -{ -FILE *fp; - - fp =fopen ("/proc/self/maps" ,"r" ); -if (fp ==NULL ) -tst_brk (TBROK |TERRNO ,"Failed to open /proc/self/maps." ); - -while (!feof (fp)) { -unsigned long start, end; -int ret; - - ret =fscanf (fp,"%lx-%lx %*[^\n]\n" , &start, &end); -if (ret !=2 ) { -fclose (fp); -tst_brk (TBROK |TERRNO ,"Couldn't parse /proc/self/maps line." ); - } - -if ((start >= low) && (start < high)) { -fclose (fp); -return 1 ; - } -if ((end >= low) && (end < high)) { -fclose (fp); -return 1 ; - } - } - -fclose (fp); -return 0 ; -}
Signature · 5 lines
2.45.2 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 03/13] lib: Add tst_mapping_in_range()
Quoted 3 lines
This moves the
range_is_mapped()function fromtestcases/kernel/mem/lib/mem.cto a top level library and renames the function to a better fitting name.
+1
Quoted 5 lines
+/**
+ *tst_mapping_in_range()
+ *
+ * @low A lower address inside of the processe address space.
+ * @high A higher address inside of the processe address space.
nit: missing ':' causes "undefined" instead of the documentation. Please fix that before merge.
Quoted 20 lines
+ *
+ * @return Returns true if there is a mapping between low and high addresses in
+ * the process address space.
+ */include/tst_memutils.h +2
-0+int tst_mapping_in_range (unsigned long low,unsigned long high); +#endif /* TST_MEMUTILS_H__ */ lib/tst_memutils.c +1
-0@@ -14,6 +14,7 @@#include "tst_test.h" #include "tst_memutils.h" #include "tst_capability.h" +#include "tst_safe_stdio.h" #include "lapi/syscalls.h" #define BLOCKSIZE (16 * 1024 * 1024)
lib/tst_memutils.c void tst_disable_oom_protection(pid_t pid) · line 193
Quoted 9 lines
lib/tst_memutils.c +6
-0@@ -184,3 +185,33 @@ void tst_disable_oom_protection(pid_t pid) {set_oom_score_adj (pid,0 ); } + +int tst_mapping_in_range (unsigned long low,unsigned long high) +{ +FILE *fp; + + fp =SAFE_FOPEN ("/proc/self/maps" ,"r" );
nit: it might be better to have const char *file, const int lineno params and have TST_MAPPING_IN_RANGE(). But I'm OK to keep it this way.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 4/13 testcases/kernel/mem: Move get_a_numa_node()
In reply to Cyril HrubisMove get_a_numa_node() from the library to the ksm_common.h since the function is used only by the ksm testcases.
--- testcases/kernel/mem/include/mem.h | 3 --- testcases/kernel/mem/ksm/ksm_common.h | 35 +++++++++++++++++++++++++++ testcases/kernel/mem/lib/mem.c | 33 ------------------------- 3 files changed, 35 insertions(+), 36 deletions(-)
testcases/kernel/mem/include/mem.h +0 -3
@@ -68,9 +68,6 @@ void write_memcg(void);/* cpuset/memcg - include/tst_cgroup.h */ void write_cpusets (const struct tst_cg_group *cg,long nd); -/* shared */ -unsigned int get_a_numa_node (void ); -void update_shm_size (size_t *shm_size);#endif
testcases/kernel/mem/ksm/ksm_common.h +35 -0
@@ -11,6 +11,7 @@#define KSM_COMMON_H__ #include "tst_test.h" +#include "numa_helper.h" #define DEFAULT_MEMSIZE 128
@@ -33,4 +34,38 @@ static inline void parse_ksm_options(char *str_size, int *size, tst_brk(TBROK, "the remainder of division of size by unit is not zero."); } +/* Warning: *DO NOT* use this function in child */ +static inline unsigned int get_a_numa_node (void ) +{ +unsigned int nd1, nd2; +int ret; + + ret =get_allowed_nodes (0 ,2 , &nd1, &nd2); +switch (ret) { +case 0 : +break ; +case -3 : +tst_brk (TCONF ,"requires a NUMA system." ); +default : +tst_brk (TBROK |TERRNO ,"1st get_allowed_nodes" ); + } + + ret =get_allowed_nodes (NH_MEMS |NH_CPUS ,1 , &nd1); +switch (ret) { +case 0 : +tst_res (TINFO ,"get node%u." , nd1); +return nd1; +case -3 : +tst_brk (TCONF ,"requires a NUMA system that has " +"at least one node with both memory and CPU " +"available." ); +default : +tst_brk (TBROK |TERRNO ,"2nd get_allowed_nodes" ); + } + +/* not reached */ +abort (); +} + +#endif /* KSM_COMMON_H__ */
testcases/kernel/mem/lib/mem.c +0 -33
@@ -593,39 +593,6 @@ void write_cpusets(const struct tst_cg_group *cg, long nd)/* shared */ -/* Warning: *DO NOT* use this function in child */ -unsigned int get_a_numa_node (void ) -{ -unsigned int nd1, nd2; -int ret; - - ret =get_allowed_nodes (0 ,2 , &nd1, &nd2); -switch (ret) { -case 0 : -break ; -case -3 : -tst_brk (TCONF ,"requires a NUMA system." ); -default : -tst_brk (TBROK |TERRNO ,"1st get_allowed_nodes" ); - } - - ret =get_allowed_nodes (NH_MEMS |NH_CPUS ,1 , &nd1); -switch (ret) { -case 0 : -tst_res (TINFO ,"get node%u." , nd1); -return nd1; -case -3 : -tst_brk (TCONF ,"requires a NUMA system that has " -"at least one node with both memory and CPU " -"available." ); -default : -tst_brk (TBROK |TERRNO ,"2nd get_allowed_nodes" ); - } - -/* not reached */ -abort (); -} -void update_shm_size (size_t * shm_size) {size_t shmmax;
Signature · 5 lines
2.45.2 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 04/13] testcases/kernel/mem: Move get_a_numa_node()
Hi Cyril,
Quoted 2 lines
Move
get_a_numa_node()from the library to theksm_common.hsince the function is used only by the ksm testcases.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 5/13 testcases/kernel/mem: Move update_shm_size()
In reply to Cyril HrubisMove update_shm_size() from the lib to the libhugetlb.c since the function is used only by the hugetlb testcases.
--- testcases/kernel/mem/hugetlb/lib/hugetlb.c | 11 +++++++++++ testcases/kernel/mem/hugetlb/lib/hugetlb.h | 3 +++ testcases/kernel/mem/include/mem.h | 2 -- testcases/kernel/mem/lib/mem.c | 13 ------------- 4 files changed, 14 insertions(+), 15 deletions(-)
testcases/kernel/mem/hugetlb/lib/hugetlb.c +11 -0
@@ -130,3 +130,14 @@ int do_readback(void *p, size_t size, char *desc) }return 0 ; } + +void update_shm_size (size_t * shm_size) +{ +size_t shmmax; + +SAFE_FILE_SCANF (PATH_SHMMAX ,"%zu" , &shmmax); +if (*shm_size > shmmax) { +tst_res (TINFO ,"Set shm_size to shmmax: %zu" , shmmax); + *shm_size = shmmax; + } +}
testcases/kernel/mem/hugetlb/lib/hugetlb.h +3 -0
@@ -56,4 +56,7 @@ int getipckey(void);int getuserid (char *user);void rm_shm (int shm_id);int do_readback (void *p,size_t size,char *desc); + +void update_shm_size (size_t *shm_size); +#endif /* hugetlb.h */
testcases/kernel/mem/include/mem.h +0 -2
@@ -68,6 +68,4 @@ void write_memcg(void);/* cpuset/memcg - include/tst_cgroup.h */ void write_cpusets (const struct tst_cg_group *cg,long nd); -void update_shm_size (size_t *shm_size); -#endif
testcases/kernel/mem/lib/mem.c +0 -13
@@ -590,16 +590,3 @@ void write_cpusets(const struct tst_cg_group *cg, long nd)SAFE_CG_PRINT (cg,"cpuset.cpus" ,"0" ); } } - -/* shared */ - -void update_shm_size (size_t * shm_size) -{ -size_t shmmax; - -SAFE_FILE_SCANF (PATH_SHMMAX ,"%zu" , &shmmax); -if (*shm_size > shmmax) { -tst_res (TINFO ,"Set shm_size to shmmax: %zu" , shmmax); - *shm_size = shmmax; - } -}
Signature · 5 lines
2.45.2 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 05/13] testcases/kernel/mem: Move update_shm_size()
Hi Cyril,
Quoted 2 lines
Move
update_shm_size()from the lib to thelibhugetlb.csince the function is used only by the hugetlb testcases.
Indeed. And the reason why it's not using .save_restore although it sets data in the setup is that it sets value based on /proc/meminfo "Hugepagesize:" value.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 6/13 testcases/kernel/mem: Move check_hugepage() + PATH_THP
In reply to Cyril HrubisThese were only used in thp testcases, also after this the mem library is no longer needed in thp tests so it's removed from the Makefile.
Also note that PATH_HUGEPAGES is defined in tst_hugepage.h which is included by tst_test.h so we can just remove this macro.
--- testcases/kernel/mem/include/mem.h | 7 ------- testcases/kernel/mem/lib/mem.c | 6 ------ testcases/kernel/mem/thp/Makefile | 2 +- testcases/kernel/mem/thp/thp.h | 17 +++++++++++++++++ testcases/kernel/mem/thp/thp01.c | 1 - testcases/kernel/mem/thp/thp02.c | 3 ++- testcases/kernel/mem/thp/thp03.c | 5 +++-- 7 files changed, 23 insertions(+), 18 deletions(-) create mode 100644 testcases/kernel/mem/thp/thp.h
testcases/kernel/mem/include/mem.h +0 -7
@@ -52,17 +52,10 @@ void test_ksm_merge_across_nodes(unsigned long nr_pages);void ksm_group_check (int run,int pg_shared,int pg_sharing,int pg_volatile,int pg_unshared,int sleep_msecs,int pages_to_scan); -/* THP */ - -#define PATH_THP "/sys/kernel/mm/transparent_hugepage/" -#define PATH_KHPD PATH_THP "khugepaged/" -/* HUGETLB */ -#define PATH_HUGEPAGES "/sys/kernel/mm/hugepages/"#define PATH_SHMMAX "/proc/sys/kernel/shmmax" -void check_hugepage (void );void write_memcg (void );/* cpuset/memcg - include/tst_cgroup.h */
testcases/kernel/mem/lib/mem.c +0 -6
@@ -324,12 +324,6 @@ static void verify(char **memory, char value, int proc,free (s); } -void check_hugepage (void ) -{ -if (access (PATH_HUGEPAGES ,F_OK )) -tst_brk (TCONF ,"Huge page is not supported." ); -} -struct ksm_merge_data {char data;unsigned int mergeable_size;
testcases/kernel/mem/thp/Makefile +1 -1
@@ -3,7 +3,7 @@ top_srcdir ?= ../../../.. thp04: LDLIBS += -lrt +thp04: CFLAGS += -pthread include $(top_srcdir)/include/mk/testcases.mk -include $(top_srcdir)/testcases/kernel/mem/include/libmem.mk include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/mem/thp/thp.h new file +17 -0
@@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) Linux Test Project, 2011-2021 +* Copyright (c) Cyril Hrubis 2024 +*/ +#ifndef THP_H +#define THP_H + +#define PATH_THP "/sys/kernel/mm/transparent_hugepage/" + +static inline void check_hugepage (void ) +{ +if (access (PATH_HUGEPAGES ,F_OK )) +tst_brk (TCONF ,"Huge page is not supported." ); +} + +#endif /* THP_H */
testcases/kernel/mem/thp/thp01.c +0 -1
@@ -38,7 +38,6 @@#include <stdlib.h> #include <unistd.h> #include "tst_test.h" -#include "mem.h" #include "tst_minmax.h" #define ARGS_SZ (256 * 32)
testcases/kernel/mem/thp/thp02.c +2 -1
@@ -38,7 +38,8 @@#include <stdlib.h> #include <string.h> #include <unistd.h> -#include "mem.h" +#include "tst_test.h" +#include "thp.h" static int ps;static long hps, size;
testcases/kernel/mem/thp/thp03.c +3 -2
@@ -36,7 +36,8 @@#include <stdlib.h> #include <string.h> #include <errno.h> -#include "mem.h" +#include "tst_test.h" +#include "thp.h" #include "lapi/mmap.h" static void thp_test (void );
@@ -83,7 +84,7 @@ static void setup(void)check_hugepage (); - hugepage_size =SAFE_READ_MEMINFO ("Hugepagesize:" ) *KB ; + hugepage_size =SAFE_READ_MEMINFO ("Hugepagesize:" ) *TST_KB ; unaligned_size = hugepage_size *4 -1 ; page_size =SAFE_SYSCONF (_SC_PAGESIZE); }
Signature · 5 lines
2.45.2 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 06/13] testcases/kernel/mem: Move check_hugepage() + PATH_THP
Hi Cyril,
testcases/kernel/mem/thp/thp.h line 15
Quoted 7 lines
testcases/kernel/mem/thp/thp.h new file +7
-0+#define PATH_THP "/sys/kernel/mm/transparent_hugepage/" + +static inline void check_hugepage (void ) +{ +if (access (PATH_HUGEPAGES ,F_OK )) +tst_brk (TCONF ,"Huge page is not supported." ); +}
I guess we don't want to move this into static inline function (used only in 2 tests.
if (access(PATH_THP, F_OK) == -1) tst_brk(TCONF, "THP not enabled in kernel?");
I also wonder if we should add to the library struct tst_test test something like .requires_proc_sys which would check for files in /sys or /proc. There could be an optional parameter for TCONF message. Advantage would be to have this in docparse docs (or isn't it useful to see this)?
We have .save_restore, but that's only for files and it reads the value. But it could share the flags (TST_SR_TCONF, TST_SR_TBROK, TST_SR_SKIP, ...).
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 06/13] testcases/kernel/mem: Move check_hugepage() + PATH_THP
Hi!
Quoted 14 lines
testcases/kernel/mem/thp/thp.h line 15
Quoted 7 lines
testcases/kernel/mem/thp/thp.h new file +7
-0+#define PATH_THP "/sys/kernel/mm/transparent_hugepage/" + +static inline void check_hugepage (void ) +{ +if (access (PATH_HUGEPAGES ,F_OK )) +tst_brk (TCONF ,"Huge page is not supported." ); +}I guess we don't want to move this into static inline function (used only in 2 tests.
if (access(PATH_THP, F_OK) == -1) tst_brk(TCONF, "THP not enabled in kernel?");
Quoted 7 lines
I also wonder if we should add to the library struct
tst_testtest something like .requires_proc_sys which would check for files in /sys or /proc. There could be an optional parameter for TCONF message. Advantage would be to have this in docparse docs (or isn't it useful to see this)?We have .save_restore, but that's only for files and it reads the value. But it could share the flags (
TST_SR_TCONF,TST_SR_TBROK,TST_SR_SKIP, ...).
Logically save_restore is not a good candidate since we are checking a directory existence here. So maybe we need to add .needs_paths array of strings into tst_test later on...
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 06/13] testcases/kernel/mem: Move check_hugepage() + PATH_THP
Quoted 20 lines
Hi!
Quoted 18 lines
testcases/kernel/mem/thp/thp.h line 15
Quoted 7 lines
testcases/kernel/mem/thp/thp.h new file +7
-0+#define PATH_THP "/sys/kernel/mm/transparent_hugepage/" + +static inline void check_hugepage (void ) +{ +if (access (PATH_HUGEPAGES ,F_OK )) +tst_brk (TCONF ,"Huge page is not supported." ); +}I guess we don't want to move this into static inline function (used only in 2 tests.
if (access(PATH_THP, F_OK) == -1) tst_brk(TCONF, "THP not enabled in kernel?");I also wonder if we should add to the library struct
tst_testtest something like .requires_proc_sys which would check for files in /sys or /proc. There could be an optional parameter for TCONF message. Advantage would be to have this in docparse docs (or isn't it useful to see this)?
Quoted 6 lines
Quoted 2 lines
We have .save_restore, but that's only for files and it reads the value. But it could share the flags (
TST_SR_TCONF,TST_SR_TBROK,TST_SR_SKIP, ...).Logically
save_restoreis not a good candidate since we are checking a directory existence here. So maybe we need to add .needs_paths array of strings intotst_testlater on...
Yeah. .needs_paths sounds reasonable + use flags we already have (TST_SR_TCONF, TST_SR_TBROK, TST_SR_SKIP).
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 7/13 testcases/kernel/mem: Move NUMA bits to numa_helper.h
In reply to Cyril HrubisTestcases that use these macros and functions include numa_helper.h anyways so there is no point in keeping numa related functions in mem.h.
Note that the unused clear_node() function was removed.
--- testcases/kernel/include/numa_helper.h | 21 +++++++++ testcases/kernel/lib/numa_cpuset.c | 64 ++++++++++++++++++++++++++ testcases/kernel/mem/include/mem.h | 24 ---------- testcases/kernel/mem/ksm/ksm02.c | 2 +- testcases/kernel/mem/ksm/ksm04.c | 2 +- testcases/kernel/mem/lib/mem.c | 57 ----------------------- testcases/kernel/mem/oom/oom04.c | 2 +- testcases/kernel/mem/oom/oom05.c | 2 +- 8 files changed, 89 insertions(+), 85 deletions(-) create mode 100644 testcases/kernel/lib/numa_cpuset.c
testcases/kernel/include/numa_helper.h +21 -0
@@ -27,13 +27,34 @@# include <numaif.h> #endif +struct tst_cg_group ; +#define NH_MEMS (1 << 0)#define NH_CPUS (1 << 1) +#if defined(__powerpc__) || defined(__powerpc64__) +# define MAXNODES 256 +#else +# define MAXNODES 512 +#endif + +#define TESTMEM (1UL<<30) + +#define BITS_PER_LONG (8 * sizeof(long)) + +#define PATH_SYS_SYSTEM "/sys/devices/system" + +static inline void set_node (unsigned long *array,unsigned int node) +{ + array[node /BITS_PER_LONG ] |=1UL << (node %BITS_PER_LONG ); +} +unsigned long get_max_node (void );int get_allowed_nodes_arr (int flag,int *num_nodes,int **nodes);int get_allowed_nodes (int flag,int count, ...);void nh_dump_nodes (void );int is_numa (void (*cleanup_fn)(void ),int flag,int min_nodes); +void write_node_cpusets (const struct tst_cg_group *cg,long nd); +#endif /* NUMA_HELPER_H */
testcases/kernel/lib/numa_cpuset.c new file +64 -0
64 lines not on this page · raw message
testcases/kernel/mem/include/mem.h +0 -24
@@ -9,35 +9,14 @@#include "ksm_helper.h" #include "tst_memutils.h" -#if defined(__powerpc__) || defined(__powerpc64__) -#define MAXNODES 256 -#else -#define MAXNODES 512 -#endif #define MB (1UL<<20)#define KB (1UL<<10) -#define PATH_SYS_SYSTEM "/sys/devices/system"#define PATH_SYSVM "/proc/sys/vm/"#define PATH_MEMINFO "/proc/meminfo" -#define BITS_PER_LONG (8 * sizeof(long)) - -static inline void set_node (unsigned long *array,unsigned int node) -{ - array[node /BITS_PER_LONG ] |=1UL << (node %BITS_PER_LONG ); -} - -static inline void clean_node (unsigned long *array) -{ -unsigned int i; - -for (i =0 ; i <MAXNODES /BITS_PER_LONG ; i++) - array[i] &=0UL ; -}/* OOM */ #define LENGTH (3UL<<30) -#define TESTMEM (1UL<<30)#define NORMAL 1#define MLOCK 2#define KSM 3
@@ -58,7 +37,4 @@ void ksm_group_check(int run, int pg_shared, int pg_sharing, int pg_volatile,void write_memcg (void ); -/* cpuset/memcg - include/tst_cgroup.h */ -void write_cpusets (const struct tst_cg_group *cg,long nd); -#endif
testcases/kernel/mem/ksm/ksm02.c +1 -1
@@ -76,7 +76,7 @@ static void verify_ksm(void) }create_same_memory (size, num, unit); -write_cpusets (tst_cg, node); +write_node_cpusets (tst_cg, node);SAFE_CG_PRINTF (tst_cg,"cgroup.procs" ,"%d" ,getpid ());create_same_memory (size, num, unit);SAFE_CG_PRINTF (tst_cg_drain,"cgroup.procs" ,"%d" ,getpid ());
testcases/kernel/mem/ksm/ksm04.c +1 -1
@@ -63,7 +63,7 @@ static void verify_ksm(void) }create_same_memory (size, num, unit); -write_cpusets (tst_cg, node); +write_node_cpusets (tst_cg, node);create_same_memory (size, num, unit); }
testcases/kernel/mem/lib/mem.c +0 -57
60 lines not on this page · raw message
testcases/kernel/mem/oom/oom04.c +1 -1
@@ -60,7 +60,7 @@ static void setup(void)if (ret <0 )tst_brk (TBROK ,"Failed to get a memory node " "using get_allowed_nodes()" ); -write_cpusets (tst_cg, memnode); +write_node_cpusets (tst_cg, memnode);SAFE_CG_PRINTF (tst_cg,"cgroup.procs" ,"%d" ,getpid ()); }
testcases/kernel/mem/oom/oom05.c +1 -1
@@ -80,7 +80,7 @@ void setup(void)tst_brk (TBROK ,"Failed to get a memory node " "using get_allowed_nodes()" ); -write_cpusets (tst_cg, memnode); +write_node_cpusets (tst_cg, memnode);SAFE_CG_PRINTF (tst_cg,"cgroup.procs" ,"%d" ,getpid ());SAFE_CG_PRINTF (tst_cg,"memory.max" ,"%lu" ,TESTMEM ); }
Signature · 5 lines
2.45.2 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 07/13] testcases/kernel/mem: Move NUMA bits to numa_helper.h
Hi Cyril,
...
testcases/kernel/lib/numa_cpuset.c
Quoted 5 lines
testcases/kernel/include/numa_helper.h +2
-0+void write_node_cpusets (const struct tst_cg_group *cg,long nd); +#endif /* NUMA_HELPER_H */ testcases/kernel/lib/numa_cpuset.c new file +0
-0
I was thinking whether creating new file with just 2 functions is a good idea (it could be in numa_helper.c), but I understand you want to point out that functions works with CPU, thus OK with me.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 07/13] testcases/kernel/mem: Move NUMA bits to numa_helper.h
In reply to Cyril HrubisHi Cyril,
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 8/13 testcases/kernel/mem: Move oom() fucntions to oom tests
In reply to Cyril HrubisFunctions that are used only by the oom testcases are moved into oom/oom.h.
--- testcases/kernel/mem/include/mem.h | 10 -- testcases/kernel/mem/lib/mem.c | 212 -------------------------- testcases/kernel/mem/oom/Makefile | 7 +- testcases/kernel/mem/oom/oom.h | 231 +++++++++++++++++++++++++++++ testcases/kernel/mem/oom/oom01.c | 3 +- testcases/kernel/mem/oom/oom02.c | 5 +- testcases/kernel/mem/oom/oom03.c | 11 +- testcases/kernel/mem/oom/oom04.c | 5 +- testcases/kernel/mem/oom/oom05.c | 9 +- 9 files changed, 256 insertions(+), 237 deletions(-) create mode 100644 testcases/kernel/mem/oom/oom.h
testcases/kernel/mem/include/mem.h +0 -10
@@ -14,16 +14,6 @@#define PATH_SYSVM "/proc/sys/vm/"#define PATH_MEMINFO "/proc/meminfo" -/* OOM */ - -#define LENGTH (3UL<<30) -#define NORMAL 1 -#define MLOCK 2 -#define KSM 3 - -void oom (int testcase,int lite,int retcode,int allow_sigkill); -void testoom (int mempolicy,int lite,int retcode,int allow_sigkill); -/* KSM */ void create_same_memory (int size,int num,int unit);
testcases/kernel/mem/lib/mem.c +0 -212
218 lines not on this page · raw message
testcases/kernel/mem/oom/Makefile +6 -1
@@ -19,5 +19,10 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk -include $(top_srcdir)/testcases/kernel/mem/include/libmem.mk + +include $(top_srcdir)/testcases/kernel/include/lib.mk + +CFLAGS+=-pthread +LDFLAGS+=-pthread + include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/mem/oom/oom.h new file +231 -0
231 lines not on this page · raw message
testcases/kernel/mem/oom/oom01.c +2 -1
@@ -16,7 +16,8 @@#include <stdio.h> #include <stdlib.h> #include <unistd.h> -#include "mem.h" +#include "tst_test.h" +#include "oom.h" #define OVERCOMMIT_MEMORY "/proc/sys/vm/overcommit_memory"
testcases/kernel/mem/oom/oom02.c +3 -2
@@ -16,11 +16,12 @@#include <fcntl.h> #include <stdio.h> #if HAVE_NUMA_H -#include <numa.h> +# include <numa.h> #endif +#include "tst_test.h" #include "numa_helper.h" -#include "mem.h" +#include "oom.h" #ifdef HAVE_NUMA_V2
testcases/kernel/mem/oom/oom03.c +6 -5
@@ -16,11 +16,12 @@#include <fcntl.h> #include <stdio.h> #if HAVE_NUMA_H -#include <numa.h> +# include <numa.h> #endif +#include "tst_test.h" #include "numa_helper.h" -#include "mem.h" +#include "oom.h" #ifdef HAVE_NUMA_V2
@@ -38,12 +39,12 @@ static void verify_oom(void)* * To get more opportunities to reach the swap limitation, * let's scale down the value of 'memory.swap.max' to only -* 1MB for CGroup v2. +* 1TST_MB for CGroup v2. */ if (!TST_CG_VER_IS_V1 (tst_cg,"memory" )) -SAFE_CG_PRINTF (tst_cg,"memory.swap.max" ,"%lu" ,MB ); +SAFE_CG_PRINTF (tst_cg,"memory.swap.max" ,"%lu" ,TST_MB );else -SAFE_CG_PRINTF (tst_cg,"memory.swap.max" ,"%lu" ,TESTMEM +MB ); +SAFE_CG_PRINTF (tst_cg,"memory.swap.max" ,"%lu" ,TESTMEM +TST_MB );testoom (0 ,1 ,ENOMEM ,1 );
testcases/kernel/mem/oom/oom04.c +3 -2
@@ -16,11 +16,12 @@#include <fcntl.h> #include <stdio.h> #if HAVE_NUMA_H -#include <numa.h> +# include <numa.h> #endif +#include "tst_test.h" #include "numa_helper.h" -#include "mem.h" +#include "oom.h" #ifdef HAVE_NUMA_V2
testcases/kernel/mem/oom/oom05.c +5 -4
@@ -16,11 +16,12 @@#include <fcntl.h> #include <stdio.h> #if HAVE_NUMA_H -#include <numa.h> +# include <numa.h> #endif +#include "tst_test.h" #include "numa_helper.h" -#include "mem.h" +#include "oom.h" #ifdef HAVE_NUMA_V2
@@ -46,9 +47,9 @@ static void verify_oom(void)tst_res (TINFO ,"OOM on CPUSET & MEMCG with " "special memswap limitation:" );if (!TST_CG_VER_IS_V1 (tst_cg,"memory" )) -SAFE_CG_PRINTF (tst_cg,"memory.swap.max" ,"%lu" ,MB ); +SAFE_CG_PRINTF (tst_cg,"memory.swap.max" ,"%lu" ,TST_MB );else -SAFE_CG_PRINTF (tst_cg,"memory.swap.max" ,"%lu" ,TESTMEM +MB ); +SAFE_CG_PRINTF (tst_cg,"memory.swap.max" ,"%lu" ,TESTMEM +TST_MB );testoom (0 ,1 ,ENOMEM ,1 );
Signature · 5 lines
2.45.2 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 08/13] testcases/kernel/mem: Move oom() fucntions to oom tests
Hi Cyril,
Quoted 2 lines
Functions that are used only by the oom testcases are moved into
oom/oom.h.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 9/13 testcases/kernel/mem: Move KSM bits to ksm tests
In reply to Cyril HrubisMoves the ksm helpers into a ksm/ksm_test.h since these are not used by any other but ksm tests.
--- testcases/kernel/mem/include/mem.h | 5 - testcases/kernel/mem/ksm/Makefile | 2 +- testcases/kernel/mem/ksm/ksm01.c | 2 +- testcases/kernel/mem/ksm/ksm02.c | 2 +- testcases/kernel/mem/ksm/ksm03.c | 2 +- testcases/kernel/mem/ksm/ksm04.c | 2 +- testcases/kernel/mem/ksm/ksm05.c | 2 +- testcases/kernel/mem/ksm/ksm06.c | 4 +- testcases/kernel/mem/ksm/ksm07.c | 3 +- testcases/kernel/mem/ksm/ksm_common.h | 3 +- testcases/kernel/mem/ksm/ksm_test.h | 299 ++++++++++++++++++++++++++ testcases/kernel/mem/lib/mem.c | 287 ------------------------ 12 files changed, 312 insertions(+), 301 deletions(-) create mode 100644 testcases/kernel/mem/ksm/ksm_test.h
testcases/kernel/mem/include/mem.h +0 -5
@@ -16,11 +16,6 @@/* KSM */ -void create_same_memory (int size,int num,int unit); -void test_ksm_merge_across_nodes (unsigned long nr_pages); -void ksm_group_check (int run,int pg_shared,int pg_sharing,int pg_volatile, -int pg_unshared,int sleep_msecs,int pages_to_scan); -/* HUGETLB */ #define PATH_SHMMAX "/proc/sys/kernel/shmmax"
testcases/kernel/mem/ksm/Makefile +1 -1
@@ -7,5 +7,5 @@ LTPLIBS = numa ksm06: LTPLDLIBS = -lltpnuma include $(top_srcdir)/include/mk/testcases.mk -include $(top_srcdir)/testcases/kernel/mem/include/libmem.mk +include $(top_srcdir)/testcases/kernel/include/lib.mk include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/mem/ksm/ksm01.c +1 -1
@@ -56,7 +56,7 @@#include <stdlib.h> #include <string.h> #include <unistd.h> -#include "mem.h" +#include "tst_test.h" #include "ksm_common.h" static void verify_ksm (void )
testcases/kernel/mem/ksm/ksm02.c +1 -1
@@ -53,7 +53,7 @@#include <signal.h> #include <stdio.h> #include <unistd.h> -#include "mem.h" +#include "tst_test.h" #include "ksm_common.h" #ifdef HAVE_NUMA_V2
testcases/kernel/mem/ksm/ksm03.c +1 -1
@@ -56,7 +56,7 @@#include <stdlib.h> #include <string.h> #include <unistd.h> -#include "mem.h" +#include "tst_test.h" #include "ksm_common.h" static void verify_ksm (void )
testcases/kernel/mem/ksm/ksm04.c +1 -1
@@ -38,7 +38,7 @@#include <signal.h> #include <stdio.h> #include <unistd.h> -#include "mem.h" +#include "tst_test.h" #include "ksm_common.h" #ifdef HAVE_NUMA_V2
testcases/kernel/mem/ksm/ksm05.c +1 -1
@@ -39,7 +39,7 @@#include <stdlib.h> #include <errno.h> #include "tst_test.h" -#include "mem.h" +#include "ksm_helper.h" #ifdef HAVE_DECL_MADV_MERGEABLE
testcases/kernel/mem/ksm/ksm06.c +3 -1
@@ -33,8 +33,10 @@#include <unistd.h> #include <limits.h> -#include "mem.h" +#include "tst_test.h" #include "tst_numa.h" +#include "ksm_helper.h" +#include "ksm_test.h" #ifdef HAVE_NUMA_V2 # include <numa.h>
testcases/kernel/mem/ksm/ksm07.c +2 -1
@@ -23,7 +23,8 @@*/ #include <sys/wait.h> -#include "mem.h" +#include "tst_test.h" +#include "ksm_helper.h" /* This test allocates one page, fills the page with a's, captures the * full_scan and pages_skipped counters. Then it makes sure at least 3
testcases/kernel/mem/ksm/ksm_common.h +2 -1
@@ -11,7 +11,9 @@#define KSM_COMMON_H__ #include "tst_test.h" +#include "ksm_helper.h" #include "numa_helper.h" +#include "ksm_test.h" #define DEFAULT_MEMSIZE 128
@@ -67,5 +69,4 @@ static inline unsigned int get_a_numa_node(void) abort(); } -#endif /* KSM_COMMON_H__ */
testcases/kernel/mem/ksm/ksm_test.h new file +299 -0
299 lines not on this page · raw message
testcases/kernel/mem/lib/mem.c +0 -287
290 lines not on this page · raw message
Signature · 5 lines
2.45.2 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 09/13] testcases/kernel/mem: Move KSM bits to ksm tests
Quoted 4 lines · Cyril Hrubis
Moves the ksm helpers into a
ksm/ksm_test.hsince these are not used by any other but ksm tests.Signed-off-by Cyril Hrubis <[email protected]>
Quoted 13 lines
--- testcases/kernel/mem/include/mem.h | 5 - testcases/kernel/mem/ksm/Makefile | 2 +- testcases/kernel/mem/ksm/ksm01.c | 2 +- testcases/kernel/mem/ksm/ksm02.c | 2 +- testcases/kernel/mem/ksm/ksm03.c | 2 +- testcases/kernel/mem/ksm/ksm04.c | 2 +- testcases/kernel/mem/ksm/ksm05.c | 2 +- testcases/kernel/mem/ksm/ksm06.c | 4 +- testcases/kernel/mem/ksm/ksm07.c | 3 +- testcases/kernel/mem/ksm/ksm_common.h | 3 +- testcases/kernel/mem/ksm/ksm_test.h | 299 ++++++++++++++++++++++++++
We do have another tst_helper.h under testcases/kernel/include/, maybe we can combine it with ksm_test.h together?
Quoted 801 lines
testcases/kernel/mem/lib/mem.c | 287 ------------------------ 12 files changed, 312 insertions(+), 301 deletions(-) create mode 100644 testcases/kernel/mem/ksm/ksm_test.htestcases/kernel/mem/include/mem.h +0
-5@@ -16,11 +16,6 @@/* KSM */ -void create_same_memory (int size,int num,int unit); -void test_ksm_merge_across_nodes (unsigned long nr_pages); -void ksm_group_check (int run,int pg_shared,int pg_sharing,int pg_volatile, -int pg_unshared,int sleep_msecs,int pages_to_scan); -/* HUGETLB */ #define
PATH_SHMMAX"/proc/sys/kernel/shmmax"testcases/kernel/mem/ksm/Makefile +1
-1@@ -7,5 +7,5 @@ LTPLIBS = numa ksm06: LTPLDLIBS = -lltpnuma include $(top_srcdir)/include/mk/testcases.mk -include $(top_srcdir)/testcases/kernel/mem/include/libmem.mk +include $(top_srcdir)/testcases/kernel/include/lib.mk include $(top_srcdir)/include/mk/generic_leaf_target.mktestcases/kernel/mem/ksm/ksm01.c +1
-1@@ -56,7 +56,7 @@#include <stdlib.h> #include <string.h> #include <unistd.h> -#include "mem.h" +#include "tst_test.h" #include "ksm_common.h" static void verify_ksm (void )testcases/kernel/mem/ksm/ksm02.c +1
-1@@ -53,7 +53,7 @@#include <signal.h> #include <stdio.h> #include <unistd.h> -#include "mem.h" +#include "tst_test.h" #include "ksm_common.h" #ifdef HAVE_NUMA_V2 testcases/kernel/mem/ksm/ksm03.c +1
-1@@ -56,7 +56,7 @@#include <stdlib.h> #include <string.h> #include <unistd.h> -#include "mem.h" +#include "tst_test.h" #include "ksm_common.h" static void verify_ksm (void )testcases/kernel/mem/ksm/ksm04.c +1
-1@@ -38,7 +38,7 @@#include <signal.h> #include <stdio.h> #include <unistd.h> -#include "mem.h" +#include "tst_test.h" #include "ksm_common.h" #ifdef HAVE_NUMA_V2 testcases/kernel/mem/ksm/ksm05.c +1
-1@@ -39,7 +39,7 @@#include <stdlib.h> #include <errno.h> #include "tst_test.h" -#include "mem.h" +#include "ksm_helper.h" #ifdef HAVE_DECL_MADV_MERGEABLE testcases/kernel/mem/ksm/ksm06.c +3
-1@@ -33,8 +33,10 @@#include <unistd.h> #include <limits.h> -#include "mem.h" +#include "tst_test.h" #include "tst_numa.h" +#include "ksm_helper.h" +#include "ksm_test.h" #ifdef HAVE_NUMA_V2 # include <numa.h> testcases/kernel/mem/ksm/ksm07.c +2
-1@@ -23,7 +23,8 @@*/ #include <sys/wait.h> -#include "mem.h" +#include "tst_test.h" +#include "ksm_helper.h" /* This test allocates one page, fills the page with a's, captures the * full_scan and pages_skipped counters. Then it makes sure at least 3 testcases/kernel/mem/ksm/ksm_common.h +2
-1@@ -11,7 +11,9 @@#define KSM_COMMON_H__ #include "tst_test.h" +#include "ksm_helper.h" #include "numa_helper.h" +#include "ksm_test.h" #define DEFAULT_MEMSIZE 128@@ -67,5 +69,4 @@ static inline unsigned int get_a_numa_node(void) abort(); } -#endif /* KSM_COMMON_H__ */ testcases/kernel/mem/ksm/ksm_test.h new file +26
-0@@ -0,0 +1,299 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) Linux Test Project, 2011-2021 +* Copyright (c) Cyril Hrubis <[email protected]> 2024 +*/ +#ifndef KSM_TEST_ +#define KSM_TEST_ + +#include <sys/wait.h> + +static inline void check (char *path,long int value) +{ +char fullpath[BUFSIZ ]; +long actual_val; + +snprintf (fullpath,BUFSIZ ,PATH_KSM "%s" , path); +SAFE_FILE_SCANF (fullpath,"%ld" , &actual_val); + +if (actual_val != value) +tst_res (TFAIL ,"%s is not %ld but %ld." , path, value, + actual_val); +else +tst_res (TPASS ,"%s is %ld." , path, actual_val); +} + +static inline void final_group_check(int run, int pages_shared, int
pages_sharing,testcases/kernel/mem/ksm/ksm_test.h new file +31
-0+ int pages_volatile, int pages_unshared, + int sleep_millisecs, int pages_to_scan) +{ + int ksm_run_orig; + +tst_res (TINFO ,"check!" ); +check ("run" , run); + +/* +* Temporarily stop the KSM scan during the checks: during the +* KSM scan the rmap_items in the stale unstable tree of the +* old pass are removed from it and are later reinserted in +* the new unstable tree of the current pass. So if the checks +* run in the race window between removal and re-insertion, it +* can lead to unexpected false positives where page_volatile +* is elevated and page_unshared is recessed. +*/ +SAFE_FILE_SCANF (PATH_KSM "run" ,"%d" , &ksm_run_orig); +SAFE_FILE_PRINTF (PATH_KSM "run" ,"0" ); + +check ("pages_shared" , pages_shared); +check ("pages_sharing" , pages_sharing); +check ("pages_volatile" , pages_volatile); +check ("pages_unshared" , pages_unshared); +check ("sleep_millisecs" , sleep_millisecs); +check ("pages_to_scan" , pages_to_scan); + +SAFE_FILE_PRINTF (PATH_KSM "run" ,"%d" , ksm_run_orig); +} + +static inline void ksm_group_check(int run, int pages_shared, int
pages_sharing,testcases/kernel/mem/ksm/ksm_test.h new file +31
-0+ int pages_volatile, int pages_unshared, + int sleep_millisecs, int pages_to_scan) +{ + if (run != 1) { + tst_res(TFAIL, "group_check run is not 1, %d.", run); + } else { +/* wait for ksm daemon to scan all mergeable pages. */ +wait_ksmd_full_scan (); + } + +final_group_check (run, pages_shared, pages_sharing, + pages_volatile, pages_unshared, + sleep_millisecs, pages_to_scan); +} + +static inline void verify (char **memory,char value,int proc, +int start,int end,int start2,int end2) +{ +int i, j; +void *s =NULL ; + + s =SAFE_MALLOC ((end - start) * (end2 - start2)); + +tst_res (TINFO ,"child %d verifies memory content." , proc); +memset (s, value, (end - start) * (end2 - start2)); +if (memcmp (memory[start], s, (end - start) * (end2 - start2)) + !=0 ) +for (j = start; j < end; j++) +for (i = start2; i < end2; i++) +if (memory[j][i] != value) + tst_res(TFAIL, "child %d has %c at"
testcases/kernel/mem/ksm/ksm_test.h new file +12
-0+"%d,%d,%d." , + proc, memory[j][i], proc, + j, i); +free (s); +} + +struct ksm_merge_data { +char data; +unsigned int mergeable_size; +}; + +static inline void ksm_child_memset(int child_num, int size, int
total_unit,testcases/kernel/mem/ksm/ksm_test.h new file +9
-0+ struct ksm_merge_data ksm_merge_data, char **memory) +{ + int i = 0, j; +int unit = size / total_unit; + +tst_res (TINFO ,"child %d continues..." , child_num); + +if (ksm_merge_data.mergeable_size == size *TST_MB ) { + tst_res(TINFO, "child %d allocates %d TST_MB filled with'%c'",
testcases/kernel/mem/ksm/ksm_test.h new file +4
-0+ child_num, size, ksm_merge_data.data); + + }else { + tst_res(TINFO, "child %d allocates %d TST_MB filled with'%c'"
testcases/kernel/mem/ksm/ksm_test.h new file +29
-0+" except one page with 'e'" , + child_num, size, ksm_merge_data.data); + } + +for (j =0 ; j < total_unit; j++) { +for (i =0 ; (unsigned int )i < unit *TST_MB ; i++) + memory[j][i] = ksm_merge_data.data; + } + +/* if it contains unshared page, then set 'e' char +* at the end of the last page +*/ +if (ksm_merge_data.mergeable_size < size *TST_MB ) + memory[j-1 ][i-1 ] ='e' ; +} + +static inline void create_ksm_child (int child_num,int size,int unit, +struct ksm_merge_data *ksm_merge_data) +{ +int j, total_unit; +char **memory; + +/* The total units in all */ + total_unit = size / unit; + +/* Apply for the space for memory */ + memory =SAFE_MALLOC (total_unit *sizeof (char *)); +for (j =0 ; j < total_unit; j++) { + memory[j] = SAFE_MMAP(NULL, unit * TST_MB,PROT_READ|PROT_WRITE,
testcases/kernel/mem/ksm/ksm_test.h new file +26
-1+ MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); +#ifdef HAVE_DECL_MADV_MERGEABLE +if (madvise (memory[j], unit *TST_MB ,MADV_MERGEABLE ) == -1) + tst_brk(TBROK|TERRNO, "madvise"); +#endif + } + +tst_res (TINFO ,"child %d stops." , child_num); +if (raise (SIGSTOP ) ==-1 ) +tst_brk (TBROK |TERRNO ,"kill" ); +fflush (stdout); + +for (j =0 ; j <4 ; j++) { + +ksm_child_memset (child_num, size, total_unit, + ksm_merge_data[j], memory); + +fflush (stdout); + +tst_res (TINFO ,"child %d stops." , child_num); +if (raise (SIGSTOP ) ==-1 ) +tst_brk (TBROK |TERRNO ,"kill" ); + +if (ksm_merge_data[j].mergeable_size < size *TST_MB ) { + verify(memory, 'e', child_num, total_unit - 1, + total_unit, unit * TST_MB - 1, unit *
TST_MB);testcases/kernel/mem/ksm/ksm_test.h new file +42
-0+verify (memory, ksm_merge_data[j].data, child_num, +0 , total_unit,0 , unit *TST_MB -1 ); + }else { +verify (memory, ksm_merge_data[j].data, child_num, +0 , total_unit,0 , unit *TST_MB ); + } + } + +tst_res (TINFO ,"child %d finished." , child_num); +} + +static inline void stop_ksm_children (int *child,int num) +{ +int k, status; + +tst_res (TINFO ,"wait for all children to stop." ); +for (k =0 ; k < num; k++) { +SAFE_WAITPID (child[k], &status,WUNTRACED ); +if (!WIFSTOPPED (status)) +tst_brk (TBROK ,"child %d was not stopped" , k); + } +} + +static inline void resume_ksm_children (int *child,int num) +{ +int k; + +tst_res (TINFO ,"resume all children." ); +for (k =0 ; k < num; k++) +SAFE_KILL (child[k],SIGCONT ); + +fflush (stdout); +} + +static inline void create_same_memory (int size,int num,int unit) +{ +int i, j, status, *child; +unsigned long ps, pages; +struct ksm_merge_data **ksm_data; + +struct ksm_merge_data ksm_data0[] = { + {'c', size*TST_MB}, {'c', size*TST_MB}, {'d', size*TST_MB},{'d', size*TST_MB},
testcases/kernel/mem/ksm/ksm_test.h new file +3
-0+ }; +struct ksm_merge_data ksm_data1[] = { + {'a' , size*TST_MB }, {'b' , size*TST_MB }, {'d' , size*TST_MB },{'d', size*TST_MB-1},
testcases/kernel/mem/ksm/ksm_test.h new file +3
-0+ }; +struct ksm_merge_data ksm_data2[] = { + {'a' , size*TST_MB }, {'a' , size*TST_MB }, {'d' , size*TST_MB },{'d', size*TST_MB},
testcases/kernel/mem/ksm/ksm_test.h new file +7
-0+ }; + + ps =sysconf (_SC_PAGE_SIZE); + pages =TST_MB / ps; + + ksm_data =malloc ((num -3 ) *sizeof (struct ksm_merge_data *)); +/* Since from third child, the data is same with the first child's */
testcases/kernel/mem/ksm/ksm_test.h new file +26
-0+for (i =0 ; i < num -3 ; i++) { + ksm_data[i] =malloc (4 *sizeof (struct ksm_merge_data )); +for (j =0 ; j <4 ; j++) { + ksm_data[i][j].data = ksm_data0[j].data; + ksm_data[i][j].mergeable_size = + ksm_data0[j].mergeable_size; + } + } + + child =SAFE_MALLOC (num *sizeof (int )); + +for (i =0 ; i < num; i++) { +fflush (stdout); +switch (child[i] =SAFE_FORK ()) { +case 0 : +if (i ==0 ) { +create_ksm_child (i, size, unit, ksm_data0); +exit (0 ); + }else if (i ==1 ) { +create_ksm_child (i, size, unit, ksm_data1); +exit (0 ); + }else if (i ==2 ) { +create_ksm_child (i, size, unit, ksm_data2); +exit (0 ); + }else { + create_ksm_child(i, size, unit,ksm_data[i-3]);
testcases/kernel/mem/ksm/ksm_test.h new file +11
-0+exit (0 ); + } + } + } + +stop_ksm_children (child, num); + +tst_res (TINFO ,"KSM merging..." ); +if (access (PATH_KSM "max_page_sharing" ,F_OK ) ==0 ) { +SAFE_FILE_PRINTF (PATH_KSM "run" ,"2" ); + SAFE_FILE_PRINTF(PATH_KSM "max_page_sharing", "%ld", size* pages * num);
testcases/kernel/mem/ksm/ksm_test.h new file +4
-0+ } + +SAFE_FILE_PRINTF (PATH_KSM "run" ,"1" ); + SAFE_FILE_PRINTF(PATH_KSM "pages_to_scan", "%ld", size * pages *num);
testcases/kernel/mem/ksm/ksm_test.h new file +5
-0+SAFE_FILE_PRINTF (PATH_KSM "sleep_millisecs" ,"0" ); + +resume_ksm_children (child, num); +stop_ksm_children (child, num); + ksm_group_check(1, 2, size * num * pages - 2, 0, 0, 0, size *pages * num);
testcases/kernel/mem/ksm/ksm_test.h new file +4
-0+ +resume_ksm_children (child, num); +stop_ksm_children (child, num); + ksm_group_check(1, 3, size * num * pages - 3, 0, 0, 0, size *pages * num);
testcases/kernel/mem/ksm/ksm_test.h new file +4
-0+ +resume_ksm_children (child, num); +stop_ksm_children (child, num); + ksm_group_check(1, 1, size * num * pages - 1, 0, 0, 0, size *pages * num);
testcases/kernel/mem/ksm/ksm_test.h new file +4
-0+ +resume_ksm_children (child, num); +stop_ksm_children (child, num); + ksm_group_check(1, 1, size * num * pages - 2, 0, 1, 0, size *pages * num);
testcases/kernel/mem/ksm/ksm_test.h new file +18
-0+ +tst_res (TINFO ,"KSM unmerging..." ); +SAFE_FILE_PRINTF (PATH_KSM "run" ,"2" ); + +resume_ksm_children (child, num); +final_group_check (2 ,0 ,0 ,0 ,0 ,0 , size * pages * num); + +tst_res (TINFO ,"stop KSM." ); +SAFE_FILE_PRINTF (PATH_KSM "run" ,"0" ); +final_group_check (0 ,0 ,0 ,0 ,0 ,0 , size * pages * num); + +while (waitpid (-1 , &status,0 ) >0 ) +if (WEXITSTATUS (status) !=0 ) +tst_res (TFAIL ,"child exit status is %d" , + WEXITSTATUS(status)); +} + +#endif /* KSM_TEST_ */ testcases/kernel/mem/lib/mem.c +0
-16@@ -28,290 +28,3 @@/* KSM */ -static void check (char *path,long int value) -{ -char fullpath[BUFSIZ ]; -long actual_val; - -snprintf (fullpath,BUFSIZ ,PATH_KSM "%s" , path); -SAFE_FILE_SCANF (fullpath,"%ld" , &actual_val); - -if (actual_val != value) -tst_res (TFAIL ,"%s is not %ld but %ld." , path, value, - actual_val); -else -tst_res (TPASS ,"%s is %ld." , path, actual_val); -} - -static void final_group_check(int run, int pages_shared, int
pages_sharing,testcases/kernel/mem/lib/mem.c +0
-62- int pages_volatile, int pages_unshared, - int sleep_millisecs, int pages_to_scan) -{ - int ksm_run_orig; - -tst_res (TINFO ,"check!" ); -check ("run" , run); - -/* -* Temporarily stop the KSM scan during the checks: during the -* KSM scan the rmap_items in the stale unstable tree of the -* old pass are removed from it and are later reinserted in -* the new unstable tree of the current pass. So if the checks -* run in the race window between removal and re-insertion, it -* can lead to unexpected false positives where page_volatile -* is elevated and page_unshared is recessed. -*/ -SAFE_FILE_SCANF (PATH_KSM "run" ,"%d" , &ksm_run_orig); -SAFE_FILE_PRINTF (PATH_KSM "run" ,"0" ); - -check ("pages_shared" , pages_shared); -check ("pages_sharing" , pages_sharing); -check ("pages_volatile" , pages_volatile); -check ("pages_unshared" , pages_unshared); -check ("sleep_millisecs" , sleep_millisecs); -check ("pages_to_scan" , pages_to_scan); - -SAFE_FILE_PRINTF (PATH_KSM "run" ,"%d" , ksm_run_orig); -} - -void ksm_group_check (int run,int pages_shared,int pages_sharing, -int pages_volatile,int pages_unshared, -int sleep_millisecs,int pages_to_scan) -{ -if (run !=1 ) { -tst_res (TFAIL ,"group_check run is not 1, %d." , run); - }else { -/* wait for ksm daemon to scan all mergeable pages. */ -wait_ksmd_full_scan (); - } - -final_group_check (run, pages_shared, pages_sharing, - pages_volatile, pages_unshared, - sleep_millisecs, pages_to_scan); -} - -static void verify (char **memory,char value,int proc, -int start,int end,int start2,int end2) -{ -int i, j; -void *s =NULL ; - - s =SAFE_MALLOC ((end - start) * (end2 - start2)); - -tst_res (TINFO ,"child %d verifies memory content." , proc); -memset (s, value, (end - start) * (end2 - start2)); -if (memcmp (memory[start], s, (end - start) * (end2 - start2)) - !=0 ) -for (j = start; j < end; j++) -for (i = start2; i < end2; i++) -if (memory[j][i] != value) - tst_res(TFAIL, "child %d has %c at"
testcases/kernel/mem/lib/mem.c +0
-54-"%d,%d,%d." , - proc, memory[j][i], proc, - j, i); -free (s); -} - -struct ksm_merge_data { -char data; -unsigned int mergeable_size; -}; - -static void ksm_child_memset (int child_num,int size,int total_unit, -struct ksm_merge_data ksm_merge_data,char **memory) -{ -int i =0 , j; -int unit = size / total_unit; - -tst_res (TINFO ,"child %d continues..." , child_num); - -if (ksm_merge_data.mergeable_size == size *MB ) { -tst_res (TINFO ,"child %d allocates %d MB filled with '%c'" , - child_num, size, ksm_merge_data.data); - - }else { -tst_res (TINFO ,"child %d allocates %d MB filled with '%c'" -" except one page with 'e'" , - child_num, size, ksm_merge_data.data); - } - -for (j =0 ; j < total_unit; j++) { -for (i =0 ; (unsigned int )i < unit *MB ; i++) - memory[j][i] = ksm_merge_data.data; - } - -/* if it contains unshared page, then set 'e' char -* at the end of the last page -*/ -if (ksm_merge_data.mergeable_size < size *MB ) - memory[j-1 ][i-1 ] ='e' ; -} - -static void create_ksm_child (int child_num,int size,int unit, -struct ksm_merge_data *ksm_merge_data) -{ -int j, total_unit; -char **memory; - -/* The total units in all */ - total_unit = size / unit; - -/* Apply for the space for memory */ - memory =SAFE_MALLOC (total_unit *sizeof (char *)); -for (j =0 ; j < total_unit; j++) { - memory[j] = SAFE_MMAP(NULL, unit * MB,PROT_READ|PROT_WRITE,
testcases/kernel/mem/lib/mem.c +0
-68- MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); -#ifdef HAVE_DECL_MADV_MERGEABLE -if (madvise (memory[j], unit *MB ,MADV_MERGEABLE ) ==-1 ) -tst_brk (TBROK |TERRNO ,"madvise" ); -#endif - } - -tst_res (TINFO ,"child %d stops." , child_num); -if (raise (SIGSTOP ) ==-1 ) -tst_brk (TBROK |TERRNO ,"kill" ); -fflush (stdout); - -for (j =0 ; j <4 ; j++) { - -ksm_child_memset (child_num, size, total_unit, - ksm_merge_data[j], memory); - -fflush (stdout); - -tst_res (TINFO ,"child %d stops." , child_num); -if (raise (SIGSTOP ) ==-1 ) -tst_brk (TBROK |TERRNO ,"kill" ); - -if (ksm_merge_data[j].mergeable_size < size *MB ) { -verify (memory,'e' , child_num, total_unit -1 , - total_unit, unit *MB -1 , unit *MB ); -verify (memory, ksm_merge_data[j].data, child_num, -0 , total_unit,0 , unit *MB -1 ); - }else { -verify (memory, ksm_merge_data[j].data, child_num, -0 , total_unit,0 , unit *MB ); - } - } - -tst_res (TINFO ,"child %d finished." , child_num); -} - -static void stop_ksm_children (int *child,int num) -{ -int k, status; - -tst_res (TINFO ,"wait for all children to stop." ); -for (k =0 ; k < num; k++) { -SAFE_WAITPID (child[k], &status,WUNTRACED ); -if (!WIFSTOPPED (status)) -tst_brk (TBROK ,"child %d was not stopped" , k); - } -} - -static void resume_ksm_children (int *child,int num) -{ -int k; - -tst_res (TINFO ,"resume all children." ); -for (k =0 ; k < num; k++) -SAFE_KILL (child[k],SIGCONT ); - -fflush (stdout); -} - -void create_same_memory (int size,int num,int unit) -{ -int i, j, status, *child; -unsigned long ps, pages; -struct ksm_merge_data **ksm_data; - -struct ksm_merge_data ksm_data0[] = { - {'c' , size*MB }, {'c' , size*MB }, {'d' , size*MB }, {'d' ,size*MB},
testcases/kernel/mem/lib/mem.c +0
-3- }; -struct ksm_merge_data ksm_data1[] = { - {'a' , size*MB }, {'b' , size*MB }, {'d' , size*MB }, {'d' ,size*MB-1},
testcases/kernel/mem/lib/mem.c +0
-3- }; -struct ksm_merge_data ksm_data2[] = { - {'a' , size*MB }, {'a' , size*MB }, {'d' , size*MB }, {'d' ,size*MB},
testcases/kernel/mem/lib/mem.c +0
-7- }; - - ps =sysconf (_SC_PAGE_SIZE); - pages =MB / ps; - - ksm_data =malloc ((num -3 ) *sizeof (struct ksm_merge_data *)); -/* Since from third child, the data is same with the first child's */
testcases/kernel/mem/lib/mem.c +0
-26-for (i =0 ; i < num -3 ; i++) { - ksm_data[i] =malloc (4 *sizeof (struct ksm_merge_data )); -for (j =0 ; j <4 ; j++) { - ksm_data[i][j].data = ksm_data0[j].data; - ksm_data[i][j].mergeable_size = - ksm_data0[j].mergeable_size; - } - } - - child =SAFE_MALLOC (num *sizeof (int )); - -for (i =0 ; i < num; i++) { -fflush (stdout); -switch (child[i] =SAFE_FORK ()) { -case 0 : -if (i ==0 ) { -create_ksm_child (i, size, unit, ksm_data0); -exit (0 ); - }else if (i ==1 ) { -create_ksm_child (i, size, unit, ksm_data1); -exit (0 ); - }else if (i ==2 ) { -create_ksm_child (i, size, unit, ksm_data2); -exit (0 ); - }else { - create_ksm_child(i, size, unit,ksm_data[i-3]);
testcases/kernel/mem/lib/mem.c +0
-11-exit (0 ); - } - } - } - -stop_ksm_children (child, num); - -tst_res (TINFO ,"KSM merging..." ); -if (access (PATH_KSM "max_page_sharing" ,F_OK ) ==0 ) { -SAFE_FILE_PRINTF (PATH_KSM "run" ,"2" ); - SAFE_FILE_PRINTF(PATH_KSM "max_page_sharing", "%ld", size* pages * num);
testcases/kernel/mem/lib/mem.c +0
-4- } - -SAFE_FILE_PRINTF (PATH_KSM "run" ,"1" ); - SAFE_FILE_PRINTF(PATH_KSM "pages_to_scan", "%ld", size * pages *num);
testcases/kernel/mem/lib/mem.c +0
-5-SAFE_FILE_PRINTF (PATH_KSM "sleep_millisecs" ,"0" ); - -resume_ksm_children (child, num); -stop_ksm_children (child, num); - ksm_group_check(1, 2, size * num * pages - 2, 0, 0, 0, size *pages * num);
testcases/kernel/mem/lib/mem.c +0
-4- -resume_ksm_children (child, num); -stop_ksm_children (child, num); - ksm_group_check(1, 3, size * num * pages - 3, 0, 0, 0, size *pages * num);
testcases/kernel/mem/lib/mem.c +0
-4- -resume_ksm_children (child, num); -stop_ksm_children (child, num); - ksm_group_check(1, 1, size * num * pages - 1, 0, 0, 0, size *pages * num);
testcases/kernel/mem/lib/mem.c +0
-4- -resume_ksm_children (child, num); -stop_ksm_children (child, num); - ksm_group_check(1, 1, size * num * pages - 2, 0, 1, 0, size *pages * num);
testcases/kernel/mem/lib/mem.c +0
-17- -tst_res (TINFO ,"KSM unmerging..." ); -SAFE_FILE_PRINTF (PATH_KSM "run" ,"2" ); - -resume_ksm_children (child, num); -final_group_check (2 ,0 ,0 ,0 ,0 ,0 , size * pages * num); - -tst_res (TINFO ,"stop KSM." ); -SAFE_FILE_PRINTF (PATH_KSM "run" ,"0" ); -final_group_check (0 ,0 ,0 ,0 ,0 ,0 , size * pages * num); - -while (waitpid (-1 , &status,0 ) >0 ) -if (WEXITSTATUS (status) !=0 ) -tst_res (TFAIL ,"child exit status is %d" , -WEXITSTATUS (status)); -} --2.45.2
--
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 09/13] testcases/kernel/mem: Move KSM bits to ksm tests
Quoted 6 lines · Li Wang
testcases/kernel/mem/ksm/ksm_test.h | 299 ++++++++++++++++++++++++++Quoted 1 line
We do have another
tst_helper.hunder testcases/kernel/include/, maybe we can combine it withksm_test.htogether?
Sorry for the typo: tst_helper.h ---> ksm_helper.h
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 09/13] testcases/kernel/mem: Move KSM bits to ksm tests
In reply to Li WangHi!
Quoted 2 lines
We do have another
tst_helper.hunder testcases/kernel/include/, maybe we can combine it withksm_test.htogether?
The ksm_test.h are functions used only in ksm testcases, the ksm_helper.h is used in more tests and I plan to make it an library in top level libs/ later on.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 09/13] testcases/kernel/mem: Move KSM bits to ksm tests
Quoted 8 lines · Cyril Hrubis
Hi!
Quoted 2 lines
We do have another
tst_helper.hunder testcases/kernel/include/, maybe we can combine it withksm_test.htogether?The
ksm_test.hare functions used only in ksm testcases, theksm_helper.his used in more tests and I plan to make it an library in top level libs/ later on.
Sounds good. Thanks.
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 09/13] testcases/kernel/mem: Move KSM bits to ksm tests
In reply to Cyril HrubisHi Cyril,
Quoted 10 lines
testcases/kernel/mem/ksm/ksm_test.h new file +7
-0@@ -0,0 +1,299 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) Linux Test Project, 2011-2021 +* Copyright (c) Cyril Hrubis <[email protected]> 2024 +*/ +#ifndef KSM_TEST_ +#define KSM_TEST_
testcases/kernel/mem/ksm/ksm_test.h line 17
Quoted 10 lines
testcases/kernel/mem/ksm/ksm_test.h new file +10
-0+ +#include <sys/wait.h> + +static inline void check (char *path,long int value) +{ +char fullpath[BUFSIZ ]; +long actual_val; + +snprintf (fullpath,BUFSIZ ,PATH_KSM "%s" , path); +SAFE_FILE_SCANF (fullpath,"%ld" , &actual_val);
FYI there is an old warning (not relevant to this change), not sure if it's an false positive or how to fix it:
mem.c: In function ‘write_cpusets’:
mem.c:555:52: warning: ‘/online’ directive output may be truncated writing 7 bytes into a region of size between 1 and 8192 [-Wformat-truncation=]
555 | snprintf(path1, BUFSIZ, "%s/online", path);
| ^~~~~~~
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 09/13] testcases/kernel/mem: Move KSM bits to ksm tests
In reply to Cyril HrubisHi Cyril,
Quoted 4 lines
new file mode 100644
index 000000000..ebce8197ctestcases/kernel/mem/ksm/ksm_test.h new file +0
-0
...
testcases/kernel/mem/ksm/ksm_test.h line 108
Quoted 9 lines
testcases/kernel/mem/ksm/ksm_test.h new file +9
-0+static inline void ksm_child_memset (int child_num,int size,int total_unit, +struct ksm_merge_data ksm_merge_data,char **memory) +{ +int i =0 , j; +int unit = size / total_unit; + +tst_res (TINFO ,"child %d continues..." , child_num); + +if (ksm_merge_data.mergeable_size == size *TST_MB ) {
This introduces new warnings, because the original code used MB which is long.
#define MB (1UL<<20)
Now we use TST_MB, which is plain int.
In file included from ksm_common.h:16,
from ksm04.c:42:
ksm_test.h: In function ‘ksm_child_memset’:
ksm_test.h:108:43: warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare]
108 | if (ksm_merge_data.mergeable_size == size * TST_MB) {
| ^~
ksm_test.h:119:45: warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare]
119 | for (i = 0; (unsigned int)i < unit * TST_MB; i++)
| ^
ksm_test.h:126:43: warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare]
126 | if (ksm_merge_data.mergeable_size < size * TST_MB)
| ^ksm_test.h: In function ‘create_ksm_child’:
ksm_test.h:166:54: warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare]
166 | if (ksm_merge_data[j].mergeable_size < size * TST_MB) {
| ^
It would be nice to add cast before merge.
testcases/kernel/mem/ksm/ksm_test.h line 109
Quoted 1 line
testcases/kernel/mem/ksm/ksm_test.h new file +1
-0+ tst_res(TINFO, "child %d allocates %d TST_MB filled with '%c'",
This should use MB (replace to whole file obviously should exclude strings):
tst_res(TINFO, "child %d allocates %d MB filled with '%c'",
testcases/kernel/mem/ksm/ksm_test.h line 113
Quoted 4 lines
testcases/kernel/mem/ksm/ksm_test.h new file +4
-0+ child_num, size, ksm_merge_data.data); + + }else { + tst_res(TINFO, "child %d allocates %d TST_MB filled with '%c'"
And here as well.
tst_res(TINFO, "child %d allocates %d MB filled with '%c'"
testcases/kernel/mem/ksm/ksm_test.h line 116
Quoted 3 lines
testcases/kernel/mem/ksm/ksm_test.h new file +3
-0+" except one page with 'e'" , + child_num, size, ksm_merge_data.data); + }
Otherwise LGTM.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 09/13] testcases/kernel/mem: Move KSM bits to ksm tests
Hi!
Quoted 22 lines
Quoted 4 lines
new file mode 100644
index 000000000..ebce8197ctestcases/kernel/mem/ksm/ksm_test.h new file +0
-0...
testcases/kernel/mem/ksm/ksm_test.h line 108
Quoted 9 lines
testcases/kernel/mem/ksm/ksm_test.h new file +9
-0+static inline void ksm_child_memset (int child_num,int size,int total_unit, +struct ksm_merge_data ksm_merge_data,char **memory) +{ +int i =0 , j; +int unit = size / total_unit; + +tst_res (TINFO ,"child %d continues..." , child_num); + +if (ksm_merge_data.mergeable_size == size *TST_MB ) {This introduces new warnings, because the original code used MB which is long.
#define MB (1UL<<20)
Now we use
TST_MB, which is plain int.In file included from ksm_common.h:16,
from ksm04.c:42:
Quoted 15 lines
ksm_test.h: In function ‘ksm_child_memset’:
ksm_test.h:108:43: warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare]
108 | if (ksm_merge_data.mergeable_size == size *TST_MB) {
| ^~
ksm_test.h:119:45: warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare]
119 | for (i = 0; (unsigned int)i < unit *TST_MB; i++)
| ^
ksm_test.h:126:43: warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare]
126 | if (ksm_merge_data.mergeable_size < size *TST_MB)
| ^ksm_test.h: In function ‘create_ksm_child’:
ksm_test.h:166:54: warning: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Wsign-compare]
166 | if (ksm_merge_data[j].mergeable_size < size *TST_MB) {
| ^
It would be nice to add cast before merge.
So the size is signed but it was implicitly casted to unsigned by the TST_MB being unsigned. I guess that the best fix here is to make the size and unit unsigned to begin with since these are numbers that should not be negative at all.
Quoted 13 lines
testcases/kernel/mem/ksm/ksm_test.h line 109
Quoted 1 line
testcases/kernel/mem/ksm/ksm_test.h new file +1
-0+ tst_res(TINFO, "child %d allocates %d TST_MB filled with '%c'",This should use MB (replace to whole file obviously should exclude strings):
tst_res(TINFO, "child %d allocates %d MB filled with '%c'",
testcases/kernel/mem/ksm/ksm_test.h line 113
Quoted 4 lines
testcases/kernel/mem/ksm/ksm_test.h new file +4
-0+ child_num, size, ksm_merge_data.data); + + }else { + tst_res(TINFO, "child %d allocates %d TST_MB filled with '%c'"And here as well.
tst_res(TINFO, "child %d allocates %d MB filled with '%c'"
Quoted 3 lines
testcases/kernel/mem/ksm/ksm_test.h line 116
Quoted 3 lines
testcases/kernel/mem/ksm/ksm_test.h new file +3
-0+" except one page with 'e'" , + child_num, size, ksm_merge_data.data); + }
Ah, sorry, that is a result from blindly doing sed s/...
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 09/13] testcases/kernel/mem: Move KSM bits to ksm tests
In reply to Cyril HrubisSignature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 10/13 mem/swapping: Remove mem/lib refrence
In reply to Cyril HrubisThe test does not use the library at all!
--- testcases/kernel/mem/swapping/Makefile | 1 - testcases/kernel/mem/swapping/swapping01.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-)
testcases/kernel/mem/swapping/Makefile +0 -1
@@ -19,5 +19,4 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk -include $(top_srcdir)/testcases/kernel/mem/include/libmem.mk include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/mem/swapping/swapping01.c +1 -1
@@ -40,8 +40,8 @@#include <stdlib.h> #include <string.h> #include <unistd.h> +#include "tst_test.h" #include "tst_safe_stdio.h" -#include "mem.h" /* allow swapping 1 * phy_mem in maximum */ #define COE_DELTA 1
Signature · 5 lines
2.45.2 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 10/13] mem/swapping: Remove mem/lib refrence
Hi Cyril,
Quoted 1 line
The test does not use the library at all!
Interesting, it looks like it has never used it.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 11/13 mem/vma: Remove mem/lib dependency
In reply to Cyril HrubisThe test does just use the testcases/lib/ instead.
--- testcases/kernel/mem/vma/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/mem/vma/Makefile +1 -1
@@ -6,7 +6,7 @@ top_srcdir ?= ../../../.. vma05_vdso: CFLAGS+=-ggdb3 include $(top_srcdir)/include/mk/testcases.mk -include $(top_srcdir)/testcases/kernel/mem/include/libmem.mk +include $(top_srcdir)/testcases/kernel/include/lib.mk INSTALL_TARGETS := vma05.sh
Signature · 5 lines
2.45.2 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 11/13] mem/vma: Remove mem/lib dependency
Hi Cyril,
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 12/13 mem/hugetlb: Remove mem/lib depenency
In reply to Cyril HrubisThe last bit used from the library PATH_SHMMAX macro.
--- testcases/kernel/mem/hugetlb/Makefile.inc | 3 --- testcases/kernel/mem/hugetlb/hugemmap/hugemmap05.c | 1 - testcases/kernel/mem/hugetlb/lib/Makefile | 1 - testcases/kernel/mem/hugetlb/lib/hugetlb.h | 3 ++- 4 files changed, 2 insertions(+), 6 deletions(-)
testcases/kernel/mem/hugetlb/Makefile.inc +0 -3
@@ -33,6 +33,3 @@ CPPFLAGS += -I$(abs_srcdir)/$(LIBIPCDIR) LDFLAGS += -L$(abs_builddir)/$(LIBIPCDIR) LDLIBS += -lhugetlb MAKE_DEPS += $(LIBIPC) - -include $(top_srcdir)/testcases/kernel/mem/include/libmem.mk -# vim: syntax=make
testcases/kernel/mem/hugetlb/hugemmap/hugemmap05.c +0 -1
@@ -34,7 +34,6 @@ static char path_sys_sz_huge[BUFSIZ];#define PATH_PROC_VM "/proc/sys/vm/"#define PATH_PROC_OVER PATH_PROC_VM "nr_overcommit_hugepages"#define PATH_PROC_HUGE PATH_PROC_VM "nr_hugepages" -#define PATH_SHMMAX "/proc/sys/kernel/shmmax"/* Only ia64 requires this */ #ifdef __ia64__
testcases/kernel/mem/hugetlb/lib/Makefile +0 -1
@@ -4,7 +4,6 @@ top_srcdir ?= ../../../../.. include $(top_srcdir)/include/mk/env_pre.mk -include $(top_srcdir)/testcases/kernel/mem/include/libmem.mk INTERNAL_LIB := libhugetlb.a
testcases/kernel/mem/hugetlb/lib/hugetlb.h +2 -1
@@ -17,7 +17,6 @@#include <errno.h> #include <sys/wait.h> #include "tst_test.h" -#include "mem.h" #define PALIGN (p, a) ((void *)LTP_ALIGN((unsigned long)(p), (a)))
@@ -29,6 +28,8 @@#define SHM_HUGETLB 04000/* segment is mapped via hugetlb */ #endif +#define PATH_SHMMAX "/proc/sys/kernel/shmmax" +#ifndef barrier# ifdef mb/* Redefining the mb() */
Signature · 5 lines
2.45.2 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 12/13] mem/hugetlb: Remove mem/lib depenency
Hi Cyril,
Quoted 1 line
The last bit used from the library
PATH_SHMMAXmacro.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 13/13 testcases/kernel/mem: Remove library
In reply to Cyril HrubisNow that the last bits of the library are unused we can remove it safely.
--- testcases/kernel/mem/include/libmem.mk | 43 -------------------------- testcases/kernel/mem/include/mem.h | 25 --------------- testcases/kernel/mem/lib/Makefile | 27 ---------------- testcases/kernel/mem/lib/mem.c | 30 ------------------ 4 files changed, 125 deletions(-) delete mode 100644 testcases/kernel/mem/include/libmem.mk delete mode 100644 testcases/kernel/mem/include/mem.h delete mode 100644 testcases/kernel/mem/lib/Makefile delete mode 100644 testcases/kernel/mem/lib/mem.c
testcases/kernel/mem/include/libmem.mk deleted +0 -43
@@ -1,43 +0,0 @@ -# -# Copyright (C) 2012 Red Hat, Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -# the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# - -MEM_SRCDIR := $(abs_top_srcdir)/testcases/kernel/mem -LIBMEM_SRCDIR := $(MEM_SRCDIR)/lib - -MEM_DIR := $(top_builddir)/testcases/kernel/mem -LIBMEM_DIR := $(MEM_DIR)/lib -LIBMEM := $(LIBMEM_DIR)/libmem.a -FILTER_OUT_DIRS := $(LIBMEM_DIR) -CFLAGS += -I$(MEM_SRCDIR)/include -pthread -LDLIBS += $(NUMA_LIBS) -lmem -lltp -LDFLAGS += -L$(LIBMEM_DIR) - -$(LIBMEM_DIR): - mkdir -p "$@" - -$(LIBMEM): $(LIBMEM_DIR) - $(MAKE) -C $^ -f "$(LIBMEM_SRCDIR)/Makefile" all - -MAKE_DEPS += $(LIBMEM) - -trunk-clean:: | lib-clean - -lib-clean:: $(LIBMEM_DIR) - $(MAKE) -C $^ -f "$(LIBMEM_SRCDIR)/Makefile" clean - -include $(top_srcdir)/testcases/kernel/include/lib.mk
testcases/kernel/mem/include/mem.h deleted +0 -25
@@ -1,25 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* -* Copyright (c) Linux Test Project, 2011-2021 -*/ -#ifndef _MEM_H -#define _MEM_H -#include "config.h" -#include "tst_test.h" -#include "ksm_helper.h" -#include "tst_memutils.h" - -#define MB (1UL<<20) -#define KB (1UL<<10) -#define PATH_SYSVM "/proc/sys/vm/" -#define PATH_MEMINFO "/proc/meminfo" - -/* KSM */ - -/* HUGETLB */ - -#define PATH_SHMMAX "/proc/sys/kernel/shmmax" - -void write_memcg (void ); - -#endif
testcases/kernel/mem/lib/Makefile deleted +0 -27
@@ -1,27 +0,0 @@ -# -# Copyright (C) 2010 Red Hat, Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -# the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# - -top_srcdir ?= ../../../.. - -include $(top_srcdir)/include/mk/env_pre.mk - -CPPFLAGS += -I$(abs_srcdir)/../include -INTERNAL_LIB := libmem.a - -include $(top_srcdir)/testcases/kernel/include/lib.mk -include $(top_srcdir)/include/mk/lib.mk
testcases/kernel/mem/lib/mem.c deleted +0 -30
@@ -1,30 +0,0 @@ -#define TST_NO_DEFAULT_MAIN - -#include "config.h" -#include <sys/types.h> -#include <sys/mman.h> -#include <sys/mount.h> -#include <sys/stat.h> -#include <sys/wait.h> -#include <sys/param.h> -#include <errno.h> -#include <fcntl.h> -#if HAVE_NUMA_H -#include <numa.h> -#endif -#if HAVE_NUMAIF_H -#include <numaif.h> -#endif -#include <pthread.h> -#include <stdarg.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> - -#include "mem.h" -#include "numa_helper.h" - - -/* KSM */ -
Signature · 5 lines
2.45.2 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 13/13] testcases/kernel/mem: Remove library
Hi Cyril,
Quoted 2 lines
Now that the last bits of the library are unused we can remove it safely.
Thanks for whole cleanup.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Cyril,
Quoted 10 lines
This patchset slowly untangles the mess called
kernel/mem/lib/library.The library is split into several places, functions that are used by more than one group of tests are either reimplemented in the top level library or in the case of numa moved into
numa_helperlibrary in testcases/kerne/include/ and testcases/kernel/lib/.The rest of the code is either moved into respective test directories or in the case of unused code removed.
Quoted 8 lines
This is not a coplete cleanup of the mem/ testcases as it mostly just moves code, but it's a nice first step that removes most of the unneeded dependencies and prepares for a possible refactoring later on.
The CI run:
https://github.com/metan-ucw/ltp/actions/runs/12398352035
Thanks for this cleanup and verifying in CI. On a quick look LGTM, I'll have deeper look tomorrow.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp