* [LTP] [PATCH v2 00/13]
@ 2025-02-10 11:31 Cyril Hrubis
2025-02-10 11:32 ` [LTP] [PATCH v2 01/13] lib: tst_sys_conf: Add two functions Cyril Hrubis
` (14 more replies)
0 siblings, 15 replies; 23+ messages in thread
From: Cyril Hrubis @ 2025-02-10 11:31 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.
v2:
- Rebased the patchset
- Fixed doc comments in headers
(decided to add short descriptions for functions after all)
- Fixed TST_MB in strings
- Fixed warnings introduced in ksm tests
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 | 32 +
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 | 302 ++++++++
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, 926 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.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* [LTP] [PATCH v2 01/13] lib: tst_sys_conf: Add two functions
2025-02-10 11:31 [LTP] [PATCH v2 00/13] Cyril Hrubis
@ 2025-02-10 11:32 ` Cyril Hrubis
2025-02-10 11:32 ` [LTP] [PATCH v2 02/13] lib: Replace path_exist() with tst_path_exists() Cyril Hrubis
` (13 subsequent siblings)
14 siblings, 0 replies; 23+ messages in thread
From: Cyril Hrubis @ 2025-02-10 11:32 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>
Reviewed-by: Li Wang <liwang@redhat.com>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
---
include/tst_sys_conf.h | 32 +++++++++++++++++++
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, 105 insertions(+), 67 deletions(-)
diff --git a/include/tst_sys_conf.h b/include/tst_sys_conf.h
index 6bbf39672..a221a9a0d 100644
--- a/include/tst_sys_conf.h
+++ b/include/tst_sys_conf.h
@@ -30,4 +30,36 @@ void tst_sys_conf_dump(void);
int tst_read_bool_sys_param(const char *filename);
+/**
+ * TST_SYS_CONF_LONG_SET() - Writes a long int into a sys or proc file.
+ *
+ * @path: A path to a sysfs or a procfs file.
+ * @val: A long int value to be written to the file.
+ * @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, ...).
+ *
+ * Sets a sysfs or procfs file and optionally checks that it was set correctly.
+ */
+#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() - Reads a long int from sys or proc file.
+ *
+ * @path: A path to a sysfs or a procfs file.
+ * return: A value read from the file converted into a long.
+ *
+ * Gets a sysfs or procfs file value and converts it to long.
+ */
+#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 91203ea9e..80cd83569 100644
--- a/lib/tst_sys_conf.c
+++ b/lib/tst_sys_conf.c
@@ -180,3 +180,32 @@ int tst_read_bool_sys_param(const char *filename)
/* Assume that any other value than 0 or N means the param is enabled */
return 1;
}
+
+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 ddb904459..4bca37963 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 65b467d60..68caf1b00 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.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [LTP] [PATCH v2 02/13] lib: Replace path_exist() with tst_path_exists()
2025-02-10 11:31 [LTP] [PATCH v2 00/13] Cyril Hrubis
2025-02-10 11:32 ` [LTP] [PATCH v2 01/13] lib: tst_sys_conf: Add two functions Cyril Hrubis
@ 2025-02-10 11:32 ` Cyril Hrubis
2025-02-10 11:53 ` pvorel
2025-02-10 11:32 ` [LTP] [PATCH v2 03/13] lib: Add tst_mapping_in_range() Cyril Hrubis
` (12 subsequent siblings)
14 siblings, 1 reply; 23+ messages in thread
From: Cyril Hrubis @ 2025-02-10 11:32 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>
Reviewed-by: Petr Vorel <pvorel@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 | 5 +++--
testcases/kernel/mem/include/mem.h | 1 -
testcases/kernel/mem/lib/mem.c | 18 +++---------------
6 files changed, 40 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..19c240e07 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() - checks if 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.
+ */
+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..e70c7c7dc 100644
--- a/testcases/kernel/mem/cpuset/cpuset01.c
+++ b/testcases/kernel/mem/cpuset/cpuset01.c
@@ -30,7 +30,8 @@
#include <numaif.h>
#endif
-#include "mem.h"
+#include "../include/mem.h"
+#include "tst_test.h"
#include "numa_helper.h"
#ifdef HAVE_NUMA_V2
@@ -164,7 +165,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.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [LTP] [PATCH v2 03/13] lib: Add tst_mapping_in_range()
2025-02-10 11:31 [LTP] [PATCH v2 00/13] Cyril Hrubis
2025-02-10 11:32 ` [LTP] [PATCH v2 01/13] lib: tst_sys_conf: Add two functions Cyril Hrubis
2025-02-10 11:32 ` [LTP] [PATCH v2 02/13] lib: Replace path_exist() with tst_path_exists() Cyril Hrubis
@ 2025-02-10 11:32 ` Cyril Hrubis
2025-02-10 11:32 ` [LTP] [PATCH v2 04/13] testcases/kernel/mem: Move get_a_numa_node() Cyril Hrubis
` (11 subsequent siblings)
14 siblings, 0 replies; 23+ messages in thread
From: Cyril Hrubis @ 2025-02-10 11:32 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>
Reviewed-by: Petr Vorel <pvorel@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..57c90c4a9 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() - Returns true if there is a mapping provided 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 06b5f8e08..90539aaeb 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 d262b65b2..d3c43b024 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.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [LTP] [PATCH v2 04/13] testcases/kernel/mem: Move get_a_numa_node()
2025-02-10 11:31 [LTP] [PATCH v2 00/13] Cyril Hrubis
` (2 preceding siblings ...)
2025-02-10 11:32 ` [LTP] [PATCH v2 03/13] lib: Add tst_mapping_in_range() Cyril Hrubis
@ 2025-02-10 11:32 ` Cyril Hrubis
2025-02-10 11:32 ` [LTP] [PATCH v2 05/13] testcases/kernel/mem: Move update_shm_size() Cyril Hrubis
` (10 subsequent siblings)
14 siblings, 0 replies; 23+ messages in thread
From: Cyril Hrubis @ 2025-02-10 11:32 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>
Reviewed-by: Petr Vorel <pvorel@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.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [LTP] [PATCH v2 05/13] testcases/kernel/mem: Move update_shm_size()
2025-02-10 11:31 [LTP] [PATCH v2 00/13] Cyril Hrubis
` (3 preceding siblings ...)
2025-02-10 11:32 ` [LTP] [PATCH v2 04/13] testcases/kernel/mem: Move get_a_numa_node() Cyril Hrubis
@ 2025-02-10 11:32 ` Cyril Hrubis
2025-02-10 11:32 ` [LTP] [PATCH v2 06/13] testcases/kernel/mem: Move check_hugepage() + PATH_THP Cyril Hrubis
` (9 subsequent siblings)
14 siblings, 0 replies; 23+ messages in thread
From: Cyril Hrubis @ 2025-02-10 11:32 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>
Reviewed-by: Petr Vorel <pvorel@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.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [LTP] [PATCH v2 06/13] testcases/kernel/mem: Move check_hugepage() + PATH_THP
2025-02-10 11:31 [LTP] [PATCH v2 00/13] Cyril Hrubis
` (4 preceding siblings ...)
2025-02-10 11:32 ` [LTP] [PATCH v2 05/13] testcases/kernel/mem: Move update_shm_size() Cyril Hrubis
@ 2025-02-10 11:32 ` Cyril Hrubis
2025-02-10 11:32 ` [LTP] [PATCH v2 07/13] testcases/kernel/mem: Move NUMA bits to numa_helper.h Cyril Hrubis
` (8 subsequent siblings)
14 siblings, 0 replies; 23+ messages in thread
From: Cyril Hrubis @ 2025-02-10 11:32 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>
Reviewed-by: Petr Vorel <pvorel@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.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [LTP] [PATCH v2 07/13] testcases/kernel/mem: Move NUMA bits to numa_helper.h
2025-02-10 11:31 [LTP] [PATCH v2 00/13] Cyril Hrubis
` (5 preceding siblings ...)
2025-02-10 11:32 ` [LTP] [PATCH v2 06/13] testcases/kernel/mem: Move check_hugepage() + PATH_THP Cyril Hrubis
@ 2025-02-10 11:32 ` Cyril Hrubis
2025-02-10 11:32 ` [LTP] [PATCH v2 08/13] testcases/kernel/mem: Move oom() fucntions to oom tests Cyril Hrubis
` (7 subsequent siblings)
14 siblings, 0 replies; 23+ messages in thread
From: Cyril Hrubis @ 2025-02-10 11:32 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>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
---
testcases/kernel/include/numa_helper.h | 21 +++++++++
testcases/kernel/lib/numa_cpuset.c | 64 ++++++++++++++++++++++++++
testcases/kernel/mem/cpuset/cpuset01.c | 1 -
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 +-
9 files changed, 89 insertions(+), 86 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/cpuset/cpuset01.c b/testcases/kernel/mem/cpuset/cpuset01.c
index e70c7c7dc..4f4415a18 100644
--- a/testcases/kernel/mem/cpuset/cpuset01.c
+++ b/testcases/kernel/mem/cpuset/cpuset01.c
@@ -30,7 +30,6 @@
#include <numaif.h>
#endif
-#include "../include/mem.h"
#include "tst_test.h"
#include "numa_helper.h"
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 ab0725303..b9e80e813 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 7b478c46d..0e264b10f 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 94e70f3c5..1edde3676 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 16e4018cf..851ec652e 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.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [LTP] [PATCH v2 08/13] testcases/kernel/mem: Move oom() fucntions to oom tests
2025-02-10 11:31 [LTP] [PATCH v2 00/13] Cyril Hrubis
` (6 preceding siblings ...)
2025-02-10 11:32 ` [LTP] [PATCH v2 07/13] testcases/kernel/mem: Move NUMA bits to numa_helper.h Cyril Hrubis
@ 2025-02-10 11:32 ` Cyril Hrubis
2025-02-10 11:32 ` [LTP] [PATCH v2 09/13] testcases/kernel/mem: Move KSM bits to ksm tests Cyril Hrubis
` (6 subsequent siblings)
14 siblings, 0 replies; 23+ messages in thread
From: Cyril Hrubis @ 2025-02-10 11:32 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>
Reviewed-by: Petr Vorel <pvorel@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 4bca37963..1249f0df4 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 50b514cb4..6fbb7db7c 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 873a6d84c..dde691a2b 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 1edde3676..5e9ea39e1 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 851ec652e..69c824a3f 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.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [LTP] [PATCH v2 09/13] testcases/kernel/mem: Move KSM bits to ksm tests
2025-02-10 11:31 [LTP] [PATCH v2 00/13] Cyril Hrubis
` (7 preceding siblings ...)
2025-02-10 11:32 ` [LTP] [PATCH v2 08/13] testcases/kernel/mem: Move oom() fucntions to oom tests Cyril Hrubis
@ 2025-02-10 11:32 ` Cyril Hrubis
2025-02-10 13:20 ` pvorel
2025-02-10 11:32 ` [LTP] [PATCH v2 10/13] mem/swapping: Remove mem/lib refrence Cyril Hrubis
` (5 subsequent siblings)
14 siblings, 1 reply; 23+ messages in thread
From: Cyril Hrubis @ 2025-02-10 11:32 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 | 302 ++++++++++++++++++++++++++
testcases/kernel/mem/lib/mem.c | 287 ------------------------
12 files changed, 315 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 b9e80e813..ab16af29e 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 0e264b10f..978214034 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..0db759d5a
--- /dev/null
+++ b/testcases/kernel/mem/ksm/ksm_test.h
@@ -0,0 +1,302 @@
+// 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, unsigned int size,
+ unsigned int total_unit,
+ struct ksm_merge_data ksm_merge_data,
+ char **memory)
+{
+ unsigned int i = 0, j;
+ unsigned 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 %u MB filled with '%c'",
+ child_num, size, ksm_merge_data.data);
+
+ } else {
+ tst_res(TINFO, "child %d allocates %u 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, unsigned int size,
+ unsigned int unit,
+ struct ksm_merge_data *ksm_merge_data)
+{
+ unsigned 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(unsigned int size, int num, unsigned 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.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [LTP] [PATCH v2 10/13] mem/swapping: Remove mem/lib refrence
2025-02-10 11:31 [LTP] [PATCH v2 00/13] Cyril Hrubis
` (8 preceding siblings ...)
2025-02-10 11:32 ` [LTP] [PATCH v2 09/13] testcases/kernel/mem: Move KSM bits to ksm tests Cyril Hrubis
@ 2025-02-10 11:32 ` Cyril Hrubis
2025-02-10 11:32 ` [LTP] [PATCH v2 11/13] mem/vma: Remove mem/lib dependency Cyril Hrubis
` (4 subsequent siblings)
14 siblings, 0 replies; 23+ messages in thread
From: Cyril Hrubis @ 2025-02-10 11:32 UTC (permalink / raw)
To: ltp
The test does not use the library at all!
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Petr Vorel <pvorel@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 df1dcdf56..1a9aab8de 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.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [LTP] [PATCH v2 11/13] mem/vma: Remove mem/lib dependency
2025-02-10 11:31 [LTP] [PATCH v2 00/13] Cyril Hrubis
` (9 preceding siblings ...)
2025-02-10 11:32 ` [LTP] [PATCH v2 10/13] mem/swapping: Remove mem/lib refrence Cyril Hrubis
@ 2025-02-10 11:32 ` Cyril Hrubis
2025-02-10 11:32 ` [LTP] [PATCH v2 12/13] mem/hugetlb: Remove mem/lib depenency Cyril Hrubis
` (3 subsequent siblings)
14 siblings, 0 replies; 23+ messages in thread
From: Cyril Hrubis @ 2025-02-10 11:32 UTC (permalink / raw)
To: ltp
The test does just use the testcases/lib/ instead.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Petr Vorel <pvorel@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.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [LTP] [PATCH v2 12/13] mem/hugetlb: Remove mem/lib depenency
2025-02-10 11:31 [LTP] [PATCH v2 00/13] Cyril Hrubis
` (10 preceding siblings ...)
2025-02-10 11:32 ` [LTP] [PATCH v2 11/13] mem/vma: Remove mem/lib dependency Cyril Hrubis
@ 2025-02-10 11:32 ` Cyril Hrubis
2025-02-10 11:32 ` [LTP] [PATCH v2 13/13] testcases/kernel/mem: Remove library Cyril Hrubis
` (2 subsequent siblings)
14 siblings, 0 replies; 23+ messages in thread
From: Cyril Hrubis @ 2025-02-10 11:32 UTC (permalink / raw)
To: ltp
The last bit used from the library PATH_SHMMAX macro.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Petr Vorel <pvorel@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.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [LTP] [PATCH v2 13/13] testcases/kernel/mem: Remove library
2025-02-10 11:31 [LTP] [PATCH v2 00/13] Cyril Hrubis
` (11 preceding siblings ...)
2025-02-10 11:32 ` [LTP] [PATCH v2 12/13] mem/hugetlb: Remove mem/lib depenency Cyril Hrubis
@ 2025-02-10 11:32 ` Cyril Hrubis
2025-02-10 11:45 ` [LTP] [PATCH v2 00/13] Get rid of testcases/kernel/mem/lib library Cyril Hrubis
2025-02-13 12:39 ` [LTP] [PATCH v2 00/13] Jan Stancek
14 siblings, 0 replies; 23+ messages in thread
From: Cyril Hrubis @ 2025-02-10 11:32 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>
Reviewed-by: Petr Vorel <pvorel@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.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v2 00/13] Get rid of testcases/kernel/mem/lib library
2025-02-10 11:31 [LTP] [PATCH v2 00/13] Cyril Hrubis
` (12 preceding siblings ...)
2025-02-10 11:32 ` [LTP] [PATCH v2 13/13] testcases/kernel/mem: Remove library Cyril Hrubis
@ 2025-02-10 11:45 ` Cyril Hrubis
2025-02-13 12:39 ` [LTP] [PATCH v2 00/13] Jan Stancek
14 siblings, 0 replies; 23+ messages in thread
From: Cyril Hrubis @ 2025-02-10 11:45 UTC (permalink / raw)
To: ltp
Hi!
The CI run was started:
https://github.com/metan-ucw/ltp/actions/runs/13240065186
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v2 02/13] lib: Replace path_exist() with tst_path_exists()
2025-02-10 11:32 ` [LTP] [PATCH v2 02/13] lib: Replace path_exist() with tst_path_exists() Cyril Hrubis
@ 2025-02-10 11:53 ` pvorel
2025-02-10 13:07 ` Cyril Hrubis
0 siblings, 1 reply; 23+ messages in thread
From: pvorel @ 2025-02-10 11:53 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi Cyril,
On 2025-02-10 12:32, Cyril Hrubis wrote:
> 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>
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
> ---
> include/tst_fs.h | 10 ++++++++++
> lib/tst_path_exists.c | 23 +++++++++++++++++++++++
The only thing I don't like is creating file for single functions.
My long term plan was to have fewer files with more functions.
I'm sorry I did not point this out in v1, thus feel free to ignore it.
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v2 02/13] lib: Replace path_exist() with tst_path_exists()
2025-02-10 11:53 ` pvorel
@ 2025-02-10 13:07 ` Cyril Hrubis
2025-02-10 13:44 ` pvorel
0 siblings, 1 reply; 23+ messages in thread
From: Cyril Hrubis @ 2025-02-10 13:07 UTC (permalink / raw)
To: pvorel; +Cc: ltp
Hi!
> > 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>
> > Reviewed-by: Petr Vorel <pvorel@suse.cz>
> > ---
> > include/tst_fs.h | 10 ++++++++++
> > lib/tst_path_exists.c | 23 +++++++++++++++++++++++
>
> The only thing I don't like is creating file for single functions.
> My long term plan was to have fewer files with more functions.
> I'm sorry I did not point this out in v1, thus feel free to ignore it.
Feel free to move this code to a file you find appropriate and merge the
patchset.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v2 09/13] testcases/kernel/mem: Move KSM bits to ksm tests
2025-02-10 11:32 ` [LTP] [PATCH v2 09/13] testcases/kernel/mem: Move KSM bits to ksm tests Cyril Hrubis
@ 2025-02-10 13:20 ` pvorel
0 siblings, 0 replies; 23+ messages in thread
From: pvorel @ 2025-02-10 13:20 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi Cyril,
LGTM.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v2 02/13] lib: Replace path_exist() with tst_path_exists()
2025-02-10 13:07 ` Cyril Hrubis
@ 2025-02-10 13:44 ` pvorel
2025-02-10 13:54 ` Cyril Hrubis
0 siblings, 1 reply; 23+ messages in thread
From: pvorel @ 2025-02-10 13:44 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
On 2025-02-10 14:07, Cyril Hrubis wrote:
> Hi!
>> > 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>
>> > Reviewed-by: Petr Vorel <pvorel@suse.cz>
>> > ---
>> > include/tst_fs.h | 10 ++++++++++
>> > lib/tst_path_exists.c | 23 +++++++++++++++++++++++
>>
>> The only thing I don't like is creating file for single functions.
>> My long term plan was to have fewer files with more functions.
>> I'm sorry I did not point this out in v1, thus feel free to ignore it.
>
> Feel free to move this code to a file you find appropriate and merge
> the
> patchset.
Cyril, please merge it as is.
After that, I send a patch for
Moving into newly created tst_fs.c these new API sources: tst_ioctl.c,
tst_fs_setup.c, tst_fill_fs.c, tst_fill_file.c, tst_path_exists.c,
tst_supported_fs_types.c.
And moving into newly created tst_fs_old.c these old API sources:
tst_fs_has_free.c (only dma_thread_diotest.c has not been converted into
new API), tst_fs_type.c.
Having everything eventually in single tst_fs.c might be too much, but
I'm not sure if it's worth to spent time to split tst_fs.h into separate
headers (and then to corresponding c sources).
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v2 02/13] lib: Replace path_exist() with tst_path_exists()
2025-02-10 13:44 ` pvorel
@ 2025-02-10 13:54 ` Cyril Hrubis
2025-02-11 5:44 ` Li Wang
0 siblings, 1 reply; 23+ messages in thread
From: Cyril Hrubis @ 2025-02-10 13:54 UTC (permalink / raw)
To: pvorel; +Cc: ltp
Hi!
I will wait till tomorrow so that other have chance to have a look and
then push the patchset.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v2 02/13] lib: Replace path_exist() with tst_path_exists()
2025-02-10 13:54 ` Cyril Hrubis
@ 2025-02-11 5:44 ` Li Wang
2025-02-12 9:59 ` Cyril Hrubis
0 siblings, 1 reply; 23+ messages in thread
From: Li Wang @ 2025-02-11 5:44 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: pvorel, ltp
On Mon, Feb 10, 2025 at 9:54 PM Cyril Hrubis <chrubis@suse.cz> wrote:
> Hi!
> I will wait till tomorrow so that other have chance to have a look and
> then push the patchset.
>
For the series:
Reviewed-by: Li Wang <liwang@redhat.com>
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v2 02/13] lib: Replace path_exist() with tst_path_exists()
2025-02-11 5:44 ` Li Wang
@ 2025-02-12 9:59 ` Cyril Hrubis
0 siblings, 0 replies; 23+ messages in thread
From: Cyril Hrubis @ 2025-02-12 9:59 UTC (permalink / raw)
To: Li Wang; +Cc: pvorel, ltp
Hi!
Applied, thanks for the reviews.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v2 00/13]
2025-02-10 11:31 [LTP] [PATCH v2 00/13] Cyril Hrubis
` (13 preceding siblings ...)
2025-02-10 11:45 ` [LTP] [PATCH v2 00/13] Get rid of testcases/kernel/mem/lib library Cyril Hrubis
@ 2025-02-13 12:39 ` Jan Stancek
14 siblings, 0 replies; 23+ messages in thread
From: Jan Stancek @ 2025-02-13 12:39 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
On Mon, Feb 10, 2025 at 12:32 PM Cyril Hrubis <chrubis@suse.cz> wrote:
>
> 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.
>
> v2:
> - Rebased the patchset
> - Fixed doc comments in headers
> (decided to add short descriptions for functions after all)
> - Fixed TST_MB in strings
> - Fixed warnings introduced in ksm tests
big series, but all steps leading to end result look reasonable
Acked-by: Jan Stancek <jstancek@redhat.com>
>
>
> 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 | 32 +
> 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 | 302 ++++++++
> 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, 926 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.3
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
end of thread, other threads:[~2025-02-13 12:40 UTC | newest]
Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-10 11:31 [LTP] [PATCH v2 00/13] Cyril Hrubis
2025-02-10 11:32 ` [LTP] [PATCH v2 01/13] lib: tst_sys_conf: Add two functions Cyril Hrubis
2025-02-10 11:32 ` [LTP] [PATCH v2 02/13] lib: Replace path_exist() with tst_path_exists() Cyril Hrubis
2025-02-10 11:53 ` pvorel
2025-02-10 13:07 ` Cyril Hrubis
2025-02-10 13:44 ` pvorel
2025-02-10 13:54 ` Cyril Hrubis
2025-02-11 5:44 ` Li Wang
2025-02-12 9:59 ` Cyril Hrubis
2025-02-10 11:32 ` [LTP] [PATCH v2 03/13] lib: Add tst_mapping_in_range() Cyril Hrubis
2025-02-10 11:32 ` [LTP] [PATCH v2 04/13] testcases/kernel/mem: Move get_a_numa_node() Cyril Hrubis
2025-02-10 11:32 ` [LTP] [PATCH v2 05/13] testcases/kernel/mem: Move update_shm_size() Cyril Hrubis
2025-02-10 11:32 ` [LTP] [PATCH v2 06/13] testcases/kernel/mem: Move check_hugepage() + PATH_THP Cyril Hrubis
2025-02-10 11:32 ` [LTP] [PATCH v2 07/13] testcases/kernel/mem: Move NUMA bits to numa_helper.h Cyril Hrubis
2025-02-10 11:32 ` [LTP] [PATCH v2 08/13] testcases/kernel/mem: Move oom() fucntions to oom tests Cyril Hrubis
2025-02-10 11:32 ` [LTP] [PATCH v2 09/13] testcases/kernel/mem: Move KSM bits to ksm tests Cyril Hrubis
2025-02-10 13:20 ` pvorel
2025-02-10 11:32 ` [LTP] [PATCH v2 10/13] mem/swapping: Remove mem/lib refrence Cyril Hrubis
2025-02-10 11:32 ` [LTP] [PATCH v2 11/13] mem/vma: Remove mem/lib dependency Cyril Hrubis
2025-02-10 11:32 ` [LTP] [PATCH v2 12/13] mem/hugetlb: Remove mem/lib depenency Cyril Hrubis
2025-02-10 11:32 ` [LTP] [PATCH v2 13/13] testcases/kernel/mem: Remove library Cyril Hrubis
2025-02-10 11:45 ` [LTP] [PATCH v2 00/13] Get rid of testcases/kernel/mem/lib library Cyril Hrubis
2025-02-13 12:39 ` [LTP] [PATCH v2 00/13] Jan Stancek
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.