* [LTP] [PATCH 00/13] Get rid of testcases/kernel/mem/lib library
@ 2024-12-18 18:45 Cyril Hrubis
2024-12-18 18:45 ` [LTP] [PATCH 01/13] lib: tst_sys_conf: Add two functions Cyril Hrubis
` (13 more replies)
0 siblings, 14 replies; 41+ messages in thread
From: Cyril Hrubis @ 2024-12-18 18:45 UTC (permalink / raw)
To: ltp
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
--
2.45.2
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 41+ messages in thread
* [LTP] [PATCH 01/13] lib: tst_sys_conf: Add two functions
2024-12-18 18:45 [LTP] [PATCH 00/13] Get rid of testcases/kernel/mem/lib library Cyril Hrubis
@ 2024-12-18 18:45 ` Cyril Hrubis
2024-12-19 3:10 ` Li Wang
2024-12-27 9:04 ` Petr Vorel
2024-12-18 18:45 ` [LTP] [PATCH 02/13] lib: Replace path_exist() with tst_path_exists() Cyril Hrubis
` (12 subsequent siblings)
13 siblings, 2 replies; 41+ messages in thread
From: Cyril Hrubis @ 2024-12-18 18:45 UTC (permalink / raw)
To: ltp
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.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
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(-)
diff --git a/include/tst_sys_conf.h b/include/tst_sys_conf.h
index 4c85767be..53e8c5ea8 100644
--- a/include/tst_sys_conf.h
+++ b/include/tst_sys_conf.h
@@ -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
diff --git a/lib/tst_sys_conf.c b/lib/tst_sys_conf.c
index c0981dcb1..f962fc124 100644
--- a/lib/tst_sys_conf.c
+++ b/lib/tst_sys_conf.c
@@ -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);
+ }
+
+}
diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
index 8ad745d5b..0d7bbf64f 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
@@ -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)
diff --git a/testcases/kernel/mem/include/mem.h b/testcases/kernel/mem/include/mem.h
index cdc3ca146..865d2c7e8 100644
--- a/testcases/kernel/mem/include/mem.h
+++ b/testcases/kernel/mem/include/mem.h
@@ -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);
diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c
index fbfeef026..3e0f5d1bb 100644
--- a/testcases/kernel/mem/lib/mem.c
+++ b/testcases/kernel/mem/lib/mem.c
@@ -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;
diff --git a/testcases/kernel/mem/oom/oom01.c b/testcases/kernel/mem/oom/oom01.c
index 903785f93..157ca84b6 100644
--- a/testcases/kernel/mem/oom/oom01.c
+++ b/testcases/kernel/mem/oom/oom01.c
@@ -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},
{}
},
};
diff --git a/testcases/kernel/mem/tunable/Makefile b/testcases/kernel/mem/tunable/Makefile
index 80d64bb4a..e0014e683 100644
--- a/testcases/kernel/mem/tunable/Makefile
+++ b/testcases/kernel/mem/tunable/Makefile
@@ -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
diff --git a/testcases/kernel/mem/tunable/max_map_count.c b/testcases/kernel/mem/tunable/max_map_count.c
index f33095473..71a7bbee0 100644
--- a/testcases/kernel/mem/tunable/max_map_count.c
+++ b/testcases/kernel/mem/tunable/max_map_count.c
@@ -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},
{}
},
};
diff --git a/testcases/kernel/mem/tunable/min_free_kbytes.c b/testcases/kernel/mem/tunable/min_free_kbytes.c
index 19da409e8..5274bb3bf 100644
--- a/testcases/kernel/mem/tunable/min_free_kbytes.c
+++ b/testcases/kernel/mem/tunable/min_free_kbytes.c
@@ -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},
{}
},
};
diff --git a/testcases/kernel/mem/tunable/overcommit_memory.c b/testcases/kernel/mem/tunable/overcommit_memory.c
index d055dd18f..b5beebbcd 100644
--- a/testcases/kernel/mem/tunable/overcommit_memory.c
+++ b/testcases/kernel/mem/tunable/overcommit_memory.c
@@ -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
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [LTP] [PATCH 02/13] lib: Replace path_exist() with tst_path_exists()
2024-12-18 18:45 [LTP] [PATCH 00/13] Get rid of testcases/kernel/mem/lib library Cyril Hrubis
2024-12-18 18:45 ` [LTP] [PATCH 01/13] lib: tst_sys_conf: Add two functions Cyril Hrubis
@ 2024-12-18 18:45 ` Cyril Hrubis
2024-12-19 14:31 ` Petr Vorel
2024-12-18 18:45 ` [LTP] [PATCH 03/13] lib: Add tst_mapping_in_range() Cyril Hrubis
` (11 subsequent siblings)
13 siblings, 1 reply; 41+ messages in thread
From: Cyril Hrubis @ 2024-12-18 18:45 UTC (permalink / raw)
To: ltp
Move 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.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
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
diff --git a/include/tst_fs.h b/include/tst_fs.h
index 835f3511c..f6ac6a40d 100644
--- a/include/tst_fs.h
+++ b/include/tst_fs.h
@@ -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
diff --git a/lib/tst_path_exists.c b/lib/tst_path_exists.c
new file mode 100644
index 000000000..333c4b0e5
--- /dev/null
+++ b/lib/tst_path_exists.c
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Linux Test Project, 2011-2021
+ * Copyright (c) Cyril Hrubis <chrubis@suse.cz> 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;
+}
diff --git a/testcases/kernel/mem/cpuset/Makefile b/testcases/kernel/mem/cpuset/Makefile
index 8e41c0223..bac13e02b 100644
--- a/testcases/kernel/mem/cpuset/Makefile
+++ b/testcases/kernel/mem/cpuset/Makefile
@@ -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
diff --git a/testcases/kernel/mem/cpuset/cpuset01.c b/testcases/kernel/mem/cpuset/cpuset01.c
index 956ac30c8..4f4415a18 100644
--- a/testcases/kernel/mem/cpuset/cpuset01.c
+++ b/testcases/kernel/mem/cpuset/cpuset01.c
@@ -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;
diff --git a/testcases/kernel/mem/include/mem.h b/testcases/kernel/mem/include/mem.h
index 865d2c7e8..87528fdd0 100644
--- a/testcases/kernel/mem/include/mem.h
+++ b/testcases/kernel/mem/include/mem.h
@@ -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);
diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c
index 3e0f5d1bb..f293e766e 100644
--- a/testcases/kernel/mem/lib/mem.c
+++ b/testcases/kernel/mem/lib/mem.c
@@ -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;
--
2.45.2
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [LTP] [PATCH 03/13] lib: Add tst_mapping_in_range()
2024-12-18 18:45 [LTP] [PATCH 00/13] Get rid of testcases/kernel/mem/lib library Cyril Hrubis
2024-12-18 18:45 ` [LTP] [PATCH 01/13] lib: tst_sys_conf: Add two functions Cyril Hrubis
2024-12-18 18:45 ` [LTP] [PATCH 02/13] lib: Replace path_exist() with tst_path_exists() Cyril Hrubis
@ 2024-12-18 18:45 ` Cyril Hrubis
2024-12-27 10:25 ` Petr Vorel
2024-12-18 18:45 ` [LTP] [PATCH 04/13] testcases/kernel/mem: Move get_a_numa_node() Cyril Hrubis
` (10 subsequent siblings)
13 siblings, 1 reply; 41+ messages in thread
From: Cyril Hrubis @ 2024-12-18 18:45 UTC (permalink / raw)
To: ltp
This 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.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
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(-)
diff --git a/include/tst_memutils.h b/include/tst_memutils.h
index 0dd941ced..e9289a4e9 100644
--- a/include/tst_memutils.h
+++ b/include/tst_memutils.h
@@ -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__ */
diff --git a/lib/tst_memutils.c b/lib/tst_memutils.c
index e33f19d29..e49684ba1 100644
--- a/lib/tst_memutils.c
+++ b/lib/tst_memutils.c
@@ -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;
+}
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c
index b788aeafb..611ae7090 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c
@@ -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)
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c
index 42b80064e..b543c8882 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap13.c
@@ -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");
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c
index c54a746b3..0a2ae312b 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap14.c
@@ -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");
diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
index 0d7bbf64f..9f877fd07 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
@@ -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");
diff --git a/testcases/kernel/mem/include/mem.h b/testcases/kernel/mem/include/mem.h
index 87528fdd0..7251a8839 100644
--- a/testcases/kernel/mem/include/mem.h
+++ b/testcases/kernel/mem/include/mem.h
@@ -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
diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c
index f293e766e..16eb39cba 100644
--- a/testcases/kernel/mem/lib/mem.c
+++ b/testcases/kernel/mem/lib/mem.c
@@ -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;
-}
--
2.45.2
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [LTP] [PATCH 04/13] testcases/kernel/mem: Move get_a_numa_node()
2024-12-18 18:45 [LTP] [PATCH 00/13] Get rid of testcases/kernel/mem/lib library Cyril Hrubis
` (2 preceding siblings ...)
2024-12-18 18:45 ` [LTP] [PATCH 03/13] lib: Add tst_mapping_in_range() Cyril Hrubis
@ 2024-12-18 18:45 ` Cyril Hrubis
2024-12-27 10:27 ` Petr Vorel
2024-12-18 18:45 ` [LTP] [PATCH 05/13] testcases/kernel/mem: Move update_shm_size() Cyril Hrubis
` (9 subsequent siblings)
13 siblings, 1 reply; 41+ messages in thread
From: Cyril Hrubis @ 2024-12-18 18:45 UTC (permalink / raw)
To: ltp
Move get_a_numa_node() from the library to the ksm_common.h since the
function is used only by the ksm testcases.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
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(-)
diff --git a/testcases/kernel/mem/include/mem.h b/testcases/kernel/mem/include/mem.h
index 7251a8839..35a1f0834 100644
--- a/testcases/kernel/mem/include/mem.h
+++ b/testcases/kernel/mem/include/mem.h
@@ -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
diff --git a/testcases/kernel/mem/ksm/ksm_common.h b/testcases/kernel/mem/ksm/ksm_common.h
index 489d34ae0..43ea8f8c2 100644
--- a/testcases/kernel/mem/ksm/ksm_common.h
+++ b/testcases/kernel/mem/ksm/ksm_common.h
@@ -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__ */
diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c
index 16eb39cba..06271f5d3 100644
--- a/testcases/kernel/mem/lib/mem.c
+++ b/testcases/kernel/mem/lib/mem.c
@@ -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;
--
2.45.2
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [LTP] [PATCH 05/13] testcases/kernel/mem: Move update_shm_size()
2024-12-18 18:45 [LTP] [PATCH 00/13] Get rid of testcases/kernel/mem/lib library Cyril Hrubis
` (3 preceding siblings ...)
2024-12-18 18:45 ` [LTP] [PATCH 04/13] testcases/kernel/mem: Move get_a_numa_node() Cyril Hrubis
@ 2024-12-18 18:45 ` Cyril Hrubis
2024-12-27 10:34 ` Petr Vorel
2024-12-18 18:45 ` [LTP] [PATCH 06/13] testcases/kernel/mem: Move check_hugepage() + PATH_THP Cyril Hrubis
` (8 subsequent siblings)
13 siblings, 1 reply; 41+ messages in thread
From: Cyril Hrubis @ 2024-12-18 18:45 UTC (permalink / raw)
To: ltp
Move update_shm_size() from the lib to the libhugetlb.c since the
function is used only by the hugetlb testcases.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
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(-)
diff --git a/testcases/kernel/mem/hugetlb/lib/hugetlb.c b/testcases/kernel/mem/hugetlb/lib/hugetlb.c
index 43a677ce9..6a2976a53 100644
--- a/testcases/kernel/mem/hugetlb/lib/hugetlb.c
+++ b/testcases/kernel/mem/hugetlb/lib/hugetlb.c
@@ -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;
+ }
+}
diff --git a/testcases/kernel/mem/hugetlb/lib/hugetlb.h b/testcases/kernel/mem/hugetlb/lib/hugetlb.h
index a694514d2..abc88e25e 100644
--- a/testcases/kernel/mem/hugetlb/lib/hugetlb.h
+++ b/testcases/kernel/mem/hugetlb/lib/hugetlb.h
@@ -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 */
diff --git a/testcases/kernel/mem/include/mem.h b/testcases/kernel/mem/include/mem.h
index 35a1f0834..03dbe91d7 100644
--- a/testcases/kernel/mem/include/mem.h
+++ b/testcases/kernel/mem/include/mem.h
@@ -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
diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c
index 06271f5d3..de9388a80 100644
--- a/testcases/kernel/mem/lib/mem.c
+++ b/testcases/kernel/mem/lib/mem.c
@@ -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;
- }
-}
--
2.45.2
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [LTP] [PATCH 06/13] testcases/kernel/mem: Move check_hugepage() + PATH_THP
2024-12-18 18:45 [LTP] [PATCH 00/13] Get rid of testcases/kernel/mem/lib library Cyril Hrubis
` (4 preceding siblings ...)
2024-12-18 18:45 ` [LTP] [PATCH 05/13] testcases/kernel/mem: Move update_shm_size() Cyril Hrubis
@ 2024-12-18 18:45 ` Cyril Hrubis
2024-12-27 10:48 ` Petr Vorel
2024-12-18 18:45 ` [LTP] [PATCH 07/13] testcases/kernel/mem: Move NUMA bits to numa_helper.h Cyril Hrubis
` (7 subsequent siblings)
13 siblings, 1 reply; 41+ messages in thread
From: Cyril Hrubis @ 2024-12-18 18:45 UTC (permalink / raw)
To: ltp
These 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.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
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
diff --git a/testcases/kernel/mem/include/mem.h b/testcases/kernel/mem/include/mem.h
index 03dbe91d7..ba5a996a7 100644
--- a/testcases/kernel/mem/include/mem.h
+++ b/testcases/kernel/mem/include/mem.h
@@ -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 */
diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c
index de9388a80..02199349d 100644
--- a/testcases/kernel/mem/lib/mem.c
+++ b/testcases/kernel/mem/lib/mem.c
@@ -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;
diff --git a/testcases/kernel/mem/thp/Makefile b/testcases/kernel/mem/thp/Makefile
index e95712eaf..d89ea1dd3 100644
--- a/testcases/kernel/mem/thp/Makefile
+++ b/testcases/kernel/mem/thp/Makefile
@@ -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
diff --git a/testcases/kernel/mem/thp/thp.h b/testcases/kernel/mem/thp/thp.h
new file mode 100644
index 000000000..7723bedc2
--- /dev/null
+++ b/testcases/kernel/mem/thp/thp.h
@@ -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 */
diff --git a/testcases/kernel/mem/thp/thp01.c b/testcases/kernel/mem/thp/thp01.c
index 69825b0f9..bdb2c54db 100644
--- a/testcases/kernel/mem/thp/thp01.c
+++ b/testcases/kernel/mem/thp/thp01.c
@@ -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)
diff --git a/testcases/kernel/mem/thp/thp02.c b/testcases/kernel/mem/thp/thp02.c
index 56568d1d1..c6f9d2fd5 100644
--- a/testcases/kernel/mem/thp/thp02.c
+++ b/testcases/kernel/mem/thp/thp02.c
@@ -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;
diff --git a/testcases/kernel/mem/thp/thp03.c b/testcases/kernel/mem/thp/thp03.c
index 839efcb0e..e8d22669e 100644
--- a/testcases/kernel/mem/thp/thp03.c
+++ b/testcases/kernel/mem/thp/thp03.c
@@ -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);
}
--
2.45.2
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [LTP] [PATCH 07/13] testcases/kernel/mem: Move NUMA bits to numa_helper.h
2024-12-18 18:45 [LTP] [PATCH 00/13] Get rid of testcases/kernel/mem/lib library Cyril Hrubis
` (5 preceding siblings ...)
2024-12-18 18:45 ` [LTP] [PATCH 06/13] testcases/kernel/mem: Move check_hugepage() + PATH_THP Cyril Hrubis
@ 2024-12-18 18:45 ` Cyril Hrubis
2024-12-27 11:01 ` Petr Vorel
2024-12-27 11:09 ` Petr Vorel
2024-12-18 18:45 ` [LTP] [PATCH 08/13] testcases/kernel/mem: Move oom() fucntions to oom tests Cyril Hrubis
` (6 subsequent siblings)
13 siblings, 2 replies; 41+ messages in thread
From: Cyril Hrubis @ 2024-12-18 18:45 UTC (permalink / raw)
To: ltp
Testcases 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.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
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
diff --git a/testcases/kernel/include/numa_helper.h b/testcases/kernel/include/numa_helper.h
index ed45ec8a8..e67ddaaca 100644
--- a/testcases/kernel/include/numa_helper.h
+++ b/testcases/kernel/include/numa_helper.h
@@ -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 */
diff --git a/testcases/kernel/lib/numa_cpuset.c b/testcases/kernel/lib/numa_cpuset.c
new file mode 100644
index 000000000..088d2d4e5
--- /dev/null
+++ b/testcases/kernel/lib/numa_cpuset.c
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Linux Test Project, 2011-2021
+ * Copyright (c) Cyril Hrubis <chrubis@suse.cz> 2024
+ */
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "tst_cgroup.h"
+#include "numa_helper.h"
+
+static void gather_node_cpus(char *cpus, long nd)
+{
+ int ncpus = 0;
+ int i;
+ long online;
+ char buf[BUFSIZ];
+ char path[BUFSIZ], path1[BUFSIZ];
+
+ 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 (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 (tst_path_exists("%s", path1)) {
+ SAFE_FILE_SCANF(path1, "%ld", &online);
+ if (online == 0)
+ continue;
+ }
+ sprintf(buf, "%d,", i);
+ strcat(cpus, buf);
+ }
+ }
+ /* Remove the trailing comma. */
+ cpus[strlen(cpus) - 1] = '\0';
+}
+
+void write_node_cpusets(const struct tst_cg_group *cg, long nd)
+{
+ char cpus[BUFSIZ] = "";
+
+ SAFE_CG_PRINTF(cg, "cpuset.mems", "%ld", nd);
+
+ gather_node_cpus(cpus, nd);
+ /*
+ * If the 'nd' node doesn't contain any CPUs,
+ * the first ID of CPU '0' will be used as
+ * the value of cpuset.cpus.
+ */
+ if (strlen(cpus) != 0) {
+ SAFE_CG_PRINT(cg, "cpuset.cpus", cpus);
+ } else {
+ tst_res(TINFO, "No CPUs in the node%ld; "
+ "using only CPU0", nd);
+ SAFE_CG_PRINT(cg, "cpuset.cpus", "0");
+ }
+}
diff --git a/testcases/kernel/mem/include/mem.h b/testcases/kernel/mem/include/mem.h
index ba5a996a7..e0f443b4b 100644
--- a/testcases/kernel/mem/include/mem.h
+++ b/testcases/kernel/mem/include/mem.h
@@ -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
diff --git a/testcases/kernel/mem/ksm/ksm02.c b/testcases/kernel/mem/ksm/ksm02.c
index 3707de95d..a388e82ab 100644
--- a/testcases/kernel/mem/ksm/ksm02.c
+++ b/testcases/kernel/mem/ksm/ksm02.c
@@ -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());
diff --git a/testcases/kernel/mem/ksm/ksm04.c b/testcases/kernel/mem/ksm/ksm04.c
index f558b23be..31f3ff2eb 100644
--- a/testcases/kernel/mem/ksm/ksm04.c
+++ b/testcases/kernel/mem/ksm/ksm04.c
@@ -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);
}
diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c
index 02199349d..c7c05aa03 100644
--- a/testcases/kernel/mem/lib/mem.c
+++ b/testcases/kernel/mem/lib/mem.c
@@ -527,60 +527,3 @@ void create_same_memory(int size, int num, int unit)
tst_res(TFAIL, "child exit status is %d",
WEXITSTATUS(status));
}
-
-/* THP */
-
-/* cpuset/memcg */
-static void gather_node_cpus(char *cpus, long nd)
-{
- int ncpus = 0;
- int i;
- long online;
- char buf[BUFSIZ];
- char path[BUFSIZ], path1[BUFSIZ];
-
- 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 (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 (tst_path_exists("%s", path1)) {
- SAFE_FILE_SCANF(path1, "%ld", &online);
- if (online == 0)
- continue;
- }
- sprintf(buf, "%d,", i);
- strcat(cpus, buf);
- }
- }
- /* Remove the trailing comma. */
- cpus[strlen(cpus) - 1] = '\0';
-}
-
-void write_cpusets(const struct tst_cg_group *cg, long nd)
-{
- char cpus[BUFSIZ] = "";
-
- SAFE_CG_PRINTF(cg, "cpuset.mems", "%ld", nd);
-
- gather_node_cpus(cpus, nd);
- /*
- * If the 'nd' node doesn't contain any CPUs,
- * the first ID of CPU '0' will be used as
- * the value of cpuset.cpus.
- */
- if (strlen(cpus) != 0) {
- SAFE_CG_PRINT(cg, "cpuset.cpus", cpus);
- } else {
- tst_res(TINFO, "No CPUs in the node%ld; "
- "using only CPU0", nd);
- SAFE_CG_PRINT(cg, "cpuset.cpus", "0");
- }
-}
diff --git a/testcases/kernel/mem/oom/oom04.c b/testcases/kernel/mem/oom/oom04.c
index 3f0bcf7e2..47087658d 100644
--- a/testcases/kernel/mem/oom/oom04.c
+++ b/testcases/kernel/mem/oom/oom04.c
@@ -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());
}
diff --git a/testcases/kernel/mem/oom/oom05.c b/testcases/kernel/mem/oom/oom05.c
index 74f0f78b3..f3851f4f2 100644
--- a/testcases/kernel/mem/oom/oom05.c
+++ b/testcases/kernel/mem/oom/oom05.c
@@ -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);
}
--
2.45.2
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [LTP] [PATCH 08/13] testcases/kernel/mem: Move oom() fucntions to oom tests
2024-12-18 18:45 [LTP] [PATCH 00/13] Get rid of testcases/kernel/mem/lib library Cyril Hrubis
` (6 preceding siblings ...)
2024-12-18 18:45 ` [LTP] [PATCH 07/13] testcases/kernel/mem: Move NUMA bits to numa_helper.h Cyril Hrubis
@ 2024-12-18 18:45 ` Cyril Hrubis
2024-12-27 11:06 ` Petr Vorel
2024-12-18 18:45 ` [LTP] [PATCH 09/13] testcases/kernel/mem: Move KSM bits to ksm tests Cyril Hrubis
` (5 subsequent siblings)
13 siblings, 1 reply; 41+ messages in thread
From: Cyril Hrubis @ 2024-12-18 18:45 UTC (permalink / raw)
To: ltp
Functions that are used only by the oom testcases are moved into
oom/oom.h.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
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
diff --git a/testcases/kernel/mem/include/mem.h b/testcases/kernel/mem/include/mem.h
index e0f443b4b..5ebedc175 100644
--- a/testcases/kernel/mem/include/mem.h
+++ b/testcases/kernel/mem/include/mem.h
@@ -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);
diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c
index c7c05aa03..f3b844994 100644
--- a/testcases/kernel/mem/lib/mem.c
+++ b/testcases/kernel/mem/lib/mem.c
@@ -25,218 +25,6 @@
#include "mem.h"
#include "numa_helper.h"
-/* OOM */
-
-static int alloc_mem(long int length, int testcase)
-{
- char *s;
- long i, pagesz = getpagesize();
- int loop = 10;
-
- tst_res(TINFO, "thread (%lx), allocating %ld bytes.",
- (unsigned long) pthread_self(), length);
-
- s = mmap(NULL, length, PROT_READ | PROT_WRITE,
- MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
- if (s == MAP_FAILED)
- return errno;
-
- if (testcase == MLOCK) {
- while (mlock(s, length) == -1 && loop > 0) {
- if (EAGAIN != errno)
- return errno;
- usleep(300000);
- loop--;
- }
- }
-
-#ifdef HAVE_DECL_MADV_MERGEABLE
- if (testcase == KSM && madvise(s, length, MADV_MERGEABLE) == -1)
- return errno;
-#endif
- for (i = 0; i < length; i += pagesz)
- s[i] = '\a';
-
- return 0;
-}
-
-static void *child_alloc_thread(void *args)
-{
- int ret = 0;
-
- /* keep allocating until there's an error */
- while (!ret)
- ret = alloc_mem(LENGTH, (long)args);
- exit(ret);
-}
-
-static void child_alloc(int testcase, int lite, int threads)
-{
- int i;
- pthread_t *th;
-
- if (lite) {
- int ret = alloc_mem(TESTMEM * 2 + MB, testcase);
- exit(ret);
- }
-
- th = malloc(sizeof(pthread_t) * threads);
- if (!th) {
- tst_res(TINFO | TERRNO, "malloc");
- goto out;
- }
-
- for (i = 0; i < threads; i++) {
- TEST(pthread_create(&th[i], NULL, child_alloc_thread,
- (void *)((long)testcase)));
- if (TST_RET) {
- tst_res(TINFO | TRERRNO, "pthread_create");
- /*
- * Keep going if thread other than first fails to
- * spawn due to lack of resources.
- */
- if (i == 0 || TST_RET != EAGAIN)
- goto out;
- }
- }
-
- /* wait for one of threads to exit whole process */
- while (1)
- sleep(1);
-out:
- exit(1);
-}
-
-/*
- * oom - allocates memory according to specified testcase and checks
- * desired outcome (e.g. child killed, operation failed with ENOMEM)
- * @testcase: selects how child allocates memory
- * valid choices are: NORMAL, MLOCK and KSM
- * @lite: if non-zero, child makes only single TESTMEM+MB allocation
- * if zero, child keeps allocating memory until it gets killed
- * or some operation fails
- * @retcode: expected return code of child process
- * if matches child ret code, this function reports PASS,
- * otherwise it reports FAIL
- * @allow_sigkill: if zero and child is killed, this function reports FAIL
- * if non-zero, then if child is killed by SIGKILL
- * it is considered as PASS
- */
-void oom(int testcase, int lite, int retcode, int allow_sigkill)
-{
- pid_t pid;
- int status, threads;
-
- tst_enable_oom_protection(0);
-
- switch (pid = SAFE_FORK()) {
- case 0:
- tst_disable_oom_protection(0);
- threads = MAX(1, tst_ncpus() - 1);
- child_alloc(testcase, lite, threads);
- default:
- break;
- }
-
- tst_res(TINFO, "expected victim is %d.", pid);
- SAFE_WAITPID(-1, &status, 0);
-
- if (WIFSIGNALED(status)) {
- if (allow_sigkill && WTERMSIG(status) == SIGKILL) {
- tst_res(TPASS, "victim signalled: (%d) %s",
- SIGKILL,
- tst_strsig(SIGKILL));
- } else {
- tst_res(TFAIL, "victim signalled: (%d) %s",
- WTERMSIG(status),
- tst_strsig(WTERMSIG(status)));
- }
- } else if (WIFEXITED(status)) {
- if (WEXITSTATUS(status) == retcode) {
- tst_res(TPASS, "victim retcode: (%d) %s",
- retcode, strerror(retcode));
- } else {
- tst_res(TFAIL, "victim unexpectedly ended with "
- "retcode: %d, expected: %d",
- WEXITSTATUS(status), retcode);
- }
- } else {
- tst_res(TFAIL, "victim unexpectedly ended");
- }
-}
-
-#ifdef HAVE_NUMA_V2
-static void set_global_mempolicy(int mempolicy)
-{
- unsigned long nmask[MAXNODES / BITS_PER_LONG] = { 0 };
- int num_nodes, *nodes;
- int ret;
-
- if (mempolicy) {
- ret = get_allowed_nodes_arr(NH_MEMS|NH_CPUS, &num_nodes, &nodes);
- if (ret != 0)
- tst_brk(TBROK|TERRNO, "get_allowed_nodes_arr");
- if (num_nodes < 2) {
- tst_res(TINFO, "mempolicy need NUMA system support");
- free(nodes);
- return;
- }
- switch(mempolicy) {
- case MPOL_BIND:
- /* bind the second node */
- set_node(nmask, nodes[1]);
- break;
- case MPOL_INTERLEAVE:
- case MPOL_PREFERRED:
- if (num_nodes == 2) {
- tst_res(TINFO, "The mempolicy need "
- "more than 2 numa nodes");
- free(nodes);
- return;
- } else {
- /* Using the 2nd,3rd node */
- set_node(nmask, nodes[1]);
- set_node(nmask, nodes[2]);
- }
- break;
- default:
- tst_brk(TBROK|TERRNO, "Bad mempolicy mode");
- }
- if (set_mempolicy(mempolicy, nmask, MAXNODES) == -1)
- tst_brk(TBROK|TERRNO, "set_mempolicy");
- }
-}
-#else
-static void set_global_mempolicy(int mempolicy LTP_ATTRIBUTE_UNUSED) { }
-#endif
-
-void testoom(int mempolicy, int lite, int retcode, int allow_sigkill)
-{
- int ksm_run_orig;
-
- set_global_mempolicy(mempolicy);
-
- tst_res(TINFO, "start normal OOM testing.");
- oom(NORMAL, lite, retcode, allow_sigkill);
-
- tst_res(TINFO, "start OOM testing for mlocked pages.");
- oom(MLOCK, lite, retcode, allow_sigkill);
-
- /*
- * Skip oom(KSM) if lite == 1, since limit_in_bytes may vary from
- * run to run, which isn't reliable for oom03 cgroup test.
- */
- if (access(PATH_KSM, F_OK) == -1 || lite == 1) {
- tst_res(TINFO, "KSM is not configed or lite == 1, "
- "skip OOM test for KSM pags");
- } else {
- tst_res(TINFO, "start OOM testing for KSM pages.");
- SAFE_FILE_SCANF(PATH_KSM "run", "%d", &ksm_run_orig);
- SAFE_FILE_PRINTF(PATH_KSM "run", "1");
- oom(KSM, lite, retcode, allow_sigkill);
- SAFE_FILE_PRINTF(PATH_KSM "run", "%d", ksm_run_orig);
- }
-}
/* KSM */
diff --git a/testcases/kernel/mem/oom/Makefile b/testcases/kernel/mem/oom/Makefile
index dd55fb8dc..db621b9ce 100644
--- a/testcases/kernel/mem/oom/Makefile
+++ b/testcases/kernel/mem/oom/Makefile
@@ -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
diff --git a/testcases/kernel/mem/oom/oom.h b/testcases/kernel/mem/oom/oom.h
new file mode 100644
index 000000000..41cc681f9
--- /dev/null
+++ b/testcases/kernel/mem/oom/oom.h
@@ -0,0 +1,231 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Linux Test Project, 2011-2021
+ * Copyright (c) Cyril Hrubis <chrubis@suse.cz> 2024
+ */
+#ifndef OOM_H_
+#define OOM_H_
+
+#include <pthread.h>
+#include "config.h"
+#include "numa_helper.h"
+
+#define PATH_KSM "/sys/kernel/mm/ksm/"
+
+#define LENGTH (3UL<<30)
+#define NORMAL 1
+#define MLOCK 2
+#define KSM 3
+
+#ifdef HAVE_NUMA_V2
+static inline void set_global_mempolicy(int mempolicy)
+{
+ unsigned long nmask[MAXNODES / BITS_PER_LONG] = { 0 };
+ int num_nodes, *nodes;
+ int ret;
+
+ if (mempolicy) {
+ ret = get_allowed_nodes_arr(NH_MEMS|NH_CPUS, &num_nodes, &nodes);
+ if (ret != 0)
+ tst_brk(TBROK|TERRNO, "get_allowed_nodes_arr");
+ if (num_nodes < 2) {
+ tst_res(TINFO, "mempolicy need NUMA system support");
+ free(nodes);
+ return;
+ }
+ switch(mempolicy) {
+ case MPOL_BIND:
+ /* bind the second node */
+ set_node(nmask, nodes[1]);
+ break;
+ case MPOL_INTERLEAVE:
+ case MPOL_PREFERRED:
+ if (num_nodes == 2) {
+ tst_res(TINFO, "The mempolicy need "
+ "more than 2 numa nodes");
+ free(nodes);
+ return;
+ } else {
+ /* Using the 2nd,3rd node */
+ set_node(nmask, nodes[1]);
+ set_node(nmask, nodes[2]);
+ }
+ break;
+ default:
+ tst_brk(TBROK|TERRNO, "Bad mempolicy mode");
+ }
+ if (set_mempolicy(mempolicy, nmask, MAXNODES) == -1)
+ tst_brk(TBROK|TERRNO, "set_mempolicy");
+ }
+}
+#else
+static void set_global_mempolicy(int mempolicy LTP_ATTRIBUTE_UNUSED) { }
+#endif
+
+static int alloc_mem(long int length, int testcase)
+{
+ char *s;
+ long i, pagesz = getpagesize();
+ int loop = 10;
+
+ tst_res(TINFO, "thread (%lx), allocating %ld bytes.",
+ (unsigned long) pthread_self(), length);
+
+ s = mmap(NULL, length, PROT_READ | PROT_WRITE,
+ MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ if (s == MAP_FAILED)
+ return errno;
+
+ if (testcase == MLOCK) {
+ while (mlock(s, length) == -1 && loop > 0) {
+ if (EAGAIN != errno)
+ return errno;
+ usleep(300000);
+ loop--;
+ }
+ }
+
+#ifdef HAVE_DECL_MADV_MERGEABLE
+ if (testcase == KSM && madvise(s, length, MADV_MERGEABLE) == -1)
+ return errno;
+#endif
+ for (i = 0; i < length; i += pagesz)
+ s[i] = '\a';
+
+ return 0;
+}
+
+static void *child_alloc_thread(void *args)
+{
+ int ret = 0;
+
+ /* keep allocating until there's an error */
+ while (!ret)
+ ret = alloc_mem(LENGTH, (long)args);
+ exit(ret);
+}
+
+static void child_alloc(int testcase, int lite, int threads)
+{
+ int i;
+ pthread_t *th;
+
+ if (lite) {
+ int ret = alloc_mem(TESTMEM * 2 + TST_MB, testcase);
+ exit(ret);
+ }
+
+ th = malloc(sizeof(pthread_t) * threads);
+ if (!th) {
+ tst_res(TINFO | TERRNO, "malloc");
+ goto out;
+ }
+
+ for (i = 0; i < threads; i++) {
+ TEST(pthread_create(&th[i], NULL, child_alloc_thread,
+ (void *)((long)testcase)));
+ if (TST_RET) {
+ tst_res(TINFO | TRERRNO, "pthread_create");
+ /*
+ * Keep going if thread other than first fails to
+ * spawn due to lack of resources.
+ */
+ if (i == 0 || TST_RET != EAGAIN)
+ goto out;
+ }
+ }
+
+ /* wait for one of threads to exit whole process */
+ while (1)
+ sleep(1);
+out:
+ exit(1);
+}
+
+/*
+ * oom - allocates memory according to specified testcase and checks
+ * desired outcome (e.g. child killed, operation failed with ENOMEM)
+ * @testcase: selects how child allocates memory
+ * valid choices are: NORMAL, MLOCK and KSM
+ * @lite: if non-zero, child makes only single TESTMEM+TST_MB allocation
+ * if zero, child keeps allocating memory until it gets killed
+ * or some operation fails
+ * @retcode: expected return code of child process
+ * if matches child ret code, this function reports PASS,
+ * otherwise it reports FAIL
+ * @allow_sigkill: if zero and child is killed, this function reports FAIL
+ * if non-zero, then if child is killed by SIGKILL
+ * it is considered as PASS
+ */
+static inline void oom(int testcase, int lite, int retcode, int allow_sigkill)
+{
+ pid_t pid;
+ int status, threads;
+
+ tst_enable_oom_protection(0);
+
+ switch (pid = SAFE_FORK()) {
+ case 0:
+ tst_disable_oom_protection(0);
+ threads = MAX(1, tst_ncpus() - 1);
+ child_alloc(testcase, lite, threads);
+ default:
+ break;
+ }
+
+ tst_res(TINFO, "expected victim is %d.", pid);
+ SAFE_WAITPID(-1, &status, 0);
+
+ if (WIFSIGNALED(status)) {
+ if (allow_sigkill && WTERMSIG(status) == SIGKILL) {
+ tst_res(TPASS, "victim signalled: (%d) %s",
+ SIGKILL,
+ tst_strsig(SIGKILL));
+ } else {
+ tst_res(TFAIL, "victim signalled: (%d) %s",
+ WTERMSIG(status),
+ tst_strsig(WTERMSIG(status)));
+ }
+ } else if (WIFEXITED(status)) {
+ if (WEXITSTATUS(status) == retcode) {
+ tst_res(TPASS, "victim retcode: (%d) %s",
+ retcode, strerror(retcode));
+ } else {
+ tst_res(TFAIL, "victim unexpectedly ended with "
+ "retcode: %d, expected: %d",
+ WEXITSTATUS(status), retcode);
+ }
+ } else {
+ tst_res(TFAIL, "victim unexpectedly ended");
+ }
+}
+
+static inline void testoom(int mempolicy, int lite, int retcode, int allow_sigkill)
+{
+ int ksm_run_orig;
+
+ set_global_mempolicy(mempolicy);
+
+ tst_res(TINFO, "start normal OOM testing.");
+ oom(NORMAL, lite, retcode, allow_sigkill);
+
+ tst_res(TINFO, "start OOM testing for mlocked pages.");
+ oom(MLOCK, lite, retcode, allow_sigkill);
+
+ /*
+ * Skip oom(KSM) if lite == 1, since limit_in_bytes may vary from
+ * run to run, which isn't reliable for oom03 cgroup test.
+ */
+ if (access(PATH_KSM, F_OK) == -1 || lite == 1) {
+ tst_res(TINFO, "KSM is not configed or lite == 1, "
+ "skip OOM test for KSM pags");
+ } else {
+ tst_res(TINFO, "start OOM testing for KSM pages.");
+ SAFE_FILE_SCANF(PATH_KSM "run", "%d", &ksm_run_orig);
+ SAFE_FILE_PRINTF(PATH_KSM "run", "1");
+ oom(KSM, lite, retcode, allow_sigkill);
+ SAFE_FILE_PRINTF(PATH_KSM "run", "%d", ksm_run_orig);
+ }
+}
+
+#endif /* OOM_H_ */
diff --git a/testcases/kernel/mem/oom/oom01.c b/testcases/kernel/mem/oom/oom01.c
index 157ca84b6..249413cf8 100644
--- a/testcases/kernel/mem/oom/oom01.c
+++ b/testcases/kernel/mem/oom/oom01.c
@@ -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"
diff --git a/testcases/kernel/mem/oom/oom02.c b/testcases/kernel/mem/oom/oom02.c
index 087d61abe..ef1eeecac 100644
--- a/testcases/kernel/mem/oom/oom02.c
+++ b/testcases/kernel/mem/oom/oom02.c
@@ -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
diff --git a/testcases/kernel/mem/oom/oom03.c b/testcases/kernel/mem/oom/oom03.c
index 1041a6a1d..67ccbf1e8 100644
--- a/testcases/kernel/mem/oom/oom03.c
+++ b/testcases/kernel/mem/oom/oom03.c
@@ -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);
diff --git a/testcases/kernel/mem/oom/oom04.c b/testcases/kernel/mem/oom/oom04.c
index 47087658d..68f7a2b18 100644
--- a/testcases/kernel/mem/oom/oom04.c
+++ b/testcases/kernel/mem/oom/oom04.c
@@ -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
diff --git a/testcases/kernel/mem/oom/oom05.c b/testcases/kernel/mem/oom/oom05.c
index f3851f4f2..05ab2b981 100644
--- a/testcases/kernel/mem/oom/oom05.c
+++ b/testcases/kernel/mem/oom/oom05.c
@@ -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);
--
2.45.2
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [LTP] [PATCH 09/13] testcases/kernel/mem: Move KSM bits to ksm tests
2024-12-18 18:45 [LTP] [PATCH 00/13] Get rid of testcases/kernel/mem/lib library Cyril Hrubis
` (7 preceding siblings ...)
2024-12-18 18:45 ` [LTP] [PATCH 08/13] testcases/kernel/mem: Move oom() fucntions to oom tests Cyril Hrubis
@ 2024-12-18 18:45 ` Cyril Hrubis
2024-12-19 2:52 ` Li Wang
` (3 more replies)
2024-12-18 18:45 ` [LTP] [PATCH 10/13] mem/swapping: Remove mem/lib refrence Cyril Hrubis
` (4 subsequent siblings)
13 siblings, 4 replies; 41+ messages in thread
From: Cyril Hrubis @ 2024-12-18 18:45 UTC (permalink / raw)
To: ltp
Moves the ksm helpers into a ksm/ksm_test.h since these are not used by
any other but ksm tests.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
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
diff --git a/testcases/kernel/mem/include/mem.h b/testcases/kernel/mem/include/mem.h
index 5ebedc175..25389f34c 100644
--- a/testcases/kernel/mem/include/mem.h
+++ b/testcases/kernel/mem/include/mem.h
@@ -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"
diff --git a/testcases/kernel/mem/ksm/Makefile b/testcases/kernel/mem/ksm/Makefile
index 6aba73e61..2af02a274 100644
--- a/testcases/kernel/mem/ksm/Makefile
+++ b/testcases/kernel/mem/ksm/Makefile
@@ -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
diff --git a/testcases/kernel/mem/ksm/ksm01.c b/testcases/kernel/mem/ksm/ksm01.c
index e2d3d9e00..a22e4830f 100644
--- a/testcases/kernel/mem/ksm/ksm01.c
+++ b/testcases/kernel/mem/ksm/ksm01.c
@@ -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)
diff --git a/testcases/kernel/mem/ksm/ksm02.c b/testcases/kernel/mem/ksm/ksm02.c
index a388e82ab..4d1306045 100644
--- a/testcases/kernel/mem/ksm/ksm02.c
+++ b/testcases/kernel/mem/ksm/ksm02.c
@@ -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
diff --git a/testcases/kernel/mem/ksm/ksm03.c b/testcases/kernel/mem/ksm/ksm03.c
index cff74700d..78844b30e 100644
--- a/testcases/kernel/mem/ksm/ksm03.c
+++ b/testcases/kernel/mem/ksm/ksm03.c
@@ -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)
diff --git a/testcases/kernel/mem/ksm/ksm04.c b/testcases/kernel/mem/ksm/ksm04.c
index 31f3ff2eb..8465ee230 100644
--- a/testcases/kernel/mem/ksm/ksm04.c
+++ b/testcases/kernel/mem/ksm/ksm04.c
@@ -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
diff --git a/testcases/kernel/mem/ksm/ksm05.c b/testcases/kernel/mem/ksm/ksm05.c
index 1d9d9699a..025dffc09 100644
--- a/testcases/kernel/mem/ksm/ksm05.c
+++ b/testcases/kernel/mem/ksm/ksm05.c
@@ -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
diff --git a/testcases/kernel/mem/ksm/ksm06.c b/testcases/kernel/mem/ksm/ksm06.c
index 80fdf1e47..09a54fd18 100644
--- a/testcases/kernel/mem/ksm/ksm06.c
+++ b/testcases/kernel/mem/ksm/ksm06.c
@@ -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>
diff --git a/testcases/kernel/mem/ksm/ksm07.c b/testcases/kernel/mem/ksm/ksm07.c
index 619bd7b55..24b393283 100644
--- a/testcases/kernel/mem/ksm/ksm07.c
+++ b/testcases/kernel/mem/ksm/ksm07.c
@@ -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
diff --git a/testcases/kernel/mem/ksm/ksm_common.h b/testcases/kernel/mem/ksm/ksm_common.h
index 43ea8f8c2..d677b224d 100644
--- a/testcases/kernel/mem/ksm/ksm_common.h
+++ b/testcases/kernel/mem/ksm/ksm_common.h
@@ -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__ */
diff --git a/testcases/kernel/mem/ksm/ksm_test.h b/testcases/kernel/mem/ksm/ksm_test.h
new file mode 100644
index 000000000..ebce8197c
--- /dev/null
+++ b/testcases/kernel/mem/ksm/ksm_test.h
@@ -0,0 +1,299 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Linux Test Project, 2011-2021
+ * Copyright (c) Cyril Hrubis <chrubis@suse.cz> 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,
+ 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,
+ 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 "
+ "%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,
+ 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'",
+ child_num, size, ksm_merge_data.data);
+
+ } else {
+ tst_res(TINFO, "child %d allocates %d TST_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 * 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,
+ 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);
+ 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},
+ };
+ struct ksm_merge_data ksm_data1[] = {
+ {'a', size*TST_MB}, {'b', size*TST_MB}, {'d', size*TST_MB}, {'d', size*TST_MB-1},
+ };
+ struct ksm_merge_data ksm_data2[] = {
+ {'a', size*TST_MB}, {'a', size*TST_MB}, {'d', size*TST_MB}, {'d', size*TST_MB},
+ };
+
+ 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 */
+ 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]);
+ 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);
+ }
+
+ SAFE_FILE_PRINTF(PATH_KSM "run", "1");
+ SAFE_FILE_PRINTF(PATH_KSM "pages_to_scan", "%ld", size * pages * num);
+ 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);
+
+ 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);
+
+ 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);
+
+ 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);
+
+ 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_ */
diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c
index f3b844994..4e5c0b873 100644
--- a/testcases/kernel/mem/lib/mem.c
+++ b/testcases/kernel/mem/lib/mem.c
@@ -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,
- 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 "
- "%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,
- 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},
- };
- struct ksm_merge_data ksm_data1[] = {
- {'a', size*MB}, {'b', size*MB}, {'d', size*MB}, {'d', size*MB-1},
- };
- struct ksm_merge_data ksm_data2[] = {
- {'a', size*MB}, {'a', size*MB}, {'d', size*MB}, {'d', size*MB},
- };
-
- 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 */
- 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]);
- 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);
- }
-
- SAFE_FILE_PRINTF(PATH_KSM "run", "1");
- SAFE_FILE_PRINTF(PATH_KSM "pages_to_scan", "%ld", size * pages * num);
- 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);
-
- 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);
-
- 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);
-
- 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);
-
- 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
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [LTP] [PATCH 10/13] mem/swapping: Remove mem/lib refrence
2024-12-18 18:45 [LTP] [PATCH 00/13] Get rid of testcases/kernel/mem/lib library Cyril Hrubis
` (8 preceding siblings ...)
2024-12-18 18:45 ` [LTP] [PATCH 09/13] testcases/kernel/mem: Move KSM bits to ksm tests Cyril Hrubis
@ 2024-12-18 18:45 ` Cyril Hrubis
2024-12-27 11:42 ` Petr Vorel
2024-12-18 18:45 ` [LTP] [PATCH 11/13] mem/vma: Remove mem/lib dependency Cyril Hrubis
` (3 subsequent siblings)
13 siblings, 1 reply; 41+ messages in thread
From: Cyril Hrubis @ 2024-12-18 18:45 UTC (permalink / raw)
To: ltp
The test does not use the library at all!
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
testcases/kernel/mem/swapping/Makefile | 1 -
testcases/kernel/mem/swapping/swapping01.c | 2 +-
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/testcases/kernel/mem/swapping/Makefile b/testcases/kernel/mem/swapping/Makefile
index dd55fb8dc..d7ddac44c 100644
--- a/testcases/kernel/mem/swapping/Makefile
+++ b/testcases/kernel/mem/swapping/Makefile
@@ -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
diff --git a/testcases/kernel/mem/swapping/swapping01.c b/testcases/kernel/mem/swapping/swapping01.c
index 79dd2b4d5..bd1f6cc19 100644
--- a/testcases/kernel/mem/swapping/swapping01.c
+++ b/testcases/kernel/mem/swapping/swapping01.c
@@ -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
--
2.45.2
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [LTP] [PATCH 11/13] mem/vma: Remove mem/lib dependency
2024-12-18 18:45 [LTP] [PATCH 00/13] Get rid of testcases/kernel/mem/lib library Cyril Hrubis
` (9 preceding siblings ...)
2024-12-18 18:45 ` [LTP] [PATCH 10/13] mem/swapping: Remove mem/lib refrence Cyril Hrubis
@ 2024-12-18 18:45 ` Cyril Hrubis
2024-12-27 11:44 ` Petr Vorel
2024-12-18 18:45 ` [LTP] [PATCH 12/13] mem/hugetlb: Remove mem/lib depenency Cyril Hrubis
` (2 subsequent siblings)
13 siblings, 1 reply; 41+ messages in thread
From: Cyril Hrubis @ 2024-12-18 18:45 UTC (permalink / raw)
To: ltp
The test does just use the testcases/lib/ instead.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
testcases/kernel/mem/vma/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/testcases/kernel/mem/vma/Makefile b/testcases/kernel/mem/vma/Makefile
index 057091e16..badec593f 100644
--- a/testcases/kernel/mem/vma/Makefile
+++ b/testcases/kernel/mem/vma/Makefile
@@ -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
--
2.45.2
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [LTP] [PATCH 12/13] mem/hugetlb: Remove mem/lib depenency
2024-12-18 18:45 [LTP] [PATCH 00/13] Get rid of testcases/kernel/mem/lib library Cyril Hrubis
` (10 preceding siblings ...)
2024-12-18 18:45 ` [LTP] [PATCH 11/13] mem/vma: Remove mem/lib dependency Cyril Hrubis
@ 2024-12-18 18:45 ` Cyril Hrubis
2024-12-27 11:47 ` Petr Vorel
2024-12-18 18:45 ` [LTP] [PATCH 13/13] testcases/kernel/mem: Remove library Cyril Hrubis
2024-12-18 18:58 ` [LTP] [PATCH 00/13] Get rid of testcases/kernel/mem/lib library Petr Vorel
13 siblings, 1 reply; 41+ messages in thread
From: Cyril Hrubis @ 2024-12-18 18:45 UTC (permalink / raw)
To: ltp
The last bit used from the library PATH_SHMMAX macro.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
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(-)
diff --git a/testcases/kernel/mem/hugetlb/Makefile.inc b/testcases/kernel/mem/hugetlb/Makefile.inc
index 9a4aa8795..b272e62a8 100644
--- a/testcases/kernel/mem/hugetlb/Makefile.inc
+++ b/testcases/kernel/mem/hugetlb/Makefile.inc
@@ -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
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap05.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap05.c
index d5983fc55..75f28102d 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap05.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap05.c
@@ -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__
diff --git a/testcases/kernel/mem/hugetlb/lib/Makefile b/testcases/kernel/mem/hugetlb/lib/Makefile
index ceccd2615..45606b17f 100644
--- a/testcases/kernel/mem/hugetlb/lib/Makefile
+++ b/testcases/kernel/mem/hugetlb/lib/Makefile
@@ -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
diff --git a/testcases/kernel/mem/hugetlb/lib/hugetlb.h b/testcases/kernel/mem/hugetlb/lib/hugetlb.h
index abc88e25e..22975c99a 100644
--- a/testcases/kernel/mem/hugetlb/lib/hugetlb.h
+++ b/testcases/kernel/mem/hugetlb/lib/hugetlb.h
@@ -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() */
--
2.45.2
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [LTP] [PATCH 13/13] testcases/kernel/mem: Remove library
2024-12-18 18:45 [LTP] [PATCH 00/13] Get rid of testcases/kernel/mem/lib library Cyril Hrubis
` (11 preceding siblings ...)
2024-12-18 18:45 ` [LTP] [PATCH 12/13] mem/hugetlb: Remove mem/lib depenency Cyril Hrubis
@ 2024-12-18 18:45 ` Cyril Hrubis
2024-12-27 11:48 ` Petr Vorel
2024-12-18 18:58 ` [LTP] [PATCH 00/13] Get rid of testcases/kernel/mem/lib library Petr Vorel
13 siblings, 1 reply; 41+ messages in thread
From: Cyril Hrubis @ 2024-12-18 18:45 UTC (permalink / raw)
To: ltp
Now that the last bits of the library are unused we can remove it
safely.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
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
diff --git a/testcases/kernel/mem/include/libmem.mk b/testcases/kernel/mem/include/libmem.mk
deleted file mode 100644
index b6d45f0fc..000000000
--- a/testcases/kernel/mem/include/libmem.mk
+++ /dev/null
@@ -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
diff --git a/testcases/kernel/mem/include/mem.h b/testcases/kernel/mem/include/mem.h
deleted file mode 100644
index 25389f34c..000000000
--- a/testcases/kernel/mem/include/mem.h
+++ /dev/null
@@ -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
diff --git a/testcases/kernel/mem/lib/Makefile b/testcases/kernel/mem/lib/Makefile
deleted file mode 100644
index d4624e9b0..000000000
--- a/testcases/kernel/mem/lib/Makefile
+++ /dev/null
@@ -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
diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c
deleted file mode 100644
index 4e5c0b873..000000000
--- a/testcases/kernel/mem/lib/mem.c
+++ /dev/null
@@ -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 */
-
--
2.45.2
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 41+ messages in thread
* Re: [LTP] [PATCH 00/13] Get rid of testcases/kernel/mem/lib library
2024-12-18 18:45 [LTP] [PATCH 00/13] Get rid of testcases/kernel/mem/lib library Cyril Hrubis
` (12 preceding siblings ...)
2024-12-18 18:45 ` [LTP] [PATCH 13/13] testcases/kernel/mem: Remove library Cyril Hrubis
@ 2024-12-18 18:58 ` Petr Vorel
13 siblings, 0 replies; 41+ messages in thread
From: Petr Vorel @ 2024-12-18 18:58 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi Cyril,
> 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
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
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [LTP] [PATCH 09/13] testcases/kernel/mem: Move KSM bits to ksm tests
2024-12-18 18:45 ` [LTP] [PATCH 09/13] testcases/kernel/mem: Move KSM bits to ksm tests Cyril Hrubis
@ 2024-12-19 2:52 ` Li Wang
2024-12-19 2:55 ` Li Wang
2024-12-19 9:08 ` Cyril Hrubis
2024-12-27 11:15 ` Petr Vorel
` (2 subsequent siblings)
3 siblings, 2 replies; 41+ messages in thread
From: Li Wang @ 2024-12-19 2:52 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
On Thu, Dec 19, 2024 at 2:48 AM Cyril Hrubis <chrubis@suse.cz> wrote:
> Moves the ksm helpers into a ksm/ksm_test.h since these are not used by
> any other but ksm tests.
>
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
> ---
> 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?
> testcases/kernel/mem/lib/mem.c | 287 ------------------------
> 12 files changed, 312 insertions(+), 301 deletions(-)
> create mode 100644 testcases/kernel/mem/ksm/ksm_test.h
>
> diff --git a/testcases/kernel/mem/include/mem.h
> b/testcases/kernel/mem/include/mem.h
> index 5ebedc175..25389f34c 100644
> --- a/testcases/kernel/mem/include/mem.h
> +++ b/testcases/kernel/mem/include/mem.h
> @@ -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"
> diff --git a/testcases/kernel/mem/ksm/Makefile
> b/testcases/kernel/mem/ksm/Makefile
> index 6aba73e61..2af02a274 100644
> --- a/testcases/kernel/mem/ksm/Makefile
> +++ b/testcases/kernel/mem/ksm/Makefile
> @@ -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
> diff --git a/testcases/kernel/mem/ksm/ksm01.c
> b/testcases/kernel/mem/ksm/ksm01.c
> index e2d3d9e00..a22e4830f 100644
> --- a/testcases/kernel/mem/ksm/ksm01.c
> +++ b/testcases/kernel/mem/ksm/ksm01.c
> @@ -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)
> diff --git a/testcases/kernel/mem/ksm/ksm02.c
> b/testcases/kernel/mem/ksm/ksm02.c
> index a388e82ab..4d1306045 100644
> --- a/testcases/kernel/mem/ksm/ksm02.c
> +++ b/testcases/kernel/mem/ksm/ksm02.c
> @@ -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
> diff --git a/testcases/kernel/mem/ksm/ksm03.c
> b/testcases/kernel/mem/ksm/ksm03.c
> index cff74700d..78844b30e 100644
> --- a/testcases/kernel/mem/ksm/ksm03.c
> +++ b/testcases/kernel/mem/ksm/ksm03.c
> @@ -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)
> diff --git a/testcases/kernel/mem/ksm/ksm04.c
> b/testcases/kernel/mem/ksm/ksm04.c
> index 31f3ff2eb..8465ee230 100644
> --- a/testcases/kernel/mem/ksm/ksm04.c
> +++ b/testcases/kernel/mem/ksm/ksm04.c
> @@ -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
> diff --git a/testcases/kernel/mem/ksm/ksm05.c
> b/testcases/kernel/mem/ksm/ksm05.c
> index 1d9d9699a..025dffc09 100644
> --- a/testcases/kernel/mem/ksm/ksm05.c
> +++ b/testcases/kernel/mem/ksm/ksm05.c
> @@ -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
>
> diff --git a/testcases/kernel/mem/ksm/ksm06.c
> b/testcases/kernel/mem/ksm/ksm06.c
> index 80fdf1e47..09a54fd18 100644
> --- a/testcases/kernel/mem/ksm/ksm06.c
> +++ b/testcases/kernel/mem/ksm/ksm06.c
> @@ -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>
> diff --git a/testcases/kernel/mem/ksm/ksm07.c
> b/testcases/kernel/mem/ksm/ksm07.c
> index 619bd7b55..24b393283 100644
> --- a/testcases/kernel/mem/ksm/ksm07.c
> +++ b/testcases/kernel/mem/ksm/ksm07.c
> @@ -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
> diff --git a/testcases/kernel/mem/ksm/ksm_common.h
> b/testcases/kernel/mem/ksm/ksm_common.h
> index 43ea8f8c2..d677b224d 100644
> --- a/testcases/kernel/mem/ksm/ksm_common.h
> +++ b/testcases/kernel/mem/ksm/ksm_common.h
> @@ -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__ */
> diff --git a/testcases/kernel/mem/ksm/ksm_test.h
> b/testcases/kernel/mem/ksm/ksm_test.h
> new file mode 100644
> index 000000000..ebce8197c
> --- /dev/null
> +++ b/testcases/kernel/mem/ksm/ksm_test.h
> @@ -0,0 +1,299 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) Linux Test Project, 2011-2021
> + * Copyright (c) Cyril Hrubis <chrubis@suse.cz> 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,
> + 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,
> + 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
> "
> + "%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,
> + 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'",
> + child_num, size, ksm_merge_data.data);
> +
> + } else {
> + tst_res(TINFO, "child %d allocates %d TST_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 * 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,
> + 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);
> + 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},
> + };
> + struct ksm_merge_data ksm_data1[] = {
> + {'a', size*TST_MB}, {'b', size*TST_MB}, {'d', size*TST_MB},
> {'d', size*TST_MB-1},
> + };
> + struct ksm_merge_data ksm_data2[] = {
> + {'a', size*TST_MB}, {'a', size*TST_MB}, {'d', size*TST_MB},
> {'d', size*TST_MB},
> + };
> +
> + 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
> */
> + 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]);
> + 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);
> + }
> +
> + SAFE_FILE_PRINTF(PATH_KSM "run", "1");
> + SAFE_FILE_PRINTF(PATH_KSM "pages_to_scan", "%ld", size * pages *
> num);
> + 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);
> +
> + 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);
> +
> + 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);
> +
> + 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);
> +
> + 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_ */
> diff --git a/testcases/kernel/mem/lib/mem.c
> b/testcases/kernel/mem/lib/mem.c
> index f3b844994..4e5c0b873 100644
> --- a/testcases/kernel/mem/lib/mem.c
> +++ b/testcases/kernel/mem/lib/mem.c
> @@ -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,
> - 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
> "
> - "%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,
> - 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},
> - };
> - struct ksm_merge_data ksm_data1[] = {
> - {'a', size*MB}, {'b', size*MB}, {'d', size*MB}, {'d',
> size*MB-1},
> - };
> - struct ksm_merge_data ksm_data2[] = {
> - {'a', size*MB}, {'a', size*MB}, {'d', size*MB}, {'d',
> size*MB},
> - };
> -
> - 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
> */
> - 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]);
> - 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);
> - }
> -
> - SAFE_FILE_PRINTF(PATH_KSM "run", "1");
> - SAFE_FILE_PRINTF(PATH_KSM "pages_to_scan", "%ld", size * pages *
> num);
> - 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);
> -
> - 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);
> -
> - 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);
> -
> - 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);
> -
> - 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
>
>
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [LTP] [PATCH 09/13] testcases/kernel/mem: Move KSM bits to ksm tests
2024-12-19 2:52 ` Li Wang
@ 2024-12-19 2:55 ` Li Wang
2024-12-19 9:08 ` Cyril Hrubis
1 sibling, 0 replies; 41+ messages in thread
From: Li Wang @ 2024-12-19 2:55 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Li Wang <liwang@redhat.com> wrote:
> 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?
>
Sorry for the typo: tst_helper.h ---> ksm_helper.h
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [LTP] [PATCH 01/13] lib: tst_sys_conf: Add two functions
2024-12-18 18:45 ` [LTP] [PATCH 01/13] lib: tst_sys_conf: Add two functions Cyril Hrubis
@ 2024-12-19 3:10 ` Li Wang
2024-12-27 9:04 ` Petr Vorel
1 sibling, 0 replies; 41+ messages in thread
From: Li Wang @ 2024-12-19 3:10 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
On Thu, Dec 19, 2024 at 2:46 AM Cyril Hrubis <chrubis@suse.cz> wrote:
> 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.
>
Thanks for doing this, all touched tests pass on RHEL 9&10 from my side.
Reviewed-by: Li Wang <liwang@redhat.com>
>
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
> ---
> 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(-)
>
> diff --git a/include/tst_sys_conf.h b/include/tst_sys_conf.h
> index 4c85767be..53e8c5ea8 100644
> --- a/include/tst_sys_conf.h
> +++ b/include/tst_sys_conf.h
> @@ -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
> diff --git a/lib/tst_sys_conf.c b/lib/tst_sys_conf.c
> index c0981dcb1..f962fc124 100644
> --- a/lib/tst_sys_conf.c
> +++ b/lib/tst_sys_conf.c
> @@ -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);
> + }
> +
> +}
> diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
> b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
> index 8ad745d5b..0d7bbf64f 100644
> --- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
> +++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
> @@ -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)
> diff --git a/testcases/kernel/mem/include/mem.h
> b/testcases/kernel/mem/include/mem.h
> index cdc3ca146..865d2c7e8 100644
> --- a/testcases/kernel/mem/include/mem.h
> +++ b/testcases/kernel/mem/include/mem.h
> @@ -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);
>
> diff --git a/testcases/kernel/mem/lib/mem.c
> b/testcases/kernel/mem/lib/mem.c
> index fbfeef026..3e0f5d1bb 100644
> --- a/testcases/kernel/mem/lib/mem.c
> +++ b/testcases/kernel/mem/lib/mem.c
> @@ -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;
> diff --git a/testcases/kernel/mem/oom/oom01.c
> b/testcases/kernel/mem/oom/oom01.c
> index 903785f93..157ca84b6 100644
> --- a/testcases/kernel/mem/oom/oom01.c
> +++ b/testcases/kernel/mem/oom/oom01.c
> @@ -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},
> {}
> },
> };
> diff --git a/testcases/kernel/mem/tunable/Makefile
> b/testcases/kernel/mem/tunable/Makefile
> index 80d64bb4a..e0014e683 100644
> --- a/testcases/kernel/mem/tunable/Makefile
> +++ b/testcases/kernel/mem/tunable/Makefile
> @@ -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
> diff --git a/testcases/kernel/mem/tunable/max_map_count.c
> b/testcases/kernel/mem/tunable/max_map_count.c
> index f33095473..71a7bbee0 100644
> --- a/testcases/kernel/mem/tunable/max_map_count.c
> +++ b/testcases/kernel/mem/tunable/max_map_count.c
> @@ -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},
> {}
> },
> };
> diff --git a/testcases/kernel/mem/tunable/min_free_kbytes.c
> b/testcases/kernel/mem/tunable/min_free_kbytes.c
> index 19da409e8..5274bb3bf 100644
> --- a/testcases/kernel/mem/tunable/min_free_kbytes.c
> +++ b/testcases/kernel/mem/tunable/min_free_kbytes.c
> @@ -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},
> {}
> },
> };
> diff --git a/testcases/kernel/mem/tunable/overcommit_memory.c
> b/testcases/kernel/mem/tunable/overcommit_memory.c
> index d055dd18f..b5beebbcd 100644
> --- a/testcases/kernel/mem/tunable/overcommit_memory.c
> +++ b/testcases/kernel/mem/tunable/overcommit_memory.c
> @@ -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
>
>
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [LTP] [PATCH 09/13] testcases/kernel/mem: Move KSM bits to ksm tests
2024-12-19 2:52 ` Li Wang
2024-12-19 2:55 ` Li Wang
@ 2024-12-19 9:08 ` Cyril Hrubis
2024-12-19 9:11 ` Li Wang
1 sibling, 1 reply; 41+ messages in thread
From: Cyril Hrubis @ 2024-12-19 9:08 UTC (permalink / raw)
To: Li Wang; +Cc: ltp
Hi!
> We do have another tst_helper.h under testcases/kernel/include/,
> maybe we can combine it with ksm_test.h together?
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.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [LTP] [PATCH 09/13] testcases/kernel/mem: Move KSM bits to ksm tests
2024-12-19 9:08 ` Cyril Hrubis
@ 2024-12-19 9:11 ` Li Wang
0 siblings, 0 replies; 41+ messages in thread
From: Li Wang @ 2024-12-19 9:11 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
On Thu, Dec 19, 2024 at 5:09 PM Cyril Hrubis <chrubis@suse.cz> wrote:
> Hi!
> > We do have another tst_helper.h under testcases/kernel/include/,
> > maybe we can combine it with ksm_test.h together?
>
> 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.
>
Sounds good. Thanks.
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [LTP] [PATCH 02/13] lib: Replace path_exist() with tst_path_exists()
2024-12-18 18:45 ` [LTP] [PATCH 02/13] lib: Replace path_exist() with tst_path_exists() Cyril Hrubis
@ 2024-12-19 14:31 ` Petr Vorel
2024-12-19 15:04 ` Cyril Hrubis
0 siblings, 1 reply; 41+ messages in thread
From: Petr Vorel @ 2024-12-19 14:31 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi Cyril,
> Move and rename the path_exist() function from
> testcases/kernel/mem/lib/ to the to level library.
+1
> This removes mem.h dependency from mem/cpuset/ test.
+1
> diff --git a/include/tst_fs.h b/include/tst_fs.h
> index 835f3511c..f6ac6a40d 100644
> --- a/include/tst_fs.h
> +++ b/include/tst_fs.h
> @@ -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?
> + *
> + * @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.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [LTP] [PATCH 02/13] lib: Replace path_exist() with tst_path_exists()
2024-12-19 14:31 ` Petr Vorel
@ 2024-12-19 15:04 ` Cyril Hrubis
2024-12-20 8:02 ` Petr Vorel
0 siblings, 1 reply; 41+ messages in thread
From: Cyril Hrubis @ 2024-12-19 15:04 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
Hi!
> > diff --git a/include/tst_fs.h b/include/tst_fs.h
> > index 835f3511c..f6ac6a40d 100644
> > --- a/include/tst_fs.h
> > +++ b/include/tst_fs.h
> > @@ -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.
> > + *
> > + * @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.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [LTP] [PATCH 02/13] lib: Replace path_exist() with tst_path_exists()
2024-12-19 15:04 ` Cyril Hrubis
@ 2024-12-20 8:02 ` Petr Vorel
0 siblings, 0 replies; 41+ messages in thread
From: Petr Vorel @ 2024-12-20 8:02 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
> Hi!
> > > diff --git a/include/tst_fs.h b/include/tst_fs.h
> > > index 835f3511c..f6ac6a40d 100644
> > > --- a/include/tst_fs.h
> > > +++ b/include/tst_fs.h
> > > @@ -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.
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).
> > > + *
> > > + * @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
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [LTP] [PATCH 01/13] lib: tst_sys_conf: Add two functions
2024-12-18 18:45 ` [LTP] [PATCH 01/13] lib: tst_sys_conf: Add two functions Cyril Hrubis
2024-12-19 3:10 ` Li Wang
@ 2024-12-27 9:04 ` Petr Vorel
1 sibling, 0 replies; 41+ messages in thread
From: Petr Vorel @ 2024-12-27 9:04 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi Cyril,
> 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.
+1
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Minor formatting notes below.
> +/**
> + * 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'
> + *
> + * 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'
> + * 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.
And here:
include/tst_sys_conf.h:50: [kernel-doc WARN] : no description found for parameter 'path'
> + */
> +#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
> diff --git a/lib/tst_sys_conf.c b/lib/tst_sys_conf.c
> index c0981dcb1..f962fc124 100644
> --- a/lib/tst_sys_conf.c
> +++ b/lib/tst_sys_conf.c
> @@ -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
> +{
> + 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;
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
> +
> + 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
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [LTP] [PATCH 03/13] lib: Add tst_mapping_in_range()
2024-12-18 18:45 ` [LTP] [PATCH 03/13] lib: Add tst_mapping_in_range() Cyril Hrubis
@ 2024-12-27 10:25 ` Petr Vorel
0 siblings, 0 replies; 41+ messages in thread
From: Petr Vorel @ 2024-12-27 10:25 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
> This 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.
+1
> +/**
> + * 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.
> + *
> + * @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__ */
> diff --git a/lib/tst_memutils.c b/lib/tst_memutils.c
> index e33f19d29..e49684ba1 100644
> --- a/lib/tst_memutils.c
> +++ b/lib/tst_memutils.c
> @@ -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");
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.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [LTP] [PATCH 04/13] testcases/kernel/mem: Move get_a_numa_node()
2024-12-18 18:45 ` [LTP] [PATCH 04/13] testcases/kernel/mem: Move get_a_numa_node() Cyril Hrubis
@ 2024-12-27 10:27 ` Petr Vorel
0 siblings, 0 replies; 41+ messages in thread
From: Petr Vorel @ 2024-12-27 10:27 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi Cyril,
> Move get_a_numa_node() from the library to the ksm_common.h since the
> function is used only by the ksm testcases.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [LTP] [PATCH 05/13] testcases/kernel/mem: Move update_shm_size()
2024-12-18 18:45 ` [LTP] [PATCH 05/13] testcases/kernel/mem: Move update_shm_size() Cyril Hrubis
@ 2024-12-27 10:34 ` Petr Vorel
0 siblings, 0 replies; 41+ messages in thread
From: Petr Vorel @ 2024-12-27 10:34 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi Cyril,
> Move update_shm_size() from the lib to the libhugetlb.c since 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.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [LTP] [PATCH 06/13] testcases/kernel/mem: Move check_hugepage() + PATH_THP
2024-12-18 18:45 ` [LTP] [PATCH 06/13] testcases/kernel/mem: Move check_hugepage() + PATH_THP Cyril Hrubis
@ 2024-12-27 10:48 ` Petr Vorel
2025-02-07 17:00 ` Cyril Hrubis
0 siblings, 1 reply; 41+ messages in thread
From: Petr Vorel @ 2024-12-27 10:48 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi Cyril,
> +#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, ...).
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [LTP] [PATCH 07/13] testcases/kernel/mem: Move NUMA bits to numa_helper.h
2024-12-18 18:45 ` [LTP] [PATCH 07/13] testcases/kernel/mem: Move NUMA bits to numa_helper.h Cyril Hrubis
@ 2024-12-27 11:01 ` Petr Vorel
2024-12-27 11:09 ` Petr Vorel
1 sibling, 0 replies; 41+ messages in thread
From: Petr Vorel @ 2024-12-27 11:01 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi Cyril,
...
> +void write_node_cpusets(const struct tst_cg_group *cg, long nd);
> +
> #endif /* NUMA_HELPER_H */
> diff --git a/testcases/kernel/lib/numa_cpuset.c b/testcases/kernel/lib/numa_cpuset.c
> new file mode 100644
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.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [LTP] [PATCH 08/13] testcases/kernel/mem: Move oom() fucntions to oom tests
2024-12-18 18:45 ` [LTP] [PATCH 08/13] testcases/kernel/mem: Move oom() fucntions to oom tests Cyril Hrubis
@ 2024-12-27 11:06 ` Petr Vorel
0 siblings, 0 replies; 41+ messages in thread
From: Petr Vorel @ 2024-12-27 11:06 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi Cyril,
> Functions that are used only by the oom testcases are moved into
> oom/oom.h.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [LTP] [PATCH 07/13] testcases/kernel/mem: Move NUMA bits to numa_helper.h
2024-12-18 18:45 ` [LTP] [PATCH 07/13] testcases/kernel/mem: Move NUMA bits to numa_helper.h Cyril Hrubis
2024-12-27 11:01 ` Petr Vorel
@ 2024-12-27 11:09 ` Petr Vorel
1 sibling, 0 replies; 41+ messages in thread
From: Petr Vorel @ 2024-12-27 11:09 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi Cyril,
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [LTP] [PATCH 09/13] testcases/kernel/mem: Move KSM bits to ksm tests
2024-12-18 18:45 ` [LTP] [PATCH 09/13] testcases/kernel/mem: Move KSM bits to ksm tests Cyril Hrubis
2024-12-19 2:52 ` Li Wang
@ 2024-12-27 11:15 ` Petr Vorel
2024-12-27 11:36 ` Petr Vorel
2024-12-27 11:37 ` Petr Vorel
3 siblings, 0 replies; 41+ messages in thread
From: Petr Vorel @ 2024-12-27 11:15 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi Cyril,
> --- /dev/null
> +++ b/testcases/kernel/mem/ksm/ksm_test.h
> @@ -0,0 +1,299 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) Linux Test Project, 2011-2021
> + * Copyright (c) Cyril Hrubis <chrubis@suse.cz> 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);
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
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [LTP] [PATCH 09/13] testcases/kernel/mem: Move KSM bits to ksm tests
2024-12-18 18:45 ` [LTP] [PATCH 09/13] testcases/kernel/mem: Move KSM bits to ksm tests Cyril Hrubis
2024-12-19 2:52 ` Li Wang
2024-12-27 11:15 ` Petr Vorel
@ 2024-12-27 11:36 ` Petr Vorel
2025-02-10 11:17 ` Cyril Hrubis
2024-12-27 11:37 ` Petr Vorel
3 siblings, 1 reply; 41+ messages in thread
From: Petr Vorel @ 2024-12-27 11:36 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi Cyril,
> new file mode 100644
> index 000000000..ebce8197c
> --- /dev/null
> +++ b/testcases/kernel/mem/ksm/ksm_test.h
...
> +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.
> + 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'",
> + 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'"
> + " except one page with 'e'",
> + child_num, size, ksm_merge_data.data);
> + }
Otherwise LGTM.
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [LTP] [PATCH 09/13] testcases/kernel/mem: Move KSM bits to ksm tests
2024-12-18 18:45 ` [LTP] [PATCH 09/13] testcases/kernel/mem: Move KSM bits to ksm tests Cyril Hrubis
` (2 preceding siblings ...)
2024-12-27 11:36 ` Petr Vorel
@ 2024-12-27 11:37 ` Petr Vorel
3 siblings, 0 replies; 41+ messages in thread
From: Petr Vorel @ 2024-12-27 11:37 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Reviewed-by: Petr Vorel <pvorel@suse.cz>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [LTP] [PATCH 10/13] mem/swapping: Remove mem/lib refrence
2024-12-18 18:45 ` [LTP] [PATCH 10/13] mem/swapping: Remove mem/lib refrence Cyril Hrubis
@ 2024-12-27 11:42 ` Petr Vorel
0 siblings, 0 replies; 41+ messages in thread
From: Petr Vorel @ 2024-12-27 11:42 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi Cyril,
> The test does not use the library at all!
Interesting, it looks like it has never used it.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [LTP] [PATCH 11/13] mem/vma: Remove mem/lib dependency
2024-12-18 18:45 ` [LTP] [PATCH 11/13] mem/vma: Remove mem/lib dependency Cyril Hrubis
@ 2024-12-27 11:44 ` Petr Vorel
0 siblings, 0 replies; 41+ messages in thread
From: Petr Vorel @ 2024-12-27 11:44 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi Cyril,
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [LTP] [PATCH 12/13] mem/hugetlb: Remove mem/lib depenency
2024-12-18 18:45 ` [LTP] [PATCH 12/13] mem/hugetlb: Remove mem/lib depenency Cyril Hrubis
@ 2024-12-27 11:47 ` Petr Vorel
0 siblings, 0 replies; 41+ messages in thread
From: Petr Vorel @ 2024-12-27 11:47 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi Cyril,
> The last bit used from the library PATH_SHMMAX macro.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [LTP] [PATCH 13/13] testcases/kernel/mem: Remove library
2024-12-18 18:45 ` [LTP] [PATCH 13/13] testcases/kernel/mem: Remove library Cyril Hrubis
@ 2024-12-27 11:48 ` Petr Vorel
0 siblings, 0 replies; 41+ messages in thread
From: Petr Vorel @ 2024-12-27 11:48 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi Cyril,
> Now that the last bits of the library are unused we can remove it
> safely.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Thanks for whole cleanup.
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [LTP] [PATCH 06/13] testcases/kernel/mem: Move check_hugepage() + PATH_THP
2024-12-27 10:48 ` Petr Vorel
@ 2025-02-07 17:00 ` Cyril Hrubis
2025-02-10 9:16 ` Petr Vorel
0 siblings, 1 reply; 41+ messages in thread
From: Cyril Hrubis @ 2025-02-07 17:00 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
Hi!
> > +#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, ...).
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...
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [LTP] [PATCH 06/13] testcases/kernel/mem: Move check_hugepage() + PATH_THP
2025-02-07 17:00 ` Cyril Hrubis
@ 2025-02-10 9:16 ` Petr Vorel
0 siblings, 0 replies; 41+ messages in thread
From: Petr Vorel @ 2025-02-10 9:16 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
> Hi!
> > > +#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, ...).
> 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...
Yeah. .needs_paths sounds reasonable + use flags we already have (TST_SR_TCONF,
TST_SR_TBROK, TST_SR_SKIP).
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [LTP] [PATCH 09/13] testcases/kernel/mem: Move KSM bits to ksm tests
2024-12-27 11:36 ` Petr Vorel
@ 2025-02-10 11:17 ` Cyril Hrubis
0 siblings, 0 replies; 41+ messages in thread
From: Cyril Hrubis @ 2025-02-10 11:17 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
Hi!
> > new file mode 100644
> > index 000000000..ebce8197c
> > --- /dev/null
> > +++ b/testcases/kernel/mem/ksm/ksm_test.h
> ...
> > +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.
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.
> > + 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'",
>
> > + 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'"
> > + " except one page with 'e'",
> > + child_num, size, ksm_merge_data.data);
> > + }
Ah, sorry, that is a result from blindly doing sed s/...
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 41+ messages in thread
end of thread, other threads:[~2025-02-10 11:17 UTC | newest]
Thread overview: 41+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-18 18:45 [LTP] [PATCH 00/13] Get rid of testcases/kernel/mem/lib library Cyril Hrubis
2024-12-18 18:45 ` [LTP] [PATCH 01/13] lib: tst_sys_conf: Add two functions Cyril Hrubis
2024-12-19 3:10 ` Li Wang
2024-12-27 9:04 ` Petr Vorel
2024-12-18 18:45 ` [LTP] [PATCH 02/13] lib: Replace path_exist() with tst_path_exists() Cyril Hrubis
2024-12-19 14:31 ` Petr Vorel
2024-12-19 15:04 ` Cyril Hrubis
2024-12-20 8:02 ` Petr Vorel
2024-12-18 18:45 ` [LTP] [PATCH 03/13] lib: Add tst_mapping_in_range() Cyril Hrubis
2024-12-27 10:25 ` Petr Vorel
2024-12-18 18:45 ` [LTP] [PATCH 04/13] testcases/kernel/mem: Move get_a_numa_node() Cyril Hrubis
2024-12-27 10:27 ` Petr Vorel
2024-12-18 18:45 ` [LTP] [PATCH 05/13] testcases/kernel/mem: Move update_shm_size() Cyril Hrubis
2024-12-27 10:34 ` Petr Vorel
2024-12-18 18:45 ` [LTP] [PATCH 06/13] testcases/kernel/mem: Move check_hugepage() + PATH_THP Cyril Hrubis
2024-12-27 10:48 ` Petr Vorel
2025-02-07 17:00 ` Cyril Hrubis
2025-02-10 9:16 ` Petr Vorel
2024-12-18 18:45 ` [LTP] [PATCH 07/13] testcases/kernel/mem: Move NUMA bits to numa_helper.h Cyril Hrubis
2024-12-27 11:01 ` Petr Vorel
2024-12-27 11:09 ` Petr Vorel
2024-12-18 18:45 ` [LTP] [PATCH 08/13] testcases/kernel/mem: Move oom() fucntions to oom tests Cyril Hrubis
2024-12-27 11:06 ` Petr Vorel
2024-12-18 18:45 ` [LTP] [PATCH 09/13] testcases/kernel/mem: Move KSM bits to ksm tests Cyril Hrubis
2024-12-19 2:52 ` Li Wang
2024-12-19 2:55 ` Li Wang
2024-12-19 9:08 ` Cyril Hrubis
2024-12-19 9:11 ` Li Wang
2024-12-27 11:15 ` Petr Vorel
2024-12-27 11:36 ` Petr Vorel
2025-02-10 11:17 ` Cyril Hrubis
2024-12-27 11:37 ` Petr Vorel
2024-12-18 18:45 ` [LTP] [PATCH 10/13] mem/swapping: Remove mem/lib refrence Cyril Hrubis
2024-12-27 11:42 ` Petr Vorel
2024-12-18 18:45 ` [LTP] [PATCH 11/13] mem/vma: Remove mem/lib dependency Cyril Hrubis
2024-12-27 11:44 ` Petr Vorel
2024-12-18 18:45 ` [LTP] [PATCH 12/13] mem/hugetlb: Remove mem/lib depenency Cyril Hrubis
2024-12-27 11:47 ` Petr Vorel
2024-12-18 18:45 ` [LTP] [PATCH 13/13] testcases/kernel/mem: Remove library Cyril Hrubis
2024-12-27 11:48 ` Petr Vorel
2024-12-18 18:58 ` [LTP] [PATCH 00/13] Get rid of testcases/kernel/mem/lib library Petr Vorel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox