* [LTP] [PATCH v1] cpuset_memory_test.c: Use $TMPDIR as prefix for HUGEPAGE file path
@ 2024-08-01 10:40 Wei Gao via ltp
2024-08-01 12:16 ` Petr Vorel
` (2 more replies)
0 siblings, 3 replies; 62+ messages in thread
From: Wei Gao via ltp @ 2024-08-01 10:40 UTC (permalink / raw)
To: ltp
Test case will fail with following error if running operation system
which force root path read ONLY.
mkdir: cannot create directory ‘/hugetlb’: Read-only file system
Signed-off-by: Wei Gao <wegao@suse.com>
---
.../cpuset_memory_test/cpuset_memory_test.c | 11 ++++++++---
.../cpuset_memory_test/cpuset_memory_testset.sh | 16 ++++++++--------
2 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_test.c b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_test.c
index 9912d8d6a..73770fd3c 100644
--- a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_test.c
+++ b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_test.c
@@ -177,9 +177,14 @@ void mmap_file(int flag_allocated)
static int fd_hugepage;
int fd_tmp;
+ char path[100];
+ char *tmpdir = getenv("TMPDIR");
+
+ sprintf(path, "%s%s", tmpdir, FILE_HUGEPAGE);
+
if (!flag_allocated) {
if (opt_hugepage) {
- fd_hugepage = open(FILE_HUGEPAGE,
+ fd_hugepage = open(path,
O_CREAT | O_RDWR, 0755);
if (fd_hugepage < 0)
err(1, "open hugepage file failed");
@@ -191,7 +196,7 @@ void mmap_file(int flag_allocated)
MAP_SHARED, fd_tmp, 0);
if (p == MAP_FAILED) {
if (opt_hugepage)
- unlink(FILE_HUGEPAGE);
+ unlink(path);
err(1, "mmap(file) failed");
}
touch_memory_and_echo_node(p, memsize);
@@ -201,7 +206,7 @@ void mmap_file(int flag_allocated)
if (opt_hugepage) {
close(fd_hugepage);
- unlink(FILE_HUGEPAGE);
+ unlink(path);
}
}
}
diff --git a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
index c1e7cea8f..b63425088 100755
--- a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
+++ b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
@@ -175,8 +175,8 @@ test6()
return 0
fi
- mkdir /hugetlb
- mount -t hugetlbfs none /hugetlb
+ mkdir ${TMPDIR}/hugetlb
+ mount -t hugetlbfs none ${TMPDIR}/hugetlb
save_nr_hugepages=$(cat /proc/sys/vm/nr_hugepages)
echo $((2*$nr_mems)) > /proc/sys/vm/nr_hugepages
@@ -184,8 +184,8 @@ test6()
cpuset_memory_test --mmap-file --hugepage -s $HUGEPAGESIZE >"$MEMORY_RESULT" &
simple_getresult $! "$CPUSET/0"
- umount /hugetlb
- rmdir /hugetlb
+ umount ${TMPDIR}/hugetlb
+ rmdir ${TMPDIR}/hugetlb
echo $save_nr_hugepages > /proc/sys/vm/nr_hugepages
if [ $(cat /proc/sys/vm/nr_hugepages) -ne $save_nr_hugepages ]; then
@@ -214,8 +214,8 @@ test7()
return 0
fi
- mkdir /hugetlb
- mount -t hugetlbfs none /hugetlb
+ mkdir ${TMPDIR}/hugetlb
+ mount -t hugetlbfs none ${TMPDIR}/hugetlb
save_nr_hugepages=$(cat /proc/sys/vm/nr_hugepages)
echo $((2*$nr_mems)) > /proc/sys/vm/nr_hugepages
@@ -223,8 +223,8 @@ test7()
cpuset_memory_test --shm --hugepage -s $HUGEPAGESIZE --key=7 >"$MEMORY_RESULT" &
simple_getresult $! "$CPUSET/0"
- umount /hugetlb
- rmdir /hugetlb
+ umount ${TMPDIR}/hugetlb
+ rmdir ${TMPDIR}/hugetlb
echo $save_nr_hugepages > /proc/sys/vm/nr_hugepages
if [ $(cat /proc/sys/vm/nr_hugepages) -ne $save_nr_hugepages ]; then
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v1] cpuset_memory_test.c: Use $TMPDIR as prefix for HUGEPAGE file path
2024-08-01 10:40 [LTP] [PATCH v1] cpuset_memory_test.c: Use $TMPDIR as prefix for HUGEPAGE file path Wei Gao via ltp
@ 2024-08-01 12:16 ` Petr Vorel
2024-08-01 12:20 ` Cyril Hrubis
2024-08-19 4:49 ` [LTP] [PATCH v2] cpuset02: Reimplementing the test6 of cpuset_memory_testset.sh as a separate C testcase Wei Gao via ltp
2 siblings, 0 replies; 62+ messages in thread
From: Petr Vorel @ 2024-08-01 12:16 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi Wei,
> Test case will fail with following error if running operation system
> which force root path read ONLY.
> mkdir: cannot create directory ‘/hugetlb’: Read-only file system
> Signed-off-by: Wei Gao <wegao@suse.com>
> ---
> .../cpuset_memory_test/cpuset_memory_test.c | 11 ++++++++---
> .../cpuset_memory_test/cpuset_memory_testset.sh | 16 ++++++++--------
> 2 files changed, 16 insertions(+), 11 deletions(-)
> diff --git a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_test.c b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_test.c
> index 9912d8d6a..73770fd3c 100644
> --- a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_test.c
> +++ b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_test.c
> @@ -177,9 +177,14 @@ void mmap_file(int flag_allocated)
> static int fd_hugepage;
> int fd_tmp;
> + char path[100];
> + char *tmpdir = getenv("TMPDIR");
> +
> + sprintf(path, "%s%s", tmpdir, FILE_HUGEPAGE);
FYI, we have custom function, thus no need to detect TMPDIR in the test.
Because this is still the legacy API, could you please use tst_tmpdir_path()?
FYI in the new API We had for a long time tst_get_tmpdir() function needed to
use free() and was used for snprintf(), but Cyril changed that quite recently:
https://github.com/linux-test-project/ltp/commit/c5d95b6d34e2356bd19e6b646da06f1bce66a024
Since that just use tst_tmpdir_path(), no need to free.
IMHO both legacy API and new API do chdir() to the temporary directory, see
lib/tst_tmpdir.c:
if (chdir(TESTDIR) == -1) {
tst_resm(TERRNO, "%s: chdir(%s) failed", __func__, TESTDIR);
Therefore unless there is full path needed (e.g. search in /proc/mounts) we
could use relative path, e.g. add "./" to the definition:
+++ testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_test.c
@@ -58,7 +58,7 @@ static int opt_thread;
static int key_id; /* used with opt_shm */
static unsigned long memsize;
-#define FILE_HUGEPAGE "/hugetlb/hugepagefile"
+#define FILE_HUGEPAGE "./hugetlb/hugepagefile"
#define MMAP_ANON (SCHAR_MAX + 1)
#define MMAP_FILE (SCHAR_MAX + 2)
---
Also, the same definition is in
testcases/kernel/controllers/memcg/functional/memcg_process.c, is it affected as
well?
FYI Besides that it's always better to use 'n' sprintf functions (e.g.
snprintf(), because they restrict the write size (man printf(3): "write at most size bytes")
> +
> if (!flag_allocated) {
> if (opt_hugepage) {
> - fd_hugepage = open(FILE_HUGEPAGE,
> + fd_hugepage = open(path,
> O_CREAT | O_RDWR, 0755);
> if (fd_hugepage < 0)
> err(1, "open hugepage file failed");
> @@ -191,7 +196,7 @@ void mmap_file(int flag_allocated)
> MAP_SHARED, fd_tmp, 0);
> if (p == MAP_FAILED) {
> if (opt_hugepage)
> - unlink(FILE_HUGEPAGE);
> + unlink(path);
> err(1, "mmap(file) failed");
> }
> touch_memory_and_echo_node(p, memsize);
> @@ -201,7 +206,7 @@ void mmap_file(int flag_allocated)
> if (opt_hugepage) {
> close(fd_hugepage);
> - unlink(FILE_HUGEPAGE);
> + unlink(path);
> }
> }
> }
> diff --git a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
> index c1e7cea8f..b63425088 100755
> --- a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
> +++ b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
> @@ -175,8 +175,8 @@ test6()
> return 0
> fi
> - mkdir /hugetlb
> - mount -t hugetlbfs none /hugetlb
> + mkdir ${TMPDIR}/hugetlb
Could you please use $TMPDIR instead of ${TMPDIR}? (more readable).
> + mount -t hugetlbfs none ${TMPDIR}/hugetlb
And here (there are more places).
BTW just ./hugetlb could work, right? Also, in the shell API we are in the
directory.
And thanks for pointing these tests, once Cyril's effort for mixing C and shell
code is merged, we should adapt these tests to use it.
https://patchwork.ozlabs.org/project/ltp/list/?series=417372&state=*
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v1] cpuset_memory_test.c: Use $TMPDIR as prefix for HUGEPAGE file path
2024-08-01 10:40 [LTP] [PATCH v1] cpuset_memory_test.c: Use $TMPDIR as prefix for HUGEPAGE file path Wei Gao via ltp
2024-08-01 12:16 ` Petr Vorel
@ 2024-08-01 12:20 ` Cyril Hrubis
2024-08-19 4:49 ` [LTP] [PATCH v2] cpuset02: Reimplementing the test6 of cpuset_memory_testset.sh as a separate C testcase Wei Gao via ltp
2 siblings, 0 replies; 62+ messages in thread
From: Cyril Hrubis @ 2024-08-01 12:20 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi!
> Test case will fail with following error if running operation system
> which force root path read ONLY.
>
> mkdir: cannot create directory ‘/hugetlb’: Read-only file system
Can we please stop applying band aids over the mess called cpuset tests
and start actually rewriting them into something saner?
I would start by reimplementing the test6 as a separate C testcase so
that we can make use of all the infrastructure for hugepages we have in
the tst_test.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* [LTP] [PATCH v2] cpuset02: Reimplementing the test6 of cpuset_memory_testset.sh as a separate C testcase
2024-08-01 10:40 [LTP] [PATCH v1] cpuset_memory_test.c: Use $TMPDIR as prefix for HUGEPAGE file path Wei Gao via ltp
2024-08-01 12:16 ` Petr Vorel
2024-08-01 12:20 ` Cyril Hrubis
@ 2024-08-19 4:49 ` Wei Gao via ltp
2024-09-26 6:19 ` [LTP] [PATCH v3] " Wei Gao via ltp
2 siblings, 1 reply; 62+ messages in thread
From: Wei Gao via ltp @ 2024-08-19 4:49 UTC (permalink / raw)
To: ltp
Signed-off-by: Wei Gao <wegao@suse.com>
---
runtest/mm | 1 +
.../cpuset_memory_test/cpuset_memory_test.c | 15 +-
testcases/kernel/mem/.gitignore | 1 +
testcases/kernel/mem/cpuset/cpuset02.c | 152 ++++++++++++++++++
4 files changed, 163 insertions(+), 6 deletions(-)
create mode 100644 testcases/kernel/mem/cpuset/cpuset02.c
diff --git a/runtest/mm b/runtest/mm
index 6a8cd0b9d..845874c41 100644
--- a/runtest/mm
+++ b/runtest/mm
@@ -75,6 +75,7 @@ ksm06_2 ksm06 -n 8000
ksm07 ksm07
cpuset01 cpuset01
+cpuset02 cpuset02
oom01 oom01
oom02 oom02
diff --git a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_test.c b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_test.c
index 9912d8d6a..4e9e40ea2 100644
--- a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_test.c
+++ b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_test.c
@@ -56,10 +56,9 @@ static int opt_check; /* check node when munmap memory (only for mmap_anon()) */
static int opt_thread;
static int key_id; /* used with opt_shm */
+static char hugepagefile[100] = "/hugetlb/hugepagefile";
static unsigned long memsize;
-#define FILE_HUGEPAGE "/hugetlb/hugepagefile"
-
#define MMAP_ANON (SCHAR_MAX + 1)
#define MMAP_FILE (SCHAR_MAX + 2)
#define MMAP_LOCK1 (SCHAR_MAX + 3)
@@ -80,6 +79,7 @@ const struct option long_opts[] = {
{"thread", 0, NULL, THREAD},
{"size", 1, NULL, 's'},
{"key", 1, NULL, 'k'},
+ {"hugepage-file", 1, NULL, 'f'},
{NULL, 0, NULL, 0},
};
@@ -92,7 +92,7 @@ void process_options(int argc, char *argv[])
char *end;
while (1) {
- c = getopt_long(argc, argv, "s:k:", long_opts, NULL);
+ c = getopt_long(argc, argv, "s:k:f:", long_opts, NULL);
if (c == -1)
break;
@@ -105,6 +105,9 @@ void process_options(int argc, char *argv[])
case 'k':
key_id = atoi(optarg);
break;
+ case 'f':
+ strncpy(hugepagefile, optarg, sizeof(hugepagefile) - 1);
+ break;
case MMAP_ANON:
opt_mmap_anon = 1;
break;
@@ -179,7 +182,7 @@ void mmap_file(int flag_allocated)
if (!flag_allocated) {
if (opt_hugepage) {
- fd_hugepage = open(FILE_HUGEPAGE,
+ fd_hugepage = open(hugepagefile,
O_CREAT | O_RDWR, 0755);
if (fd_hugepage < 0)
err(1, "open hugepage file failed");
@@ -191,7 +194,7 @@ void mmap_file(int flag_allocated)
MAP_SHARED, fd_tmp, 0);
if (p == MAP_FAILED) {
if (opt_hugepage)
- unlink(FILE_HUGEPAGE);
+ unlink(hugepagefile);
err(1, "mmap(file) failed");
}
touch_memory_and_echo_node(p, memsize);
@@ -201,7 +204,7 @@ void mmap_file(int flag_allocated)
if (opt_hugepage) {
close(fd_hugepage);
- unlink(FILE_HUGEPAGE);
+ unlink(hugepagefile);
}
}
}
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index c96fe8bfc..f01953b5c 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -1,4 +1,5 @@
/cpuset/cpuset01
+/cpuset/cpuset02
/hugetlb/hugefallocate/hugefallocate01
/hugetlb/hugefallocate/hugefallocate02
/hugetlb/hugefork/hugefork01
diff --git a/testcases/kernel/mem/cpuset/cpuset02.c b/testcases/kernel/mem/cpuset/cpuset02.c
new file mode 100644
index 000000000..801c23d34
--- /dev/null
+++ b/testcases/kernel/mem/cpuset/cpuset02.c
@@ -0,0 +1,152 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (c) 2009 FUJITSU LIMITED Miao Xie <miaox@cn.fujitsu.com>
+ * Copyright (c) 2023 SUSE LLC <wegao@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This is reimplementing the test6 of cpuset_memory_testset.sh
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+
+#include "tst_test.h"
+
+#if HAVE_NUMA_H
+#include <numa.h>
+#endif
+#if HAVE_NUMAIF_H
+#include <numaif.h>
+#endif
+
+#include "tst_safe_stdio.h"
+#include "mem.h"
+#include "numa_helper.h"
+
+#define MNTPOINT "hugetlbfs/"
+#define CPUSET "cpuset_mnt"
+
+#ifdef HAVE_NUMA_V2
+
+static long hpage_size;
+static int ncpus;
+static int *nodes;
+static int nnodes;
+
+static void count_cpus_mems(void)
+{
+ while (path_exist(PATH_SYS_SYSTEM "/cpu/cpu%d", ncpus))
+ ncpus++;
+ if (get_allowed_nodes_arr(NH_MEMS | NH_CPUS, &nnodes, &nodes) < 0)
+ tst_brk(TBROK | TERRNO, "get_allowed_nodes_arr");
+ if (nnodes <= 1)
+ tst_brk(TCONF, "requires a NUMA system.");
+}
+
+static void run_test(void)
+{
+ char path[256];
+ char tmp_path[256];
+
+ snprintf(path, sizeof(path), "./%s/0", CPUSET);
+ if (access(path, F_OK) != 0)
+ SAFE_MKDIR(path, 0777);
+ snprintf(tmp_path, sizeof(tmp_path), "./%s/cpuset.cpus", path);
+ SAFE_FILE_PRINTF(tmp_path, "%s", "0");
+ snprintf(tmp_path, sizeof(tmp_path), "./%s/cpuset.mems", path);
+ SAFE_FILE_PRINTF(tmp_path, "%s", "0");
+ snprintf(tmp_path, sizeof(tmp_path), "./%s/cpuset.sched_load_balance", path);
+ SAFE_FILE_PRINTF(tmp_path, "%s", "0");
+ SAFE_FILE_PRINTF("/proc/sys/vm/nr_hugepages", "%d", 2 * nnodes);
+
+ int pid;
+ char str_hpage_size[20];
+
+ snprintf(str_hpage_size, sizeof(str_hpage_size), "%ld", hpage_size);
+ snprintf(tmp_path, sizeof(tmp_path), "%shugepagefile", MNTPOINT);
+
+ char *argv[10] = {
+ "cpuset_memory_test",
+ "--mmap-file",
+ "--hugepage",
+ "-s",
+ str_hpage_size,
+ "-f",
+ tmp_path,
+ NULL,
+ };
+
+ pid = SAFE_FORK();
+ if (pid == 0) {
+ int fd = SAFE_OPEN("memory_result", O_WRONLY | O_CREAT | O_TRUNC, 0644);
+
+ SAFE_DUP2(fd, STDOUT_FILENO);
+ close(fd);
+ execvpe("cpuset_memory_test", argv, NULL);
+ tst_brk(TBROK | TERRNO, "execvpe(%s, ...) failed!", argv[0]);
+ exit(0);
+ }
+
+ sleep(1);
+ snprintf(tmp_path, sizeof(tmp_path), "./%s/tasks", path);
+ SAFE_FILE_PRINTF(tmp_path, "%d", pid);
+ kill(pid, SIGUSR1);
+ sleep(1);
+ kill(pid, SIGUSR1);
+ sleep(1);
+ kill(pid, SIGINT);
+ SAFE_WAITPID(pid, NULL, 0);
+
+ char node[20];
+ FILE *file;
+
+ file = SAFE_FOPEN("memory_result", "r");
+
+ if (fgets(node, sizeof(node), file) == NULL)
+ tst_res(TFAIL, "read memory_result failed");
+
+ fclose(file);
+
+ TST_EXP_PASS(strncmp(node, "0", 1));
+}
+
+static void setup(void)
+{
+ count_cpus_mems();
+
+ hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;
+ SAFE_MKDIR(CPUSET, 0777);
+ SAFE_MOUNT("cpuset", CPUSET, "cgroup", 0, "cpuset");
+}
+
+static void cleanup(void)
+{
+ SAFE_UMOUNT(CPUSET);
+}
+
+static struct tst_test test = {
+ .needs_root = 1,
+ .mntpoint = MNTPOINT,
+ .needs_hugetlbfs = 1,
+ .setup = setup,
+ .forks_child = 1,
+ .cleanup = cleanup,
+ .test_all = run_test,
+ .hugepages = {3, TST_NEEDS},
+ .save_restore = (const struct tst_path_val[]) {
+ {"/proc/sys/vm/nr_hugepages", NULL, TST_SR_TBROK},
+ {}
+ },
+};
+
+#else
+TST_TEST_TCONF(NUMA_ERROR_MSG);
+#endif
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 62+ messages in thread
* [LTP] [PATCH v3] cpuset02: Reimplementing the test6 of cpuset_memory_testset.sh as a separate C testcase
2024-08-19 4:49 ` [LTP] [PATCH v2] cpuset02: Reimplementing the test6 of cpuset_memory_testset.sh as a separate C testcase Wei Gao via ltp
@ 2024-09-26 6:19 ` Wei Gao via ltp
2024-09-27 10:30 ` Cyril Hrubis
2024-09-30 13:58 ` [LTP] [PATCH v4] " Wei Gao via ltp
0 siblings, 2 replies; 62+ messages in thread
From: Wei Gao via ltp @ 2024-09-26 6:19 UTC (permalink / raw)
To: ltp
Signed-off-by: Wei Gao <wegao@suse.com>
---
runtest/mm | 1 +
.../cpuset_memory_test/cpuset_memory_test.c | 15 +-
testcases/kernel/mem/.gitignore | 1 +
testcases/kernel/mem/cpuset/cpuset02.c | 147 ++++++++++++++++++
4 files changed, 158 insertions(+), 6 deletions(-)
create mode 100644 testcases/kernel/mem/cpuset/cpuset02.c
diff --git a/runtest/mm b/runtest/mm
index 6a8cd0b9d..845874c41 100644
--- a/runtest/mm
+++ b/runtest/mm
@@ -75,6 +75,7 @@ ksm06_2 ksm06 -n 8000
ksm07 ksm07
cpuset01 cpuset01
+cpuset02 cpuset02
oom01 oom01
oom02 oom02
diff --git a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_test.c b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_test.c
index 9912d8d6a..4e9e40ea2 100644
--- a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_test.c
+++ b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_test.c
@@ -56,10 +56,9 @@ static int opt_check; /* check node when munmap memory (only for mmap_anon()) */
static int opt_thread;
static int key_id; /* used with opt_shm */
+static char hugepagefile[100] = "/hugetlb/hugepagefile";
static unsigned long memsize;
-#define FILE_HUGEPAGE "/hugetlb/hugepagefile"
-
#define MMAP_ANON (SCHAR_MAX + 1)
#define MMAP_FILE (SCHAR_MAX + 2)
#define MMAP_LOCK1 (SCHAR_MAX + 3)
@@ -80,6 +79,7 @@ const struct option long_opts[] = {
{"thread", 0, NULL, THREAD},
{"size", 1, NULL, 's'},
{"key", 1, NULL, 'k'},
+ {"hugepage-file", 1, NULL, 'f'},
{NULL, 0, NULL, 0},
};
@@ -92,7 +92,7 @@ void process_options(int argc, char *argv[])
char *end;
while (1) {
- c = getopt_long(argc, argv, "s:k:", long_opts, NULL);
+ c = getopt_long(argc, argv, "s:k:f:", long_opts, NULL);
if (c == -1)
break;
@@ -105,6 +105,9 @@ void process_options(int argc, char *argv[])
case 'k':
key_id = atoi(optarg);
break;
+ case 'f':
+ strncpy(hugepagefile, optarg, sizeof(hugepagefile) - 1);
+ break;
case MMAP_ANON:
opt_mmap_anon = 1;
break;
@@ -179,7 +182,7 @@ void mmap_file(int flag_allocated)
if (!flag_allocated) {
if (opt_hugepage) {
- fd_hugepage = open(FILE_HUGEPAGE,
+ fd_hugepage = open(hugepagefile,
O_CREAT | O_RDWR, 0755);
if (fd_hugepage < 0)
err(1, "open hugepage file failed");
@@ -191,7 +194,7 @@ void mmap_file(int flag_allocated)
MAP_SHARED, fd_tmp, 0);
if (p == MAP_FAILED) {
if (opt_hugepage)
- unlink(FILE_HUGEPAGE);
+ unlink(hugepagefile);
err(1, "mmap(file) failed");
}
touch_memory_and_echo_node(p, memsize);
@@ -201,7 +204,7 @@ void mmap_file(int flag_allocated)
if (opt_hugepage) {
close(fd_hugepage);
- unlink(FILE_HUGEPAGE);
+ unlink(hugepagefile);
}
}
}
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index d88484fa1..0845297cb 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -1,4 +1,5 @@
/cpuset/cpuset01
+/cpuset/cpuset02
/hugetlb/hugefallocate/hugefallocate01
/hugetlb/hugefallocate/hugefallocate02
/hugetlb/hugefork/hugefork01
diff --git a/testcases/kernel/mem/cpuset/cpuset02.c b/testcases/kernel/mem/cpuset/cpuset02.c
new file mode 100644
index 000000000..05ed5c791
--- /dev/null
+++ b/testcases/kernel/mem/cpuset/cpuset02.c
@@ -0,0 +1,147 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (c) 2009 FUJITSU LIMITED Miao Xie <miaox@cn.fujitsu.com>
+ * Copyright (c) 2023 SUSE LLC <wegao@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This is reimplementing the test6 of cpuset_memory_testset.sh
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+
+#include "tst_test.h"
+
+#if HAVE_NUMA_H
+#include <numa.h>
+#endif
+#if HAVE_NUMAIF_H
+#include <numaif.h>
+#endif
+
+#include "tst_safe_stdio.h"
+#include "mem.h"
+#include "numa_helper.h"
+
+#define MNTPOINT "hugetlbfs/"
+#define CPUSET "cpuset_mnt"
+
+#ifdef HAVE_NUMA_V2
+
+static long hpage_size;
+static int ncpus;
+static int *nodes;
+static int nnodes;
+
+static void count_cpus_mems(void)
+{
+ while (path_exist(PATH_SYS_SYSTEM "/cpu/cpu%d", ncpus))
+ ncpus++;
+ if (get_allowed_nodes_arr(NH_MEMS | NH_CPUS, &nnodes, &nodes) < 0)
+ tst_brk(TBROK | TERRNO, "get_allowed_nodes_arr");
+ if (nnodes <= 1)
+ tst_brk(TCONF, "requires a NUMA system.");
+}
+
+static void run_test(void)
+{
+ char path[256];
+ char tmp_path[256];
+
+ snprintf(path, sizeof(path), "./%s/0", CPUSET);
+ if (access(path, F_OK) != 0)
+ SAFE_MKDIR(path, 0777);
+ snprintf(tmp_path, sizeof(tmp_path), "./%s/cpuset.cpus", path);
+ SAFE_FILE_PRINTF(tmp_path, "%s", "0");
+ snprintf(tmp_path, sizeof(tmp_path), "./%s/cpuset.mems", path);
+ SAFE_FILE_PRINTF(tmp_path, "%s", "0");
+ snprintf(tmp_path, sizeof(tmp_path), "./%s/cpuset.sched_load_balance", path);
+ SAFE_FILE_PRINTF(tmp_path, "%s", "0");
+ SAFE_FILE_PRINTF("/proc/sys/vm/nr_hugepages", "%d", 2 * nnodes);
+
+ int pid;
+ char str_hpage_size[20];
+
+ snprintf(str_hpage_size, sizeof(str_hpage_size), "%ld", hpage_size);
+ snprintf(tmp_path, sizeof(tmp_path), "%shugepagefile", MNTPOINT);
+
+ char *argv[10] = {
+ "--mmap-file",
+ "--hugepage",
+ "-s",
+ str_hpage_size,
+ "-f",
+ tmp_path,
+ NULL,
+ };
+
+ int fd = SAFE_OPEN("memory_result", O_WRONLY | O_CREAT | O_TRUNC, 0644);
+
+ SAFE_DUP2(fd, STDOUT_FILENO);
+ pid = tst_run_script("cpuset_memory_test", argv);
+ close(fd);
+
+ sleep(1);
+ snprintf(tmp_path, sizeof(tmp_path), "./%s/tasks", path);
+ SAFE_FILE_PRINTF(tmp_path, "%d", pid);
+ kill(pid, SIGUSR1);
+ sleep(1);
+ kill(pid, SIGUSR1);
+ sleep(1);
+ kill(pid, SIGINT);
+ SAFE_WAITPID(pid, NULL, 0);
+
+ char node[20];
+ FILE *file;
+
+ file = SAFE_FOPEN("memory_result", "r");
+
+ if (fgets(node, sizeof(node), file) == NULL)
+ tst_res(TFAIL, "read memory_result failed");
+
+ fclose(file);
+
+ TST_EXP_PASS(strncmp(node, "0", 1));
+}
+
+static void setup(void)
+{
+ count_cpus_mems();
+
+ hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;
+ SAFE_MKDIR(CPUSET, 0777);
+ SAFE_MOUNT("cpuset", CPUSET, "cgroup", 0, "cpuset");
+}
+
+static void cleanup(void)
+{
+ SAFE_UMOUNT(CPUSET);
+}
+
+static struct tst_test test = {
+ .needs_root = 1,
+ .runs_script = 1,
+ .mntpoint = MNTPOINT,
+ .needs_hugetlbfs = 1,
+ .setup = setup,
+ .forks_child = 1,
+ .cleanup = cleanup,
+ .test_all = run_test,
+ .hugepages = {3, TST_NEEDS},
+ .save_restore = (const struct tst_path_val[]) {
+ {"/proc/sys/vm/nr_hugepages", NULL, TST_SR_TBROK},
+ {}
+ },
+};
+
+#else
+TST_TEST_TCONF(NUMA_ERROR_MSG);
+#endif
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v3] cpuset02: Reimplementing the test6 of cpuset_memory_testset.sh as a separate C testcase
2024-09-26 6:19 ` [LTP] [PATCH v3] " Wei Gao via ltp
@ 2024-09-27 10:30 ` Cyril Hrubis
2024-09-30 13:58 ` [LTP] [PATCH v4] " Wei Gao via ltp
1 sibling, 0 replies; 62+ messages in thread
From: Cyril Hrubis @ 2024-09-27 10:30 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi!
> diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
> index d88484fa1..0845297cb 100644
> --- a/testcases/kernel/mem/.gitignore
> +++ b/testcases/kernel/mem/.gitignore
> @@ -1,4 +1,5 @@
> /cpuset/cpuset01
> +/cpuset/cpuset02
> /hugetlb/hugefallocate/hugefallocate01
> /hugetlb/hugefallocate/hugefallocate02
> /hugetlb/hugefork/hugefork01
> diff --git a/testcases/kernel/mem/cpuset/cpuset02.c b/testcases/kernel/mem/cpuset/cpuset02.c
> new file mode 100644
> index 000000000..05ed5c791
> --- /dev/null
> +++ b/testcases/kernel/mem/cpuset/cpuset02.c
> @@ -0,0 +1,147 @@
> +// SPDX-License-Identifier: LGPL-2.1-or-later
> +/*
> + * Copyright (c) 2009 FUJITSU LIMITED Miao Xie <miaox@cn.fujitsu.com>
> + * Copyright (c) 2023 SUSE LLC <wegao@suse.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * This is reimplementing the test6 of cpuset_memory_testset.sh
This is _WRONG_.
You have to describe what the test does here, not where it came from.
> + */
> +
> +#define _GNU_SOURCE
> +#include <stdio.h>
> +#include <sys/mount.h>
> +#include <limits.h>
> +#include <sys/param.h>
> +#include <sys/types.h>
> +
> +#include "tst_test.h"
> +
> +#if HAVE_NUMA_H
> +#include <numa.h>
> +#endif
> +#if HAVE_NUMAIF_H
> +#include <numaif.h>
> +#endif
> +
> +#include "tst_safe_stdio.h"
> +#include "mem.h"
> +#include "numa_helper.h"
> +
> +#define MNTPOINT "hugetlbfs/"
> +#define CPUSET "cpuset_mnt"
> +
> +#ifdef HAVE_NUMA_V2
> +
> +static long hpage_size;
> +static int ncpus;
> +static int *nodes;
> +static int nnodes;
> +
> +static void count_cpus_mems(void)
> +{
> + while (path_exist(PATH_SYS_SYSTEM "/cpu/cpu%d", ncpus))
> + ncpus++;
> + if (get_allowed_nodes_arr(NH_MEMS | NH_CPUS, &nnodes, &nodes) < 0)
> + tst_brk(TBROK | TERRNO, "get_allowed_nodes_arr");
> + if (nnodes <= 1)
> + tst_brk(TCONF, "requires a NUMA system.");
> +}
You must use the tst_get_nodemap() instead which also allows you to
specify how much free memory is required for each NUMA node.
> +static void run_test(void)
> +{
> + char path[256];
> + char tmp_path[256];
> +
> + snprintf(path, sizeof(path), "./%s/0", CPUSET);
> + if (access(path, F_OK) != 0)
> + SAFE_MKDIR(path, 0777);
> + snprintf(tmp_path, sizeof(tmp_path), "./%s/cpuset.cpus", path);
> + SAFE_FILE_PRINTF(tmp_path, "%s", "0");
> + snprintf(tmp_path, sizeof(tmp_path), "./%s/cpuset.mems", path);
> + SAFE_FILE_PRINTF(tmp_path, "%s", "0");
> + snprintf(tmp_path, sizeof(tmp_path), "./%s/cpuset.sched_load_balance", path);
> + SAFE_FILE_PRINTF(tmp_path, "%s", "0");
> + SAFE_FILE_PRINTF("/proc/sys/vm/nr_hugepages", "%d", 2 * nnodes);
> +
> + int pid;
> + char str_hpage_size[20];
> +
> + snprintf(str_hpage_size, sizeof(str_hpage_size), "%ld", hpage_size);
> + snprintf(tmp_path, sizeof(tmp_path), "%shugepagefile", MNTPOINT);
> +
> + char *argv[10] = {
> + "--mmap-file",
> + "--hugepage",
> + "-s",
> + str_hpage_size,
> + "-f",
> + tmp_path,
> + NULL,
> + };
> +
> + int fd = SAFE_OPEN("memory_result", O_WRONLY | O_CREAT | O_TRUNC, 0644);
> +
> + SAFE_DUP2(fd, STDOUT_FILENO);
> + pid = tst_run_script("cpuset_memory_test", argv);
> + close(fd);
> +
> + sleep(1);
> + snprintf(tmp_path, sizeof(tmp_path), "./%s/tasks", path);
> + SAFE_FILE_PRINTF(tmp_path, "%d", pid);
> + kill(pid, SIGUSR1);
> + sleep(1);
> + kill(pid, SIGUSR1);
> + sleep(1);
> + kill(pid, SIGINT);
> + SAFE_WAITPID(pid, NULL, 0);
> +
> + char node[20];
> + FILE *file;
> +
> + file = SAFE_FOPEN("memory_result", "r");
> +
> + if (fgets(node, sizeof(node), file) == NULL)
> + tst_res(TFAIL, "read memory_result failed");
> +
> + fclose(file);
The whole point of the rewrite is to get rid of this mess where we
propagate the test results in files.
The code that allocates the memory has to be in this test and use proper
synchronization between processes, i.e. checkpoints. This would also
avoid the need to propagate test results because the forked child could
report results directly.
> + TST_EXP_PASS(strncmp(node, "0", 1));
> +}
> +
> +static void setup(void)
> +{
> + count_cpus_mems();
> +
> + hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;
> + SAFE_MKDIR(CPUSET, 0777);
> + SAFE_MOUNT("cpuset", CPUSET, "cgroup", 0, "cpuset");
You have to use the .needs_cgroup_ctrls in tst_test instead.
> +}
> +
> +static void cleanup(void)
> +{
> + SAFE_UMOUNT(CPUSET);
> +}
> +
> +static struct tst_test test = {
> + .needs_root = 1,
> + .runs_script = 1,
> + .mntpoint = MNTPOINT,
> + .needs_hugetlbfs = 1,
> + .setup = setup,
> + .forks_child = 1,
> + .cleanup = cleanup,
> + .test_all = run_test,
> + .hugepages = {3, TST_NEEDS},
> + .save_restore = (const struct tst_path_val[]) {
> + {"/proc/sys/vm/nr_hugepages", NULL, TST_SR_TBROK},
> + {}
> + },
> +};
> +
> +#else
> +TST_TEST_TCONF(NUMA_ERROR_MSG);
> +#endif
> --
> 2.35.3
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* [LTP] [PATCH v4] cpuset02: Reimplementing the test6 of cpuset_memory_testset.sh as a separate C testcase
2024-09-26 6:19 ` [LTP] [PATCH v3] " Wei Gao via ltp
2024-09-27 10:30 ` Cyril Hrubis
@ 2024-09-30 13:58 ` Wei Gao via ltp
2024-11-01 10:58 ` Petr Vorel
` (2 more replies)
1 sibling, 3 replies; 62+ messages in thread
From: Wei Gao via ltp @ 2024-09-30 13:58 UTC (permalink / raw)
To: ltp
Signed-off-by: Wei Gao <wegao@suse.com>
---
lib/tst_cgroup.c | 1 +
runtest/mm | 1 +
testcases/kernel/mem/.gitignore | 1 +
testcases/kernel/mem/cpuset/Makefile | 7 ++
testcases/kernel/mem/cpuset/cpuset02.c | 140 +++++++++++++++++++++++++
5 files changed, 150 insertions(+)
create mode 100644 testcases/kernel/mem/cpuset/cpuset02.c
diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
index 6055015eb..1404116a5 100644
--- a/lib/tst_cgroup.c
+++ b/lib/tst_cgroup.c
@@ -203,6 +203,7 @@ static const struct cgroup_file cpuset_ctrl_files[] = {
{ "cpuset.cpus", "cpuset.cpus", CTRL_CPUSET },
{ "cpuset.mems", "cpuset.mems", CTRL_CPUSET },
{ "cpuset.memory_migrate", "cpuset.memory_migrate", CTRL_CPUSET },
+ { "cpuset.sched_load_balance", "cpuset.sched_load_balance", CTRL_CPUSET },
{ }
};
diff --git a/runtest/mm b/runtest/mm
index 6a8cd0b9d..845874c41 100644
--- a/runtest/mm
+++ b/runtest/mm
@@ -75,6 +75,7 @@ ksm06_2 ksm06 -n 8000
ksm07 ksm07
cpuset01 cpuset01
+cpuset02 cpuset02
oom01 oom01
oom02 oom02
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index d88484fa1..0845297cb 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -1,4 +1,5 @@
/cpuset/cpuset01
+/cpuset/cpuset02
/hugetlb/hugefallocate/hugefallocate01
/hugetlb/hugefallocate/hugefallocate02
/hugetlb/hugefork/hugefork01
diff --git a/testcases/kernel/mem/cpuset/Makefile b/testcases/kernel/mem/cpuset/Makefile
index 8e41c0223..366d67ce9 100644
--- a/testcases/kernel/mem/cpuset/Makefile
+++ b/testcases/kernel/mem/cpuset/Makefile
@@ -19,6 +19,13 @@
top_srcdir ?= ../../../..
+LTPLIBS = numa
+
include $(top_srcdir)/include/mk/testcases.mk
include $(top_srcdir)/testcases/kernel/mem/include/libmem.mk
+
+LDLIBS += $(NUMA_LIBS)
+LDLIBS += $(top_srcdir)/testcases/kernel/controllers/cpuset/cpuset_lib/libcpu_set.a
+LTPLDLIBS = -lltpnuma
+
include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/mem/cpuset/cpuset02.c b/testcases/kernel/mem/cpuset/cpuset02.c
new file mode 100644
index 000000000..a62c98b3f
--- /dev/null
+++ b/testcases/kernel/mem/cpuset/cpuset02.c
@@ -0,0 +1,140 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (c) 2009 FUJITSU LIMITED Miao Xie <miaox@cn.fujitsu.com>
+ * Copyright (c) 2023 SUSE LLC <wegao@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test check cpuset's mems work with hugepage file.
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include "tst_test.h"
+#include "../../controllers/cpuset/cpuset_lib/cpuset.h"
+
+#ifdef HAVE_NUMA_V2
+#include <numa.h>
+#include <numaif.h>
+#include <errno.h>
+#include "tst_numa.h"
+#include "tst_safe_stdio.h"
+#include "mem.h"
+#include "numa_helper.h"
+
+#define MNTPOINT "hugetlbfs/"
+#define HUGE_PAGE_FILE MNTPOINT "hugepagefile"
+#define PAGES_ALLOCATED 16u
+
+static long hpage_size;
+static struct tst_nodemap *node;
+static struct tst_cg_group *cg_cpuset_0;
+
+static void count_cpus_mems(void)
+{
+ node = tst_get_nodemap(TST_NUMA_MEM, PAGES_ALLOCATED * getpagesize() / 1024);
+ if (node->cnt <= 1)
+ tst_brk(TCONF, "test requires NUMA system");
+}
+
+static void touch_memory_and_check_node(char *p, int size)
+{
+ int i;
+ int pagesize = sysconf(_SC_PAGESIZE);
+
+ for (i = 0; i < size; i += pagesize)
+ p[i] = 0xef;
+
+ if (cpuset_addr2node(p) == 0)
+ tst_res(TPASS, "check node pass");
+ else
+ tst_res(TFAIL, "check node failed");
+}
+
+static void child(void)
+{
+ char *p;
+ int fd_hugepage;
+
+ TST_CHECKPOINT_WAIT(0);
+
+ fd_hugepage = SAFE_OPEN(HUGE_PAGE_FILE, O_CREAT | O_RDWR, 0755);
+ p = SAFE_MMAP(NULL, hpage_size, PROT_WRITE | PROT_READ,
+ MAP_SHARED, fd_hugepage, 0);
+
+ touch_memory_and_check_node(p, hpage_size);
+
+ SAFE_MUNMAP(p, hpage_size);
+ SAFE_CLOSE(fd_hugepage);
+
+ TST_CHECKPOINT_WAKE(1);
+}
+
+static void run_test(void)
+{
+ int pid;
+
+ cg_cpuset_0 = tst_cg_group_mk(tst_cg, "0");
+
+ SAFE_CG_PRINT(cg_cpuset_0, "cpuset.cpus", "0");
+ SAFE_CG_PRINT(cg_cpuset_0, "cpuset.mems", "0");
+ SAFE_CG_PRINT(cg_cpuset_0, "cpuset.sched_load_balance", "0");
+
+ SAFE_FILE_PRINTF("/proc/sys/vm/nr_hugepages", "%d", 2 * node->cnt);
+
+ pid = SAFE_FORK();
+ if (!pid) {
+ child();
+ } else {
+ SAFE_CG_PRINTF(cg_cpuset_0, "cgroup.procs", "%d", pid);
+
+ TST_CHECKPOINT_WAKE(0);
+ TST_CHECKPOINT_WAIT(1);
+
+ SAFE_WAITPID(pid, NULL, 0);
+
+ cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
+ }
+}
+
+static void setup(void)
+{
+ count_cpus_mems();
+
+ hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;
+}
+
+static void cleanup(void)
+{
+ if (cg_cpuset_0)
+ cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
+}
+
+static struct tst_test test = {
+ .needs_root = 1,
+ .runs_script = 1,
+ .mntpoint = MNTPOINT,
+ .needs_hugetlbfs = 1,
+ .setup = setup,
+ .forks_child = 1,
+ .cleanup = cleanup,
+ .test_all = run_test,
+ .hugepages = {3, TST_NEEDS},
+ .needs_checkpoints = 1,
+ .needs_cgroup_ctrls = (const char *const []){ "cpuset", NULL },
+ .save_restore = (const struct tst_path_val[]) {
+ {"/proc/sys/vm/nr_hugepages", NULL, TST_SR_TBROK},
+ {}
+ },
+};
+
+#else
+TST_TEST_TCONF(NUMA_ERROR_MSG);
+#endif
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v4] cpuset02: Reimplementing the test6 of cpuset_memory_testset.sh as a separate C testcase
2024-09-30 13:58 ` [LTP] [PATCH v4] " Wei Gao via ltp
@ 2024-11-01 10:58 ` Petr Vorel
2024-11-05 5:30 ` Wei Gao via ltp
2024-11-05 11:44 ` Petr Vorel
2024-12-09 6:01 ` [LTP] [PATCH v5 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2 siblings, 1 reply; 62+ messages in thread
From: Petr Vorel @ 2024-11-01 10:58 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi Wei, Cyril,
> "Reimplementing the test6 of cpuset_memory_testset.sh as a separate C testcase"
This could be followed by removing test6 from cpuset_memory_testset.sh?
The conversion itself from shell test test6 LGTM.
I suppose the reason is that moving code to C improves stability of the test.
But this would be nice to mention in the commit message. (Remember "what" versus
"why" - often the reason for the change is more important that describing the
change.)
> index 8e41c0223..366d67ce9 100644
> --- a/testcases/kernel/mem/cpuset/Makefile
> +++ b/testcases/kernel/mem/cpuset/Makefile
> @@ -19,6 +19,13 @@
> top_srcdir ?= ../../../..
> +LTPLIBS = numa
> +
> include $(top_srcdir)/include/mk/testcases.mk
> include $(top_srcdir)/testcases/kernel/mem/include/libmem.mk
> +
> +LDLIBS += $(NUMA_LIBS)
> +LDLIBS += $(top_srcdir)/testcases/kernel/controllers/cpuset/cpuset_lib/libcpu_set.a
This is not enough, because there is no build dependency on libcpu_set.a.
Other tests which depends on libcpu_set.a are in the subdirectories (e.g.
testcases/kernel/controllers/cpuset/cpuset_hotplug_test/) and they use
testcases/kernel/controllers/cpuset/Makefile.inc. Can you somehow use it?
Maybe we should move cpuset_lib code to libs/ directory, when used elsewhere.
That would also help to avoid ugly includes like:
> +#include "../../controllers/cpuset/cpuset_lib/cpuset.h"
(This could be also improved with CFLAGS += -I../../controllers/cpuset/cpuset_lib/.)
> +LTPLDLIBS = -lltpnuma
> +
> include $(top_srcdir)/include/mk/generic_leaf_target.mk
> diff --git a/testcases/kernel/mem/cpuset/cpuset02.c b/testcases/kernel/mem/cpuset/cpuset02.c
> new file mode 100644
> index 000000000..a62c98b3f
> --- /dev/null
> +++ b/testcases/kernel/mem/cpuset/cpuset02.c
> @@ -0,0 +1,140 @@
> +// SPDX-License-Identifier: LGPL-2.1-or-later
> +/*
> + * Copyright (c) 2009 FUJITSU LIMITED Miao Xie <miaox@cn.fujitsu.com>
> + * Copyright (c) 2023 SUSE LLC <wegao@suse.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * This test check cpuset's mems work with hugepage file.
Maybe: Test checks cpuset.mems works with hugepage file.
> + *
Please remove the blank line above ^.
> + */
...
> +static void count_cpus_mems(void)
> +{
> + node = tst_get_nodemap(TST_NUMA_MEM, PAGES_ALLOCATED * getpagesize() / 1024);
> + if (node->cnt <= 1)
> + tst_brk(TCONF, "test requires NUMA system");
> +}
nit: Function used only once, I would move the code into setup().
Later (separate effort), this function (with size parameter) could be in
libs/numa/tst_numa.c, because it's used in many tests, or even added into struct
tst_test.
> +static void run_test(void)
> +{
...
> + pid = SAFE_FORK();
> + if (!pid) {
> + child();
> + } else {
> + SAFE_CG_PRINTF(cg_cpuset_0, "cgroup.procs", "%d", pid);
> +
> + TST_CHECKPOINT_WAKE(0);
> + TST_CHECKPOINT_WAIT(1);
> +
> + SAFE_WAITPID(pid, NULL, 0);
> +
> + cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
> + }
Very nit: IMHO saving indent would be more readable:
if (!pid) {
child();
return; // or call exit() in child() and no return here.
}
SAFE_CG_PRINTF(cg_cpuset_0, "cgroup.procs", "%d", pid);
TST_CHECKPOINT_WAKE(0);
TST_CHECKPOINT_WAIT(1);
SAFE_WAITPID(pid, NULL, 0);
cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v4] cpuset02: Reimplementing the test6 of cpuset_memory_testset.sh as a separate C testcase
2024-11-01 10:58 ` Petr Vorel
@ 2024-11-05 5:30 ` Wei Gao via ltp
0 siblings, 0 replies; 62+ messages in thread
From: Wei Gao via ltp @ 2024-11-05 5:30 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
On Fri, Nov 01, 2024 at 11:58:08AM +0100, Petr Vorel wrote:
> Hi Wei, Cyril,
>
> > "Reimplementing the test6 of cpuset_memory_testset.sh as a separate C testcase"
> This could be followed by removing test6 from cpuset_memory_testset.sh?
>
> The conversion itself from shell test test6 LGTM.
>
> I suppose the reason is that moving code to C improves stability of the test.
> But this would be nice to mention in the commit message. (Remember "what" versus
> "why" - often the reason for the change is more important that describing the
> change.)
>
> > index 8e41c0223..366d67ce9 100644
> > --- a/testcases/kernel/mem/cpuset/Makefile
> > +++ b/testcases/kernel/mem/cpuset/Makefile
> > @@ -19,6 +19,13 @@
>
> > top_srcdir ?= ../../../..
>
> > +LTPLIBS = numa
> > +
> > include $(top_srcdir)/include/mk/testcases.mk
> > include $(top_srcdir)/testcases/kernel/mem/include/libmem.mk
> > +
> > +LDLIBS += $(NUMA_LIBS)
> > +LDLIBS += $(top_srcdir)/testcases/kernel/controllers/cpuset/cpuset_lib/libcpu_set.a
> This is not enough, because there is no build dependency on libcpu_set.a.
>
> Other tests which depends on libcpu_set.a are in the subdirectories (e.g.
> testcases/kernel/controllers/cpuset/cpuset_hotplug_test/) and they use
> testcases/kernel/controllers/cpuset/Makefile.inc. Can you somehow use it?
>
> Maybe we should move cpuset_lib code to libs/ directory, when used elsewhere.
I have created another new patch for move lib code:
https://patchwork.ozlabs.org/project/ltp/patch/20241105052507.29630-1-wegao@suse.com/
>
> That would also help to avoid ugly includes like:
> > +#include "../../controllers/cpuset/cpuset_lib/cpuset.h"
>
> (This could be also improved with CFLAGS += -I../../controllers/cpuset/cpuset_lib/.)
>
>
> > +LTPLDLIBS = -lltpnuma
> > +
> > include $(top_srcdir)/include/mk/generic_leaf_target.mk
> > diff --git a/testcases/kernel/mem/cpuset/cpuset02.c b/testcases/kernel/mem/cpuset/cpuset02.c
> > new file mode 100644
> > index 000000000..a62c98b3f
> > --- /dev/null
> > +++ b/testcases/kernel/mem/cpuset/cpuset02.c
> > @@ -0,0 +1,140 @@
> > +// SPDX-License-Identifier: LGPL-2.1-or-later
> > +/*
> > + * Copyright (c) 2009 FUJITSU LIMITED Miao Xie <miaox@cn.fujitsu.com>
> > + * Copyright (c) 2023 SUSE LLC <wegao@suse.com>
> > + */
> > +
> > +/*\
> > + * [Description]
> > + *
> > + * This test check cpuset's mems work with hugepage file.
> Maybe: Test checks cpuset.mems works with hugepage file.
>
> > + *
> Please remove the blank line above ^.
> > + */
> ...
>
> > +static void count_cpus_mems(void)
> > +{
> > + node = tst_get_nodemap(TST_NUMA_MEM, PAGES_ALLOCATED * getpagesize() / 1024);
> > + if (node->cnt <= 1)
> > + tst_brk(TCONF, "test requires NUMA system");
> > +}
> nit: Function used only once, I would move the code into setup().
>
> Later (separate effort), this function (with size parameter) could be in
> libs/numa/tst_numa.c, because it's used in many tests, or even added into struct
> tst_test.
>
> > +static void run_test(void)
> > +{
> ...
> > + pid = SAFE_FORK();
> > + if (!pid) {
> > + child();
> > + } else {
> > + SAFE_CG_PRINTF(cg_cpuset_0, "cgroup.procs", "%d", pid);
> > +
> > + TST_CHECKPOINT_WAKE(0);
> > + TST_CHECKPOINT_WAIT(1);
> > +
> > + SAFE_WAITPID(pid, NULL, 0);
> > +
> > + cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
> > + }
>
> Very nit: IMHO saving indent would be more readable:
>
> if (!pid) {
> child();
> return; // or call exit() in child() and no return here.
> }
>
> SAFE_CG_PRINTF(cg_cpuset_0, "cgroup.procs", "%d", pid);
>
> TST_CHECKPOINT_WAKE(0);
> TST_CHECKPOINT_WAIT(1);
>
> SAFE_WAITPID(pid, NULL, 0);
>
> cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
>
> Kind regards,
> Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v4] cpuset02: Reimplementing the test6 of cpuset_memory_testset.sh as a separate C testcase
2024-09-30 13:58 ` [LTP] [PATCH v4] " Wei Gao via ltp
2024-11-01 10:58 ` Petr Vorel
@ 2024-11-05 11:44 ` Petr Vorel
2024-11-07 4:20 ` Wei Gao via ltp
2024-11-08 5:45 ` Wei Gao via ltp
2024-12-09 6:01 ` [LTP] [PATCH v5 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2 siblings, 2 replies; 62+ messages in thread
From: Petr Vorel @ 2024-11-05 11:44 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi Wei,
This fails to build.
https://github.com/pevik/ltp/actions/runs/11628250882
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v4] cpuset02: Reimplementing the test6 of cpuset_memory_testset.sh as a separate C testcase
2024-11-05 11:44 ` Petr Vorel
@ 2024-11-07 4:20 ` Wei Gao via ltp
2024-11-08 5:45 ` Wei Gao via ltp
1 sibling, 0 replies; 62+ messages in thread
From: Wei Gao via ltp @ 2024-11-07 4:20 UTC (permalink / raw)
To: Petr Vorel, Cyril Hrubis; +Cc: ltp
On Tue, Nov 05, 2024 at 12:44:27PM +0100, Petr Vorel wrote:
> Hi Wei,
>
> This fails to build.
> https://github.com/pevik/ltp/actions/runs/11628250882
>
> Kind regards,
> Petr
Hi Cyril / Petr
I have a question before my next patch.
The old cpuset_memory_testset.sh test is focus ONLY on cgroupv1 test,
it setup cgroupv1 mnt point on /dev/cpuset, even on cgroupv2 support system.
If i add needs_cgroup_ver = TST_CG_V1 on current v4 patch, this test will be
skipped on system which support cgroupv2, since current cgroup framework will
detect cgroupv2 mount point and skip test.
If i do not add needs_cgroup_ver = TST_CG_V1 then error will happen since cgroupv2
does not support cpuset.sched_load_balance anymore.
Finally i have to add new flag such as force_cgroup_ver = TST_CG_V1, so the test
case can continue create cgroupv1 mnt point to continue cgroupv1 test regardless
detect cgroupv2 or not. What's your suggestion? Thanks.
Regards
Gao Wei
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v4] cpuset02: Reimplementing the test6 of cpuset_memory_testset.sh as a separate C testcase
2024-11-05 11:44 ` Petr Vorel
2024-11-07 4:20 ` Wei Gao via ltp
@ 2024-11-08 5:45 ` Wei Gao via ltp
1 sibling, 0 replies; 62+ messages in thread
From: Wei Gao via ltp @ 2024-11-08 5:45 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
On Tue, Nov 05, 2024 at 12:44:27PM +0100, Petr Vorel wrote:
> Hi Wei,
>
> This fails to build.
> https://github.com/pevik/ltp/actions/runs/11628250882
>
> Kind regards,
> Petr
I also make another proposal for cpuset02 test case.
This will force check/create cgroupv1 test regardless current test system support cgroupv2 or not.
https://patchwork.ozlabs.org/project/ltp/patch/20241108053710.8639-1-wegao@suse.com/
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* [LTP] [PATCH v5 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2024-09-30 13:58 ` [LTP] [PATCH v4] " Wei Gao via ltp
2024-11-01 10:58 ` Petr Vorel
2024-11-05 11:44 ` Petr Vorel
@ 2024-12-09 6:01 ` Wei Gao via ltp
2024-12-09 6:01 ` [LTP] [PATCH v5 1/2] " Wei Gao via ltp
` (2 more replies)
2 siblings, 3 replies; 62+ messages in thread
From: Wei Gao via ltp @ 2024-12-09 6:01 UTC (permalink / raw)
To: ltp
Wei Gao (2):
cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
cpuset_memory_testset.sh: Remove test6
lib/tst_cgroup.c | 1 +
runtest/mm | 1 +
.../cpuset_memory_testset.sh | 37 +----
testcases/kernel/mem/.gitignore | 1 +
testcases/kernel/mem/cpuset/Makefile | 6 +
testcases/kernel/mem/cpuset/cpuset02.c | 142 ++++++++++++++++++
.../mq_timedreceive/mq_timedreceive01.c | 80 +++++++---
7 files changed, 212 insertions(+), 56 deletions(-)
create mode 100644 testcases/kernel/mem/cpuset/cpuset02.c
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* [LTP] [PATCH v5 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2024-12-09 6:01 ` [LTP] [PATCH v5 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
@ 2024-12-09 6:01 ` Wei Gao via ltp
2025-02-27 16:02 ` Petr Vorel
2024-12-09 6:01 ` [LTP] [PATCH v5 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
2025-03-05 5:08 ` [LTP] [PATCH v6 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2 siblings, 1 reply; 62+ messages in thread
From: Wei Gao via ltp @ 2024-12-09 6:01 UTC (permalink / raw)
To: ltp
Base Cyril Hrubis's suggestion [1].
We should stop applying band aids over the mess called cpuset tests
and start actually rewriting them into something saner, and start by
reimplementing the test6 as a separate C testcase so that we can make
use of all the infrastructure for hugepages we have in the tst_test.
[1] https://patchwork.ozlabs.org/project/ltp/patch/20240801104004.15514-1-wegao@suse.com/
Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Wei Gao <wegao@suse.com>
---
lib/tst_cgroup.c | 1 +
runtest/mm | 1 +
testcases/kernel/mem/.gitignore | 1 +
testcases/kernel/mem/cpuset/Makefile | 6 +
testcases/kernel/mem/cpuset/cpuset02.c | 142 ++++++++++++++++++
.../mq_timedreceive/mq_timedreceive01.c | 80 +++++++---
6 files changed, 210 insertions(+), 21 deletions(-)
create mode 100644 testcases/kernel/mem/cpuset/cpuset02.c
diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
index 6055015eb..1404116a5 100644
--- a/lib/tst_cgroup.c
+++ b/lib/tst_cgroup.c
@@ -203,6 +203,7 @@ static const struct cgroup_file cpuset_ctrl_files[] = {
{ "cpuset.cpus", "cpuset.cpus", CTRL_CPUSET },
{ "cpuset.mems", "cpuset.mems", CTRL_CPUSET },
{ "cpuset.memory_migrate", "cpuset.memory_migrate", CTRL_CPUSET },
+ { "cpuset.sched_load_balance", "cpuset.sched_load_balance", CTRL_CPUSET },
{ }
};
diff --git a/runtest/mm b/runtest/mm
index d8e62af81..5af29b0ea 100644
--- a/runtest/mm
+++ b/runtest/mm
@@ -75,6 +75,7 @@ ksm06_2 ksm06 -n 8000
ksm07 ksm07
cpuset01 cpuset01
+cpuset02 cpuset02
oom01 oom01
oom02 oom02
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index 699e022fb..e24e96001 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -1,4 +1,5 @@
/cpuset/cpuset01
+/cpuset/cpuset02
/hugetlb/hugefallocate/hugefallocate01
/hugetlb/hugefallocate/hugefallocate02
/hugetlb/hugefork/hugefork01
diff --git a/testcases/kernel/mem/cpuset/Makefile b/testcases/kernel/mem/cpuset/Makefile
index 8e41c0223..9311985b1 100644
--- a/testcases/kernel/mem/cpuset/Makefile
+++ b/testcases/kernel/mem/cpuset/Makefile
@@ -19,6 +19,12 @@
top_srcdir ?= ../../../..
+LTPLIBS = numa
+
include $(top_srcdir)/include/mk/testcases.mk
include $(top_srcdir)/testcases/kernel/mem/include/libmem.mk
+
+LDLIBS += $(NUMA_LIBS)
+LTPLDLIBS = -lltpnuma
+
include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/mem/cpuset/cpuset02.c b/testcases/kernel/mem/cpuset/cpuset02.c
new file mode 100644
index 000000000..2bd226bab
--- /dev/null
+++ b/testcases/kernel/mem/cpuset/cpuset02.c
@@ -0,0 +1,142 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (c) 2009 FUJITSU LIMITED Miao Xie <miaox@cn.fujitsu.com>
+ * Copyright (c) 2023 SUSE LLC <wegao@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test checks cpuset.mems works with hugepage file.
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include "tst_test.h"
+
+#ifdef HAVE_NUMA_V2
+#include <numa.h>
+#include <numaif.h>
+#include <errno.h>
+#include "tst_numa.h"
+#include "tst_safe_stdio.h"
+#include "mem.h"
+#include "numa_helper.h"
+
+#define MNTPOINT "hugetlbfs/"
+#define HUGE_PAGE_FILE MNTPOINT "hugepagefile"
+#define PAGES_ALLOCATED 16u
+
+static long hpage_size;
+static struct tst_nodemap *node;
+static struct tst_cg_group *cg_cpuset_0;
+
+static void touch_memory_and_check_node(char *p, int size)
+{
+ int i;
+ int node = -1;
+ long ret;
+ int pagesize = sysconf(_SC_PAGESIZE);
+
+ for (i = 0; i < size; i += pagesize)
+ p[i] = 0xef;
+
+ ret = get_mempolicy(&node, NULL, 0, p, MPOL_F_NODE | MPOL_F_ADDR);
+ if (ret < 0)
+ tst_brk(TBROK | TERRNO, "get_mempolicy() failed");
+
+ if (node == 0)
+ tst_res(TPASS, "check node pass");
+ else
+ tst_res(TFAIL, "check node failed");
+}
+
+static void child(void)
+{
+ char *p;
+ int fd_hugepage;
+
+ TST_CHECKPOINT_WAIT(0);
+
+ fd_hugepage = SAFE_OPEN(HUGE_PAGE_FILE, O_CREAT | O_RDWR, 0755);
+ p = SAFE_MMAP(NULL, hpage_size, PROT_WRITE | PROT_READ,
+ MAP_SHARED, fd_hugepage, 0);
+
+ touch_memory_and_check_node(p, hpage_size);
+
+ SAFE_MUNMAP(p, hpage_size);
+ SAFE_CLOSE(fd_hugepage);
+
+ TST_CHECKPOINT_WAKE(1);
+}
+
+static void run_test(void)
+{
+ int pid;
+
+ cg_cpuset_0 = tst_cg_group_mk(tst_cg, "0");
+
+ SAFE_CG_PRINT(cg_cpuset_0, "cpuset.cpus", "0");
+ SAFE_CG_PRINT(cg_cpuset_0, "cpuset.mems", "0");
+ SAFE_CG_PRINT(cg_cpuset_0, "cpuset.sched_load_balance", "0");
+
+ SAFE_FILE_PRINTF("/proc/sys/vm/nr_hugepages", "%d", 2 * node->cnt);
+
+ pid = SAFE_FORK();
+
+ if (!pid) {
+ child();
+ return;
+ }
+
+ SAFE_CG_PRINTF(cg_cpuset_0, "cgroup.procs", "%d", pid);
+
+ TST_CHECKPOINT_WAKE(0);
+ TST_CHECKPOINT_WAIT(1);
+
+ SAFE_WAITPID(pid, NULL, 0);
+
+ cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
+}
+
+static void setup(void)
+{
+ node = tst_get_nodemap(TST_NUMA_MEM, PAGES_ALLOCATED * getpagesize() / 1024);
+ if (node->cnt <= 1)
+ tst_brk(TCONF, "test requires NUMA system");
+
+ hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;
+}
+
+static void cleanup(void)
+{
+ if (cg_cpuset_0)
+ cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
+}
+
+static struct tst_test test = {
+ .needs_root = 1,
+ .runs_script = 1,
+ .mntpoint = MNTPOINT,
+ .needs_hugetlbfs = 1,
+ .setup = setup,
+ .forks_child = 1,
+ .cleanup = cleanup,
+ .test_all = run_test,
+ .hugepages = {3, TST_NEEDS},
+ .needs_checkpoints = 1,
+ .needs_cgroup_ver = TST_CG_V1,
+ .needs_cgroup_ctrls = (const char *const []){ "cpuset", NULL },
+ .save_restore = (const struct tst_path_val[]) {
+ {"/proc/sys/vm/nr_hugepages", NULL, TST_SR_TBROK},
+ {}
+ },
+};
+
+#else
+TST_TEST_TCONF(NUMA_ERROR_MSG);
+#endif
diff --git a/testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c b/testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c
index be437e19a..6dadc3de6 100644
--- a/testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c
+++ b/testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c
@@ -145,32 +145,16 @@ static void setup(void)
setup_common();
}
-static void do_test(unsigned int i)
+
+static void verify_mqt_receive(unsigned int i, pid_t pid)
{
struct time64_variants *tv = &variants[tst_variant];
const struct test_case *tc = &tcase[i];
- unsigned int j;
- unsigned int prio;
size_t len = MAX_MSGSIZE;
char rmsg[len];
- pid_t pid = -1;
void *abs_timeout;
-
- tst_ts_set_sec(&ts, tc->tv_sec);
- tst_ts_set_nsec(&ts, tc->tv_nsec);
-
- if (tc->signal)
- pid = set_sig(tc->rq, tv->clock_gettime);
-
- if (tc->timeout)
- set_timeout(tc->rq, tv->clock_gettime);
-
- if (tc->send) {
- if (tv->mqt_send(*tc->fd, smsg, tc->len, tc->prio, NULL) < 0) {
- tst_res(TFAIL | TTERRNO, "mq_timedsend() failed");
- return;
- }
- }
+ unsigned int j;
+ unsigned int prio;
if (tc->invalid_msg)
len -= 1;
@@ -199,7 +183,7 @@ static void do_test(unsigned int i)
return;
}
- if (tc->len != TST_RET) {
+ if ((long)tc->len != TST_RET) {
tst_res(TFAIL, "mq_timedreceive() wrong length %ld, expected %u",
TST_RET, tc->len);
return;
@@ -224,6 +208,60 @@ static void do_test(unsigned int i)
TST_RET, prio, len);
}
+static void test_bad_addr(unsigned int i)
+{
+ struct time64_variants *tv = &variants[tst_variant];
+ pid_t pid;
+ int status;
+
+ pid = SAFE_FORK();
+ if (!pid) {
+ verify_mqt_receive(i, pid);
+ _exit(0);
+ }
+
+ SAFE_WAITPID(pid, &status, 0);
+
+ if (WIFEXITED(status) && !WEXITSTATUS(status))
+ return;
+
+ if (tv->ts_type == TST_LIBC_TIMESPEC &&
+ WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) {
+ tst_res(TPASS, "Child killed by expected signal");
+ return;
+ }
+
+ tst_res(TFAIL, "Child %s", tst_strstatus(status));
+}
+
+static void do_test(unsigned int i)
+{
+ struct time64_variants *tv = &variants[tst_variant];
+ const struct test_case *tc = &tcase[i];
+ pid_t pid = -1;
+
+ tst_ts_set_sec(&ts, tc->tv_sec);
+ tst_ts_set_nsec(&ts, tc->tv_nsec);
+
+ if (tc->bad_ts_addr) {
+ test_bad_addr(i);
+ return;
+ }
+
+ if (tc->signal)
+ pid = set_sig(tc->rq, tv->clock_gettime);
+
+ if (tc->timeout)
+ set_timeout(tc->rq, tv->clock_gettime);
+
+ if (tc->send && tv->mqt_send(*tc->fd, smsg, tc->len, tc->prio, NULL) < 0) {
+ tst_res(TFAIL | TTERRNO, "mq_timedsend() failed");
+ return;
+ }
+
+ verify_mqt_receive(i, pid);
+}
+
static struct tst_test test = {
.tcnt = ARRAY_SIZE(tcase),
.test = do_test,
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 62+ messages in thread
* [LTP] [PATCH v5 2/2] cpuset_memory_testset.sh: Remove test6
2024-12-09 6:01 ` [LTP] [PATCH v5 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2024-12-09 6:01 ` [LTP] [PATCH v5 1/2] " Wei Gao via ltp
@ 2024-12-09 6:01 ` Wei Gao via ltp
2025-02-27 16:04 ` Petr Vorel
2025-03-05 5:08 ` [LTP] [PATCH v6 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2 siblings, 1 reply; 62+ messages in thread
From: Wei Gao via ltp @ 2024-12-09 6:01 UTC (permalink / raw)
To: ltp
Signed-off-by: Wei Gao <wegao@suse.com>
---
.../cpuset_memory_testset.sh | 37 +------------------
1 file changed, 2 insertions(+), 35 deletions(-)
diff --git a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
index c1e7cea8f..fd41dc97a 100755
--- a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
+++ b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
@@ -162,41 +162,8 @@ check_hugetlbfs()
test6()
{
- cpuset_set "$CPUSET/0" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
- if [ $? -ne 0 ]; then
- cpuset_log_error $CPUSET_TMP/stderr
- tst_resm TFAIL "set general group parameter failed."
- return 1
- fi
-
- check_hugetlbfs
- if [ $? -eq 0 ]; then
- tst_resm TCONF "This system don't support hugetlbfs"
- return 0
- fi
-
- mkdir /hugetlb
- mount -t hugetlbfs none /hugetlb
-
- save_nr_hugepages=$(cat /proc/sys/vm/nr_hugepages)
- echo $((2*$nr_mems)) > /proc/sys/vm/nr_hugepages
-
- cpuset_memory_test --mmap-file --hugepage -s $HUGEPAGESIZE >"$MEMORY_RESULT" &
- simple_getresult $! "$CPUSET/0"
-
- umount /hugetlb
- rmdir /hugetlb
-
- echo $save_nr_hugepages > /proc/sys/vm/nr_hugepages
- if [ $(cat /proc/sys/vm/nr_hugepages) -ne $save_nr_hugepages ]; then
- tst_resm TFAIL "can't restore nr_hugepages(nr_hugepages = $save_nr_hugepages)."
- return 1
- fi
-
- if [ "$node" != "0" ]; then
- tst_resm TFAIL "allocate memory on the Node#$node(Expect: Node#0)."
- return 1
- fi
+ tst_resm TINFO "This test is replaced by testcases/kernel/mem/cpuset/cpuset02.c"
+ return 0
}
test7()
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v5 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2024-12-09 6:01 ` [LTP] [PATCH v5 1/2] " Wei Gao via ltp
@ 2025-02-27 16:02 ` Petr Vorel
0 siblings, 0 replies; 62+ messages in thread
From: Petr Vorel @ 2025-02-27 16:02 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi Wei,
...
> lib/tst_cgroup.c | 1 +
> runtest/mm | 1 +
> testcases/kernel/mem/.gitignore | 1 +
> testcases/kernel/mem/cpuset/Makefile | 6 +
> testcases/kernel/mem/cpuset/cpuset02.c | 142 ++++++++++++++++++
> .../mq_timedreceive/mq_timedreceive01.c | 80 +++++++---
This is completely unrelated change. Please remove it in the next version.
...
> +++ b/testcases/kernel/mem/cpuset/Makefile
> @@ -19,6 +19,12 @@
> top_srcdir ?= ../../../..
> +LTPLIBS = numa
> +
> include $(top_srcdir)/include/mk/testcases.mk
> include $(top_srcdir)/testcases/kernel/mem/include/libmem.mk
> +
> +LDLIBS += $(NUMA_LIBS)
IMHO we don't need LDLIBS += $(NUMA_LIBS) ? It compiles without it
because it's added by /testcases/kernel/include/lib.mk due Cyril's change:
6f830ea5c0 ("lib: Replace path_exist() with tst_path_exists()")
> +LTPLDLIBS = -lltpnuma
This change is related to cpuset02, it should be prefixed with cpuset02:
..
> +++ b/testcases/kernel/mem/cpuset/cpuset02.c
> @@ -0,0 +1,142 @@
> +// SPDX-License-Identifier: LGPL-2.1-or-later
> +/*
> + * Copyright (c) 2009 FUJITSU LIMITED Miao Xie <miaox@cn.fujitsu.com>
> + * Copyright (c) 2023 SUSE LLC <wegao@suse.com>
> + */
> +
> +/*\
> + * [Description]
Also please delete [Description] in next version.
> + *
> + * Test checks cpuset.mems works with hugepage file.
> + */
> +
> +#define _GNU_SOURCE
> +#include <stdio.h>
> +#include <sys/mount.h>
> +#include <limits.h>
> +#include <sys/param.h>
> +#include <sys/types.h>
> +#include "tst_test.h"
> +
> +#ifdef HAVE_NUMA_V2
> +#include <numa.h>
> +#include <numaif.h>
> +#include <errno.h>
> +#include "tst_numa.h"
> +#include "tst_safe_stdio.h"
> +#include "mem.h"
And, please, rebase. Recent Cyril's cleanup removed "mem.h", see:
decd09c5dab6ad1694857116c011e01f8cc65788~..ac1af455d3384f1bbbda994aee42aeb036c27a23
> +#include "numa_helper.h"
> +
> +#define MNTPOINT "hugetlbfs/"
> +#define HUGE_PAGE_FILE MNTPOINT "hugepagefile"
> +#define PAGES_ALLOCATED 16u
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v5 2/2] cpuset_memory_testset.sh: Remove test6
2024-12-09 6:01 ` [LTP] [PATCH v5 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
@ 2025-02-27 16:04 ` Petr Vorel
2025-03-05 4:29 ` Wei Gao via ltp
0 siblings, 1 reply; 62+ messages in thread
From: Petr Vorel @ 2025-02-27 16:04 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi Wei,
> Signed-off-by: Wei Gao <wegao@suse.com>
> ---
> .../cpuset_memory_testset.sh | 37 +------------------
> 1 file changed, 2 insertions(+), 35 deletions(-)
You're supposed to remove cpuset_memory_testset.sh entry from
runtest/controllers.
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v5 2/2] cpuset_memory_testset.sh: Remove test6
2025-02-27 16:04 ` Petr Vorel
@ 2025-03-05 4:29 ` Wei Gao via ltp
0 siblings, 0 replies; 62+ messages in thread
From: Wei Gao via ltp @ 2025-03-05 4:29 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
On Thu, Feb 27, 2025 at 05:04:50PM +0100, Petr Vorel wrote:
> Hi Wei,
>
> > Signed-off-by: Wei Gao <wegao@suse.com>
> > ---
> > .../cpuset_memory_testset.sh | 37 +------------------
> > 1 file changed, 2 insertions(+), 35 deletions(-)
>
> You're supposed to remove cpuset_memory_testset.sh entry from
> runtest/controllers.
This patch is hack for remove error which happen on our openqa micro test
product.
If we need remove full cpuset_memory_testset.sh, i suppose we need convert all
sub cases within cpuset_memory_testset.sh to c case.
>
> Kind regards,
> Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* [LTP] [PATCH v6 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2024-12-09 6:01 ` [LTP] [PATCH v5 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2024-12-09 6:01 ` [LTP] [PATCH v5 1/2] " Wei Gao via ltp
2024-12-09 6:01 ` [LTP] [PATCH v5 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
@ 2025-03-05 5:08 ` Wei Gao via ltp
2025-03-05 5:08 ` [LTP] [PATCH v6 1/2] " Wei Gao via ltp
` (2 more replies)
2 siblings, 3 replies; 62+ messages in thread
From: Wei Gao via ltp @ 2025-03-05 5:08 UTC (permalink / raw)
To: ltp
Wei Gao (2):
cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
cpuset_memory_testset.sh: Remove test6
lib/tst_cgroup.c | 1 +
runtest/mm | 1 +
.../cpuset_memory_testset.sh | 37 +----
testcases/kernel/mem/.gitignore | 1 +
testcases/kernel/mem/cpuset/Makefile | 5 +
testcases/kernel/mem/cpuset/cpuset02.c | 139 ++++++++++++++++++
6 files changed, 149 insertions(+), 35 deletions(-)
create mode 100644 testcases/kernel/mem/cpuset/cpuset02.c
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* [LTP] [PATCH v6 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-05 5:08 ` [LTP] [PATCH v6 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
@ 2025-03-05 5:08 ` Wei Gao via ltp
2025-03-06 18:35 ` Petr Vorel
2025-03-10 16:51 ` Cyril Hrubis
2025-03-05 5:08 ` [LTP] [PATCH v6 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
2025-03-24 12:00 ` [LTP] [PATCH v7 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2 siblings, 2 replies; 62+ messages in thread
From: Wei Gao via ltp @ 2025-03-05 5:08 UTC (permalink / raw)
To: ltp
Signed-off-by: Wei Gao <wegao@suse.com>
---
lib/tst_cgroup.c | 1 +
runtest/mm | 1 +
testcases/kernel/mem/.gitignore | 1 +
testcases/kernel/mem/cpuset/Makefile | 5 +
testcases/kernel/mem/cpuset/cpuset02.c | 139 +++++++++++++++++++++++++
5 files changed, 147 insertions(+)
create mode 100644 testcases/kernel/mem/cpuset/cpuset02.c
diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
index 73b696c58..545c779e7 100644
--- a/lib/tst_cgroup.c
+++ b/lib/tst_cgroup.c
@@ -204,6 +204,7 @@ static const struct cgroup_file cpuset_ctrl_files[] = {
{ "cpuset.cpus", "cpuset.cpus", CTRL_CPUSET },
{ "cpuset.mems", "cpuset.mems", CTRL_CPUSET },
{ "cpuset.memory_migrate", "cpuset.memory_migrate", CTRL_CPUSET },
+ { "cpuset.sched_load_balance", "cpuset.sched_load_balance", CTRL_CPUSET },
{ }
};
diff --git a/runtest/mm b/runtest/mm
index d8e62af81..5af29b0ea 100644
--- a/runtest/mm
+++ b/runtest/mm
@@ -75,6 +75,7 @@ ksm06_2 ksm06 -n 8000
ksm07 ksm07
cpuset01 cpuset01
+cpuset02 cpuset02
oom01 oom01
oom02 oom02
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index 699e022fb..e24e96001 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -1,4 +1,5 @@
/cpuset/cpuset01
+/cpuset/cpuset02
/hugetlb/hugefallocate/hugefallocate01
/hugetlb/hugefallocate/hugefallocate02
/hugetlb/hugefork/hugefork01
diff --git a/testcases/kernel/mem/cpuset/Makefile b/testcases/kernel/mem/cpuset/Makefile
index bac13e02b..7010c7be4 100644
--- a/testcases/kernel/mem/cpuset/Makefile
+++ b/testcases/kernel/mem/cpuset/Makefile
@@ -19,6 +19,11 @@
top_srcdir ?= ../../../..
+LTPLIBS = numa
+
include $(top_srcdir)/include/mk/testcases.mk
include $(top_srcdir)/testcases/kernel/include/lib.mk
+
+cpuset02: LTPLDLIBS = -lltpnuma
+
include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/mem/cpuset/cpuset02.c b/testcases/kernel/mem/cpuset/cpuset02.c
new file mode 100644
index 000000000..f43d8e98a
--- /dev/null
+++ b/testcases/kernel/mem/cpuset/cpuset02.c
@@ -0,0 +1,139 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (c) 2009 FUJITSU LIMITED Miao Xie <miaox@cn.fujitsu.com>
+ * Copyright (c) 2023 SUSE LLC <wegao@suse.com>
+ */
+
+/*\
+ * Test checks cpuset.mems works with hugepage file.
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include "tst_test.h"
+
+#ifdef HAVE_NUMA_V2
+#include <numa.h>
+#include <numaif.h>
+#include <errno.h>
+#include "tst_numa.h"
+#include "tst_safe_stdio.h"
+#include "numa_helper.h"
+
+#define MNTPOINT "hugetlbfs/"
+#define HUGE_PAGE_FILE MNTPOINT "hugepagefile"
+#define PAGES_ALLOCATED 16u
+
+static long hpage_size;
+static struct tst_nodemap *node;
+static struct tst_cg_group *cg_cpuset_0;
+
+static void touch_memory_and_check_node(char *p, int size)
+{
+ int i;
+ int node = -1;
+ long ret;
+ int pagesize = sysconf(_SC_PAGESIZE);
+
+ for (i = 0; i < size; i += pagesize)
+ p[i] = 0xef;
+
+ ret = get_mempolicy(&node, NULL, 0, p, MPOL_F_NODE | MPOL_F_ADDR);
+ if (ret < 0)
+ tst_brk(TBROK | TERRNO, "get_mempolicy() failed");
+
+ if (node == 0)
+ tst_res(TPASS, "check node pass");
+ else
+ tst_res(TFAIL, "check node failed");
+}
+
+static void child(void)
+{
+ char *p;
+ int fd_hugepage;
+
+ TST_CHECKPOINT_WAIT(0);
+
+ fd_hugepage = SAFE_OPEN(HUGE_PAGE_FILE, O_CREAT | O_RDWR, 0755);
+ p = SAFE_MMAP(NULL, hpage_size, PROT_WRITE | PROT_READ,
+ MAP_SHARED, fd_hugepage, 0);
+
+ touch_memory_and_check_node(p, hpage_size);
+
+ SAFE_MUNMAP(p, hpage_size);
+ SAFE_CLOSE(fd_hugepage);
+
+ TST_CHECKPOINT_WAKE(1);
+}
+
+static void run_test(void)
+{
+ int pid;
+
+ cg_cpuset_0 = tst_cg_group_mk(tst_cg, "0");
+
+ SAFE_CG_PRINT(cg_cpuset_0, "cpuset.cpus", "0");
+ SAFE_CG_PRINT(cg_cpuset_0, "cpuset.mems", "0");
+ SAFE_CG_PRINT(cg_cpuset_0, "cpuset.sched_load_balance", "0");
+
+ SAFE_FILE_PRINTF("/proc/sys/vm/nr_hugepages", "%d", 2 * node->cnt);
+
+ pid = SAFE_FORK();
+
+ if (!pid) {
+ child();
+ return;
+ }
+
+ SAFE_CG_PRINTF(cg_cpuset_0, "cgroup.procs", "%d", pid);
+
+ TST_CHECKPOINT_WAKE(0);
+ TST_CHECKPOINT_WAIT(1);
+
+ SAFE_WAITPID(pid, NULL, 0);
+
+ cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
+}
+
+static void setup(void)
+{
+ node = tst_get_nodemap(TST_NUMA_MEM, PAGES_ALLOCATED * getpagesize() / 1024);
+ if (node->cnt <= 1)
+ tst_brk(TCONF, "test requires NUMA system");
+
+ hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;
+}
+
+static void cleanup(void)
+{
+ if (cg_cpuset_0)
+ cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
+}
+
+static struct tst_test test = {
+ .needs_root = 1,
+ .runs_script = 1,
+ .mntpoint = MNTPOINT,
+ .needs_hugetlbfs = 1,
+ .setup = setup,
+ .forks_child = 1,
+ .cleanup = cleanup,
+ .test_all = run_test,
+ .hugepages = {3, TST_NEEDS},
+ .needs_checkpoints = 1,
+ .needs_cgroup_ver = TST_CG_V1,
+ .needs_cgroup_ctrls = (const char *const []){ "cpuset", NULL },
+ .save_restore = (const struct tst_path_val[]) {
+ {"/proc/sys/vm/nr_hugepages", NULL, TST_SR_TBROK},
+ {}
+ },
+};
+
+#else
+TST_TEST_TCONF(NUMA_ERROR_MSG);
+#endif
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 62+ messages in thread
* [LTP] [PATCH v6 2/2] cpuset_memory_testset.sh: Remove test6
2025-03-05 5:08 ` [LTP] [PATCH v6 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2025-03-05 5:08 ` [LTP] [PATCH v6 1/2] " Wei Gao via ltp
@ 2025-03-05 5:08 ` Wei Gao via ltp
2025-03-06 18:32 ` Petr Vorel
2025-03-24 12:00 ` [LTP] [PATCH v7 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2 siblings, 1 reply; 62+ messages in thread
From: Wei Gao via ltp @ 2025-03-05 5:08 UTC (permalink / raw)
To: ltp
Signed-off-by: Wei Gao <wegao@suse.com>
---
.../cpuset_memory_testset.sh | 37 +------------------
1 file changed, 2 insertions(+), 35 deletions(-)
diff --git a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
index c1e7cea8f..fd41dc97a 100755
--- a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
+++ b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
@@ -162,41 +162,8 @@ check_hugetlbfs()
test6()
{
- cpuset_set "$CPUSET/0" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
- if [ $? -ne 0 ]; then
- cpuset_log_error $CPUSET_TMP/stderr
- tst_resm TFAIL "set general group parameter failed."
- return 1
- fi
-
- check_hugetlbfs
- if [ $? -eq 0 ]; then
- tst_resm TCONF "This system don't support hugetlbfs"
- return 0
- fi
-
- mkdir /hugetlb
- mount -t hugetlbfs none /hugetlb
-
- save_nr_hugepages=$(cat /proc/sys/vm/nr_hugepages)
- echo $((2*$nr_mems)) > /proc/sys/vm/nr_hugepages
-
- cpuset_memory_test --mmap-file --hugepage -s $HUGEPAGESIZE >"$MEMORY_RESULT" &
- simple_getresult $! "$CPUSET/0"
-
- umount /hugetlb
- rmdir /hugetlb
-
- echo $save_nr_hugepages > /proc/sys/vm/nr_hugepages
- if [ $(cat /proc/sys/vm/nr_hugepages) -ne $save_nr_hugepages ]; then
- tst_resm TFAIL "can't restore nr_hugepages(nr_hugepages = $save_nr_hugepages)."
- return 1
- fi
-
- if [ "$node" != "0" ]; then
- tst_resm TFAIL "allocate memory on the Node#$node(Expect: Node#0)."
- return 1
- fi
+ tst_resm TINFO "This test is replaced by testcases/kernel/mem/cpuset/cpuset02.c"
+ return 0
}
test7()
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v6 2/2] cpuset_memory_testset.sh: Remove test6
2025-03-05 5:08 ` [LTP] [PATCH v6 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
@ 2025-03-06 18:32 ` Petr Vorel
0 siblings, 0 replies; 62+ messages in thread
From: Petr Vorel @ 2025-03-06 18:32 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi Wei,
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v6 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-05 5:08 ` [LTP] [PATCH v6 1/2] " Wei Gao via ltp
@ 2025-03-06 18:35 ` Petr Vorel
2025-03-10 16:51 ` Cyril Hrubis
1 sibling, 0 replies; 62+ messages in thread
From: Petr Vorel @ 2025-03-06 18:35 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi Wei,
> --- /dev/null
> +++ b/testcases/kernel/mem/cpuset/cpuset02.c
> @@ -0,0 +1,139 @@
> +// SPDX-License-Identifier: LGPL-2.1-or-later
> +/*
> + * Copyright (c) 2009 FUJITSU LIMITED Miao Xie <miaox@cn.fujitsu.com>
nit: You created a completely new test, just based on test6 from shell test.
I suggest instead of adding this copyright to add:
Based on test6 from cpuset_memory_testset.sh.
I can change it before merge.
> + * Copyright (c) 2023 SUSE LLC <wegao@suse.com>
> + */
> +
> +/*\
> + * Test checks cpuset.mems works with hugepage file.
> + */
> +
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v6 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-05 5:08 ` [LTP] [PATCH v6 1/2] " Wei Gao via ltp
2025-03-06 18:35 ` Petr Vorel
@ 2025-03-10 16:51 ` Cyril Hrubis
2025-03-25 13:36 ` Petr Vorel
1 sibling, 1 reply; 62+ messages in thread
From: Cyril Hrubis @ 2025-03-10 16:51 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi!
> diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
> index 73b696c58..545c779e7 100644
> --- a/lib/tst_cgroup.c
> +++ b/lib/tst_cgroup.c
> @@ -204,6 +204,7 @@ static const struct cgroup_file cpuset_ctrl_files[] = {
> { "cpuset.cpus", "cpuset.cpus", CTRL_CPUSET },
> { "cpuset.mems", "cpuset.mems", CTRL_CPUSET },
> { "cpuset.memory_migrate", "cpuset.memory_migrate", CTRL_CPUSET },
> + { "cpuset.sched_load_balance", "cpuset.sched_load_balance", CTRL_CPUSET },
> { }
> };
>
> diff --git a/runtest/mm b/runtest/mm
> index d8e62af81..5af29b0ea 100644
> --- a/runtest/mm
> +++ b/runtest/mm
> @@ -75,6 +75,7 @@ ksm06_2 ksm06 -n 8000
> ksm07 ksm07
>
> cpuset01 cpuset01
> +cpuset02 cpuset02
>
> oom01 oom01
> oom02 oom02
> diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
> index 699e022fb..e24e96001 100644
> --- a/testcases/kernel/mem/.gitignore
> +++ b/testcases/kernel/mem/.gitignore
> @@ -1,4 +1,5 @@
> /cpuset/cpuset01
> +/cpuset/cpuset02
> /hugetlb/hugefallocate/hugefallocate01
> /hugetlb/hugefallocate/hugefallocate02
> /hugetlb/hugefork/hugefork01
> diff --git a/testcases/kernel/mem/cpuset/Makefile b/testcases/kernel/mem/cpuset/Makefile
> index bac13e02b..7010c7be4 100644
> --- a/testcases/kernel/mem/cpuset/Makefile
> +++ b/testcases/kernel/mem/cpuset/Makefile
> @@ -19,6 +19,11 @@
>
> top_srcdir ?= ../../../..
>
> +LTPLIBS = numa
> +
> include $(top_srcdir)/include/mk/testcases.mk
> include $(top_srcdir)/testcases/kernel/include/lib.mk
> +
> +cpuset02: LTPLDLIBS = -lltpnuma
> +
> include $(top_srcdir)/include/mk/generic_leaf_target.mk
> diff --git a/testcases/kernel/mem/cpuset/cpuset02.c b/testcases/kernel/mem/cpuset/cpuset02.c
> new file mode 100644
> index 000000000..f43d8e98a
> --- /dev/null
> +++ b/testcases/kernel/mem/cpuset/cpuset02.c
> @@ -0,0 +1,139 @@
> +// SPDX-License-Identifier: LGPL-2.1-or-later
> +/*
> + * Copyright (c) 2009 FUJITSU LIMITED Miao Xie <miaox@cn.fujitsu.com>
> + * Copyright (c) 2023 SUSE LLC <wegao@suse.com>
> + */
> +
> +/*\
> + * Test checks cpuset.mems works with hugepage file.
> + */
> +
> +#define _GNU_SOURCE
> +#include <stdio.h>
> +#include <sys/mount.h>
> +#include <limits.h>
> +#include <sys/param.h>
> +#include <sys/types.h>
> +#include "tst_test.h"
> +
> +#ifdef HAVE_NUMA_V2
> +#include <numa.h>
> +#include <numaif.h>
> +#include <errno.h>
> +#include "tst_numa.h"
> +#include "tst_safe_stdio.h"
> +#include "numa_helper.h"
> +
> +#define MNTPOINT "hugetlbfs/"
> +#define HUGE_PAGE_FILE MNTPOINT "hugepagefile"
> +#define PAGES_ALLOCATED 16u
> +
> +static long hpage_size;
> +static struct tst_nodemap *node;
> +static struct tst_cg_group *cg_cpuset_0;
> +
> +static void touch_memory_and_check_node(char *p, int size)
> +{
> + int i;
> + int node = -1;
> + long ret;
> + int pagesize = sysconf(_SC_PAGESIZE);
> +
> + for (i = 0; i < size; i += pagesize)
> + p[i] = 0xef;
> +
> + ret = get_mempolicy(&node, NULL, 0, p, MPOL_F_NODE | MPOL_F_ADDR);
> + if (ret < 0)
> + tst_brk(TBROK | TERRNO, "get_mempolicy() failed");
> +
> + if (node == 0)
> + tst_res(TPASS, "check node pass");
> + else
> + tst_res(TFAIL, "check node failed");
> +}
> +
> +static void child(void)
> +{
> + char *p;
> + int fd_hugepage;
> +
> + TST_CHECKPOINT_WAIT(0);
> +
> + fd_hugepage = SAFE_OPEN(HUGE_PAGE_FILE, O_CREAT | O_RDWR, 0755);
> + p = SAFE_MMAP(NULL, hpage_size, PROT_WRITE | PROT_READ,
> + MAP_SHARED, fd_hugepage, 0);
> +
> + touch_memory_and_check_node(p, hpage_size);
> +
> + SAFE_MUNMAP(p, hpage_size);
> + SAFE_CLOSE(fd_hugepage);
> +
> + TST_CHECKPOINT_WAKE(1);
> +}
> +
> +static void run_test(void)
> +{
> + int pid;
> +
> + cg_cpuset_0 = tst_cg_group_mk(tst_cg, "0");
> +
> + SAFE_CG_PRINT(cg_cpuset_0, "cpuset.cpus", "0");
> + SAFE_CG_PRINT(cg_cpuset_0, "cpuset.mems", "0");
> + SAFE_CG_PRINT(cg_cpuset_0, "cpuset.sched_load_balance", "0");
Here you are locking the process to node0 but that does not necessarily
means that the node0 has enough memory or CPUs. You have to choose a
node from the nodemap that you got in the setup.
Also if you want to have a node with CPU, so that you can lock the
process there, you need to add TST_NUMA_CPU flag to the
tst_get_nodemap(). And yes, there are machines that can have node with
just memory or just CPU.
However in the touch_memory_and_check_node() we just check a node the
memory was allocated on. So I do not think that we need to lock the
process on a particular CPU. And I do not think that we need the se the
sched_load_balance either.
> + SAFE_FILE_PRINTF("/proc/sys/vm/nr_hugepages", "%d", 2 * node->cnt);
What is this needed for and why is there the 2*node->cnt useful for? As
far as I can tell, we allocate a single page on a given node.
> + pid = SAFE_FORK();
> +
> + if (!pid) {
> + child();
> + return;
> + }
> +
> + SAFE_CG_PRINTF(cg_cpuset_0, "cgroup.procs", "%d", pid);
We can just get rid of all the checkpoints if this is done by the child
process before it calls the child() function.
> + TST_CHECKPOINT_WAKE(0);
> + TST_CHECKPOINT_WAIT(1);
> +
> + SAFE_WAITPID(pid, NULL, 0);
We should not wait processes if we are not interested in their return
value. Such children are collected automatically by the test library.
> + cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
> +}
> +
> +static void setup(void)
> +{
> + node = tst_get_nodemap(TST_NUMA_MEM, PAGES_ALLOCATED * getpagesize() / 1024);
^
Why is this here? The
child in the test
allocates just a single
page.
> + if (node->cnt <= 1)
> + tst_brk(TCONF, "test requires NUMA system");
> +
> + hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;
> +}
> +
> +static void cleanup(void)
> +{
> + if (cg_cpuset_0)
> + cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
> +}
> +
> +static struct tst_test test = {
> + .needs_root = 1,
> + .runs_script = 1,
> + .mntpoint = MNTPOINT,
> + .needs_hugetlbfs = 1,
> + .setup = setup,
> + .forks_child = 1,
> + .cleanup = cleanup,
> + .test_all = run_test,
> + .hugepages = {3, TST_NEEDS},
> + .needs_checkpoints = 1,
> + .needs_cgroup_ver = TST_CG_V1,
> + .needs_cgroup_ctrls = (const char *const []){ "cpuset", NULL },
> + .save_restore = (const struct tst_path_val[]) {
> + {"/proc/sys/vm/nr_hugepages", NULL, TST_SR_TBROK},
> + {}
> + },
> +};
> +
> +#else
> +TST_TEST_TCONF(NUMA_ERROR_MSG);
> +#endif
> --
> 2.35.3
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* [LTP] [PATCH v7 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-05 5:08 ` [LTP] [PATCH v6 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2025-03-05 5:08 ` [LTP] [PATCH v6 1/2] " Wei Gao via ltp
2025-03-05 5:08 ` [LTP] [PATCH v6 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
@ 2025-03-24 12:00 ` Wei Gao via ltp
2025-03-24 12:00 ` [LTP] [PATCH v7 1/2] " Wei Gao via ltp
` (2 more replies)
2 siblings, 3 replies; 62+ messages in thread
From: Wei Gao via ltp @ 2025-03-24 12:00 UTC (permalink / raw)
To: ltp
Wei Gao (2):
cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
cpuset_memory_testset.sh: Remove test6
lib/tst_cgroup.c | 1 +
runtest/mm | 1 +
.../cpuset_memory_testset.sh | 37 +----
testcases/kernel/mem/.gitignore | 1 +
testcases/kernel/mem/cpuset/Makefile | 5 +
testcases/kernel/mem/cpuset/cpuset02.c | 132 ++++++++++++++++++
6 files changed, 142 insertions(+), 35 deletions(-)
create mode 100644 testcases/kernel/mem/cpuset/cpuset02.c
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* [LTP] [PATCH v7 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-24 12:00 ` [LTP] [PATCH v7 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
@ 2025-03-24 12:00 ` Wei Gao via ltp
2025-03-25 14:00 ` Petr Vorel
2025-03-24 12:00 ` [LTP] [PATCH v7 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
2025-03-28 7:59 ` [LTP] [PATCH v8 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2 siblings, 1 reply; 62+ messages in thread
From: Wei Gao via ltp @ 2025-03-24 12:00 UTC (permalink / raw)
To: ltp
Signed-off-by: Wei Gao <wegao@suse.com>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
---
lib/tst_cgroup.c | 1 +
runtest/mm | 1 +
testcases/kernel/mem/.gitignore | 1 +
testcases/kernel/mem/cpuset/Makefile | 5 +
testcases/kernel/mem/cpuset/cpuset02.c | 132 +++++++++++++++++++++++++
5 files changed, 140 insertions(+)
create mode 100644 testcases/kernel/mem/cpuset/cpuset02.c
diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
index 73b696c58..545c779e7 100644
--- a/lib/tst_cgroup.c
+++ b/lib/tst_cgroup.c
@@ -204,6 +204,7 @@ static const struct cgroup_file cpuset_ctrl_files[] = {
{ "cpuset.cpus", "cpuset.cpus", CTRL_CPUSET },
{ "cpuset.mems", "cpuset.mems", CTRL_CPUSET },
{ "cpuset.memory_migrate", "cpuset.memory_migrate", CTRL_CPUSET },
+ { "cpuset.sched_load_balance", "cpuset.sched_load_balance", CTRL_CPUSET },
{ }
};
diff --git a/runtest/mm b/runtest/mm
index d8e62af81..5af29b0ea 100644
--- a/runtest/mm
+++ b/runtest/mm
@@ -75,6 +75,7 @@ ksm06_2 ksm06 -n 8000
ksm07 ksm07
cpuset01 cpuset01
+cpuset02 cpuset02
oom01 oom01
oom02 oom02
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index 699e022fb..e24e96001 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -1,4 +1,5 @@
/cpuset/cpuset01
+/cpuset/cpuset02
/hugetlb/hugefallocate/hugefallocate01
/hugetlb/hugefallocate/hugefallocate02
/hugetlb/hugefork/hugefork01
diff --git a/testcases/kernel/mem/cpuset/Makefile b/testcases/kernel/mem/cpuset/Makefile
index bac13e02b..7010c7be4 100644
--- a/testcases/kernel/mem/cpuset/Makefile
+++ b/testcases/kernel/mem/cpuset/Makefile
@@ -19,6 +19,11 @@
top_srcdir ?= ../../../..
+LTPLIBS = numa
+
include $(top_srcdir)/include/mk/testcases.mk
include $(top_srcdir)/testcases/kernel/include/lib.mk
+
+cpuset02: LTPLDLIBS = -lltpnuma
+
include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/mem/cpuset/cpuset02.c b/testcases/kernel/mem/cpuset/cpuset02.c
new file mode 100644
index 000000000..0d8ef055a
--- /dev/null
+++ b/testcases/kernel/mem/cpuset/cpuset02.c
@@ -0,0 +1,132 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (c) 2025 SUSE LLC <wegao@suse.com>
+ */
+
+/*\
+ * Test checks cpuset.mems works with hugepage file.
+ * Based on test6 from cpuset_memory_testset.sh.
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include "tst_test.h"
+
+#ifdef HAVE_NUMA_V2
+#include <numa.h>
+#include <numaif.h>
+#include <errno.h>
+#include "tst_numa.h"
+#include "tst_safe_stdio.h"
+#include "numa_helper.h"
+
+#define MNTPOINT "hugetlbfs/"
+#define HUGE_PAGE_FILE MNTPOINT "hugepagefile"
+
+static long hpage_size;
+static struct tst_nodemap *node;
+static int check_node_id;
+static struct tst_cg_group *cg_cpuset_0;
+
+static void touch_memory_and_check_node(char *p, int size)
+{
+ int i;
+ int node = -1;
+ long ret;
+ int pagesize = sysconf(_SC_PAGESIZE);
+
+ for (i = 0; i < size; i += pagesize)
+ p[i] = 0xef;
+
+ ret = get_mempolicy(&node, NULL, 0, p, MPOL_F_NODE | MPOL_F_ADDR);
+ if (ret < 0)
+ tst_brk(TBROK | TERRNO, "get_mempolicy() failed");
+
+ if (node == check_node_id)
+ tst_res(TPASS, "check node pass");
+ else
+ tst_res(TFAIL, "check node failed");
+}
+
+static void child(void)
+{
+ char *p;
+ int fd_hugepage;
+
+ fd_hugepage = SAFE_OPEN(HUGE_PAGE_FILE, O_CREAT | O_RDWR, 0755);
+ p = SAFE_MMAP(NULL, hpage_size, PROT_WRITE | PROT_READ,
+ MAP_SHARED, fd_hugepage, 0);
+
+ touch_memory_and_check_node(p, hpage_size);
+
+ SAFE_MUNMAP(p, hpage_size);
+ SAFE_CLOSE(fd_hugepage);
+}
+
+static void run_test(void)
+{
+ int pid;
+ char node_id_str[256];
+
+ cg_cpuset_0 = tst_cg_group_mk(tst_cg, "0");
+
+ sprintf(node_id_str, "%u", check_node_id);
+ SAFE_CG_PRINT(cg_cpuset_0, "cpuset.mems", node_id_str);
+ SAFE_FILE_PRINTF("/proc/sys/vm/nr_hugepages", "%d", 1);
+
+ pid = SAFE_FORK();
+
+ if (!pid) {
+ SAFE_CG_PRINTF(cg_cpuset_0, "cgroup.procs", "%d", pid);
+ child();
+ return;
+ }
+
+ SAFE_WAITPID(pid, NULL, 0);
+
+ cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
+}
+
+static void setup(void)
+{
+ node = tst_get_nodemap(TST_NUMA_MEM, getpagesize() / 1024);
+ if (node->cnt <= 1)
+ tst_brk(TCONF, "test requires NUMA system");
+
+ check_node_id = node->map[0];
+
+ hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;
+}
+
+static void cleanup(void)
+{
+ if (cg_cpuset_0)
+ cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
+}
+
+static struct tst_test test = {
+ .needs_root = 1,
+ .runs_script = 1,
+ .mntpoint = MNTPOINT,
+ .needs_hugetlbfs = 1,
+ .setup = setup,
+ .forks_child = 1,
+ .cleanup = cleanup,
+ .test_all = run_test,
+ .hugepages = {3, TST_NEEDS},
+ .needs_checkpoints = 1,
+ .needs_cgroup_ver = TST_CG_V1,
+ .needs_cgroup_ctrls = (const char *const []){ "cpuset", NULL },
+ .save_restore = (const struct tst_path_val[]) {
+ {"/proc/sys/vm/nr_hugepages", NULL, TST_SR_TBROK},
+ {}
+ },
+};
+
+#else
+TST_TEST_TCONF(NUMA_ERROR_MSG);
+#endif
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 62+ messages in thread
* [LTP] [PATCH v7 2/2] cpuset_memory_testset.sh: Remove test6
2025-03-24 12:00 ` [LTP] [PATCH v7 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2025-03-24 12:00 ` [LTP] [PATCH v7 1/2] " Wei Gao via ltp
@ 2025-03-24 12:00 ` Wei Gao via ltp
2025-03-24 15:32 ` Petr Vorel
2025-03-28 7:59 ` [LTP] [PATCH v8 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2 siblings, 1 reply; 62+ messages in thread
From: Wei Gao via ltp @ 2025-03-24 12:00 UTC (permalink / raw)
To: ltp
Signed-off-by: Wei Gao <wegao@suse.com>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
---
.../cpuset_memory_testset.sh | 37 +------------------
1 file changed, 2 insertions(+), 35 deletions(-)
diff --git a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
index c1e7cea8f..fd41dc97a 100755
--- a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
+++ b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
@@ -162,41 +162,8 @@ check_hugetlbfs()
test6()
{
- cpuset_set "$CPUSET/0" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
- if [ $? -ne 0 ]; then
- cpuset_log_error $CPUSET_TMP/stderr
- tst_resm TFAIL "set general group parameter failed."
- return 1
- fi
-
- check_hugetlbfs
- if [ $? -eq 0 ]; then
- tst_resm TCONF "This system don't support hugetlbfs"
- return 0
- fi
-
- mkdir /hugetlb
- mount -t hugetlbfs none /hugetlb
-
- save_nr_hugepages=$(cat /proc/sys/vm/nr_hugepages)
- echo $((2*$nr_mems)) > /proc/sys/vm/nr_hugepages
-
- cpuset_memory_test --mmap-file --hugepage -s $HUGEPAGESIZE >"$MEMORY_RESULT" &
- simple_getresult $! "$CPUSET/0"
-
- umount /hugetlb
- rmdir /hugetlb
-
- echo $save_nr_hugepages > /proc/sys/vm/nr_hugepages
- if [ $(cat /proc/sys/vm/nr_hugepages) -ne $save_nr_hugepages ]; then
- tst_resm TFAIL "can't restore nr_hugepages(nr_hugepages = $save_nr_hugepages)."
- return 1
- fi
-
- if [ "$node" != "0" ]; then
- tst_resm TFAIL "allocate memory on the Node#$node(Expect: Node#0)."
- return 1
- fi
+ tst_resm TINFO "This test is replaced by testcases/kernel/mem/cpuset/cpuset02.c"
+ return 0
}
test7()
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v7 2/2] cpuset_memory_testset.sh: Remove test6
2025-03-24 12:00 ` [LTP] [PATCH v7 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
@ 2025-03-24 15:32 ` Petr Vorel
2025-03-25 3:32 ` Wei Gao via ltp
0 siblings, 1 reply; 62+ messages in thread
From: Petr Vorel @ 2025-03-24 15:32 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi Wei,
it's helpful in the commit message to write *the reason* why doing change.
There should be a note that C test in the previous commit implemented the test.
Also generally it helps a review process if you add a changelog what changed in
the previous version.
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v7 2/2] cpuset_memory_testset.sh: Remove test6
2025-03-24 15:32 ` Petr Vorel
@ 2025-03-25 3:32 ` Wei Gao via ltp
2025-03-25 3:54 ` Wei Gao via ltp
0 siblings, 1 reply; 62+ messages in thread
From: Wei Gao via ltp @ 2025-03-25 3:32 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
On Mon, Mar 24, 2025 at 04:32:52PM +0100, Petr Vorel wrote:
> Hi Wei,
>
> it's helpful in the commit message to write *the reason* why doing change.
> There should be a note that C test in the previous commit implemented the test.
>
Got it, the previous commit change mainly base Cyril v6's feedback.
> Also generally it helps a review process if you add a changelog what changed in
> the previous version.
Thanks for point this out.
v6: https://patchwork.ozlabs.org/project/ltp/patch/20250305050805.7905-2-wegao@suse.com/
Changes v6-v7:
* choose a node from the nodemap which get from setup instead of using hardcode node0
* remove unnecessary steps such as locking process into specific node and sched_load_balance
* update allocate memory size to single page
* remove unnecessary checkpoints
>
> Kind regards,
> Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v7 2/2] cpuset_memory_testset.sh: Remove test6
2025-03-25 3:32 ` Wei Gao via ltp
@ 2025-03-25 3:54 ` Wei Gao via ltp
0 siblings, 0 replies; 62+ messages in thread
From: Wei Gao via ltp @ 2025-03-25 3:54 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
Hi Petr
Got it, currently the reason for previous commit change is v6's comments
from Cyril.
v6:
https://patchwork.ozlabs.org/project/ltp/patch/20250305050805.7905-2-wegao@suse.com/
Changes v6-v7:
* select node from nodemap which got in setup()
* remove unnecessary step such as locking process to node0 and
schedu_load_balance setting
* change allocate memory to single page
* remove checkpoint
Thanks.
Regards
Gao Wei
On Tue, Mar 25, 2025 at 11:32 AM Wei Gao <wegao@suse.com> wrote:
> On Mon, Mar 24, 2025 at 04:32:52PM +0100, Petr Vorel wrote:
> > Hi Wei,
> >
> > it's helpful in the commit message to write *the reason* why doing
> change.
> > There should be a note that C test in the previous commit implemented
> the test.
> >
> Got it, the previous commit change mainly base Cyril v6's feedback.
> > Also generally it helps a review process if you add a changelog what
> changed in
> > the previous version.
> Thanks for point this out.
>
> v6:
> https://patchwork.ozlabs.org/project/ltp/patch/20250305050805.7905-2-wegao@suse.com/
> Changes v6-v7:
> * choose a node from the nodemap which get from setup instead of using
> hardcode node0
> * remove unnecessary steps such as locking process into specific node and
> sched_load_balance
> * update allocate memory size to single page
> * remove unnecessary checkpoints
>
>
> >
> > Kind regards,
> > Petr
>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v6 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-10 16:51 ` Cyril Hrubis
@ 2025-03-25 13:36 ` Petr Vorel
0 siblings, 0 replies; 62+ messages in thread
From: Petr Vorel @ 2025-03-25 13:36 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
> Hi!
> > diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
> > index 73b696c58..545c779e7 100644
> > --- a/lib/tst_cgroup.c
> > +++ b/lib/tst_cgroup.c
> > @@ -204,6 +204,7 @@ static const struct cgroup_file cpuset_ctrl_files[] = {
> > { "cpuset.cpus", "cpuset.cpus", CTRL_CPUSET },
> > { "cpuset.mems", "cpuset.mems", CTRL_CPUSET },
> > { "cpuset.memory_migrate", "cpuset.memory_migrate", CTRL_CPUSET },
> > + { "cpuset.sched_load_balance", "cpuset.sched_load_balance", CTRL_CPUSET },
> > { }
> > };
> > diff --git a/runtest/mm b/runtest/mm
> > index d8e62af81..5af29b0ea 100644
> > --- a/runtest/mm
> > +++ b/runtest/mm
> > @@ -75,6 +75,7 @@ ksm06_2 ksm06 -n 8000
> > ksm07 ksm07
> > cpuset01 cpuset01
> > +cpuset02 cpuset02
> > oom01 oom01
> > oom02 oom02
> > diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
> > index 699e022fb..e24e96001 100644
> > --- a/testcases/kernel/mem/.gitignore
> > +++ b/testcases/kernel/mem/.gitignore
> > @@ -1,4 +1,5 @@
> > /cpuset/cpuset01
> > +/cpuset/cpuset02
> > /hugetlb/hugefallocate/hugefallocate01
> > /hugetlb/hugefallocate/hugefallocate02
> > /hugetlb/hugefork/hugefork01
> > diff --git a/testcases/kernel/mem/cpuset/Makefile b/testcases/kernel/mem/cpuset/Makefile
> > index bac13e02b..7010c7be4 100644
> > --- a/testcases/kernel/mem/cpuset/Makefile
> > +++ b/testcases/kernel/mem/cpuset/Makefile
> > @@ -19,6 +19,11 @@
> > top_srcdir ?= ../../../..
> > +LTPLIBS = numa
> > +
> > include $(top_srcdir)/include/mk/testcases.mk
> > include $(top_srcdir)/testcases/kernel/include/lib.mk
> > +
> > +cpuset02: LTPLDLIBS = -lltpnuma
> > +
> > include $(top_srcdir)/include/mk/generic_leaf_target.mk
> > diff --git a/testcases/kernel/mem/cpuset/cpuset02.c b/testcases/kernel/mem/cpuset/cpuset02.c
> > new file mode 100644
> > index 000000000..f43d8e98a
> > --- /dev/null
> > +++ b/testcases/kernel/mem/cpuset/cpuset02.c
> > @@ -0,0 +1,139 @@
> > +// SPDX-License-Identifier: LGPL-2.1-or-later
> > +/*
> > + * Copyright (c) 2009 FUJITSU LIMITED Miao Xie <miaox@cn.fujitsu.com>
> > + * Copyright (c) 2023 SUSE LLC <wegao@suse.com>
> > + */
> > +
> > +/*\
> > + * Test checks cpuset.mems works with hugepage file.
> > + */
> > +
> > +#define _GNU_SOURCE
> > +#include <stdio.h>
> > +#include <sys/mount.h>
> > +#include <limits.h>
> > +#include <sys/param.h>
> > +#include <sys/types.h>
> > +#include "tst_test.h"
> > +
> > +#ifdef HAVE_NUMA_V2
> > +#include <numa.h>
> > +#include <numaif.h>
> > +#include <errno.h>
> > +#include "tst_numa.h"
> > +#include "tst_safe_stdio.h"
> > +#include "numa_helper.h"
> > +
> > +#define MNTPOINT "hugetlbfs/"
> > +#define HUGE_PAGE_FILE MNTPOINT "hugepagefile"
> > +#define PAGES_ALLOCATED 16u
> > +
> > +static long hpage_size;
> > +static struct tst_nodemap *node;
> > +static struct tst_cg_group *cg_cpuset_0;
> > +
> > +static void touch_memory_and_check_node(char *p, int size)
> > +{
> > + int i;
> > + int node = -1;
> > + long ret;
> > + int pagesize = sysconf(_SC_PAGESIZE);
> > +
> > + for (i = 0; i < size; i += pagesize)
> > + p[i] = 0xef;
> > +
> > + ret = get_mempolicy(&node, NULL, 0, p, MPOL_F_NODE | MPOL_F_ADDR);
> > + if (ret < 0)
> > + tst_brk(TBROK | TERRNO, "get_mempolicy() failed");
> > +
> > + if (node == 0)
> > + tst_res(TPASS, "check node pass");
> > + else
> > + tst_res(TFAIL, "check node failed");
> > +}
> > +
> > +static void child(void)
> > +{
> > + char *p;
> > + int fd_hugepage;
> > +
> > + TST_CHECKPOINT_WAIT(0);
> > +
> > + fd_hugepage = SAFE_OPEN(HUGE_PAGE_FILE, O_CREAT | O_RDWR, 0755);
> > + p = SAFE_MMAP(NULL, hpage_size, PROT_WRITE | PROT_READ,
> > + MAP_SHARED, fd_hugepage, 0);
> > +
> > + touch_memory_and_check_node(p, hpage_size);
> > +
> > + SAFE_MUNMAP(p, hpage_size);
> > + SAFE_CLOSE(fd_hugepage);
> > +
> > + TST_CHECKPOINT_WAKE(1);
> > +}
> > +
> > +static void run_test(void)
> > +{
> > + int pid;
> > +
> > + cg_cpuset_0 = tst_cg_group_mk(tst_cg, "0");
> > +
> > + SAFE_CG_PRINT(cg_cpuset_0, "cpuset.cpus", "0");
> > + SAFE_CG_PRINT(cg_cpuset_0, "cpuset.mems", "0");
> > + SAFE_CG_PRINT(cg_cpuset_0, "cpuset.sched_load_balance", "0");
> Here you are locking the process to node0 but that does not necessarily
> means that the node0 has enough memory or CPUs. You have to choose a
> node from the nodemap that you got in the setup.
> Also if you want to have a node with CPU, so that you can lock the
> process there, you need to add TST_NUMA_CPU flag to the
> tst_get_nodemap(). And yes, there are machines that can have node with
> just memory or just CPU.
> However in the touch_memory_and_check_node() we just check a node the
> memory was allocated on. So I do not think that we need to lock the
> process on a particular CPU. And I do not think that we need the se the
> sched_load_balance either.
[ commenting old version, there is v7 already ]
Thanks for catching these. For a record original shell test does not set
cpuset.cpus, only cpuset.mems.
> > + SAFE_FILE_PRINTF("/proc/sys/vm/nr_hugepages", "%d", 2 * node->cnt);
> What is this needed for and why is there the 2*node->cnt useful for? As
> far as I can tell, we allocate a single page on a given node.
For a record, shell test does:
echo $((2*$nr_mems)) > /proc/sys/vm/nr_hugepages
I don't have deep understanding of hugetlbpage and NUMA, but kernel hugetlbpage
allows more huge pages in the kernel's huge page pool:
https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt
echo 20 > /proc/sys/vm/nr_hugepages
Kind regards,
Petr
> > + pid = SAFE_FORK();
> > +
> > + if (!pid) {
> > + child();
> > + return;
> > + }
> > +
> > + SAFE_CG_PRINTF(cg_cpuset_0, "cgroup.procs", "%d", pid);
> We can just get rid of all the checkpoints if this is done by the child
> process before it calls the child() function.
> > + TST_CHECKPOINT_WAKE(0);
> > + TST_CHECKPOINT_WAIT(1);
> > +
> > + SAFE_WAITPID(pid, NULL, 0);
> We should not wait processes if we are not interested in their return
> value. Such children are collected automatically by the test library.
> > + cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
> > +}
> > +
> > +static void setup(void)
> > +{
> > + node = tst_get_nodemap(TST_NUMA_MEM, PAGES_ALLOCATED * getpagesize() / 1024);
> ^
> Why is this here? The
> child in the test
> allocates just a single
> page.
> > + if (node->cnt <= 1)
> > + tst_brk(TCONF, "test requires NUMA system");
> > +
> > + hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;
> > +}
> > +
> > +static void cleanup(void)
> > +{
> > + if (cg_cpuset_0)
> > + cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
> > +}
> > +
> > +static struct tst_test test = {
> > + .needs_root = 1,
> > + .runs_script = 1,
> > + .mntpoint = MNTPOINT,
> > + .needs_hugetlbfs = 1,
> > + .setup = setup,
> > + .forks_child = 1,
> > + .cleanup = cleanup,
> > + .test_all = run_test,
> > + .hugepages = {3, TST_NEEDS},
> > + .needs_checkpoints = 1,
> > + .needs_cgroup_ver = TST_CG_V1,
> > + .needs_cgroup_ctrls = (const char *const []){ "cpuset", NULL },
> > + .save_restore = (const struct tst_path_val[]) {
> > + {"/proc/sys/vm/nr_hugepages", NULL, TST_SR_TBROK},
> > + {}
> > + },
> > +};
> > +
> > +#else
> > +TST_TEST_TCONF(NUMA_ERROR_MSG);
> > +#endif
> > --
> > 2.35.3
> > --
> > Mailing list info: https://lists.linux.it/listinfo/ltp
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v7 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-24 12:00 ` [LTP] [PATCH v7 1/2] " Wei Gao via ltp
@ 2025-03-25 14:00 ` Petr Vorel
2025-03-26 4:14 ` Wei Gao via ltp
2025-03-26 8:38 ` Li Wang via ltp
0 siblings, 2 replies; 62+ messages in thread
From: Petr Vorel @ 2025-03-25 14:00 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi Wei,
...
> +++ b/testcases/kernel/mem/cpuset/cpuset02.c
> @@ -0,0 +1,132 @@
> +// SPDX-License-Identifier: LGPL-2.1-or-later
> +/*
> + * Copyright (c) 2025 SUSE LLC <wegao@suse.com>
> + */
> +
> +/*\
> + * Test checks cpuset.mems works with hugepage file.
> + * Based on test6 from cpuset_memory_testset.sh.
very nit: I would add the author name:
* Based on test6 from cpuset_memory_testset.sh written by Miao Xie.
(We don't need to keep the copyright, but because we likely sooner or later
delete cpuset_memory_testset.sh it's nice to give the original author his credit
for his original idea.)
> + */
> +
> +#define _GNU_SOURCE
> +#include <stdio.h>
> +#include <sys/mount.h>
> +#include <limits.h>
> +#include <sys/param.h>
> +#include <sys/types.h>
> +#include "tst_test.h"
> +
> +#ifdef HAVE_NUMA_V2
> +#include <numa.h>
<numa.h> is not needed, please delete it.
> +#include <numaif.h>
> +#include <errno.h>
<errno.h> is not needed either, please delete it.
> +#include "tst_numa.h"
> +#include "tst_safe_stdio.h"
tst_safe_stdio.h is not needed either, please delete it.
> +#include "numa_helper.h"
numa_helper.h is not needed either, please delete it.
...
> +static void run_test(void)
> +{
> + int pid;
> + char node_id_str[256];
> +
> + cg_cpuset_0 = tst_cg_group_mk(tst_cg, "0");
> +
> + sprintf(node_id_str, "%u", check_node_id);
> + SAFE_CG_PRINT(cg_cpuset_0, "cpuset.mems", node_id_str);
> + SAFE_FILE_PRINTF("/proc/sys/vm/nr_hugepages", "%d", 1);
You changed the /proc/sys/vm/nr_hugepages to 1, because Cyril objected the code
in v6:
SAFE_FILE_PRINTF("/proc/sys/vm/nr_hugepages", "%d", 2 * node->cnt);
But as I note there [1], the original shell test did it this way and kernel docs
allows more than 1 to allocate. I'm obviously missing something.
[1] https://lore.kernel.org/ltp/20250325133611.GB372417@pevik/
> +
> + pid = SAFE_FORK();
> +
> + if (!pid) {
> + SAFE_CG_PRINTF(cg_cpuset_0, "cgroup.procs", "%d", pid);
> + child();
> + return;
> + }
> +
> + SAFE_WAITPID(pid, NULL, 0);
> +
> + cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
> +}
> +
> +static void setup(void)
> +{
> + node = tst_get_nodemap(TST_NUMA_MEM, getpagesize() / 1024);
> + if (node->cnt <= 1)
> + tst_brk(TCONF, "test requires NUMA system");
This fails on system with single NUMA memory node. Either it should be compared as:
if (node->cnt < 1)
or you're checking for 2 NUMA memory nodes (IMHO you want just single ATM.
Also maybe worth to change to "test requires at least one NUMA memory node" as
other tests do, you do have check for NUMA itsef anyway in
TST_TEST_TCONF(NUMA_ERROR_MSG).
> +
> + check_node_id = node->map[0];
> +
> + hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;
> +}
> +
> +static void cleanup(void)
> +{
> + if (cg_cpuset_0)
> + cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
> +}
> +
> +static struct tst_test test = {
> + .needs_root = 1,
> + .runs_script = 1,
> + .mntpoint = MNTPOINT,
> + .needs_hugetlbfs = 1,
> + .setup = setup,
> + .forks_child = 1,
> + .cleanup = cleanup,
> + .test_all = run_test,
> + .hugepages = {3, TST_NEEDS},
> + .needs_checkpoints = 1,
> + .needs_cgroup_ver = TST_CG_V1,
> + .needs_cgroup_ctrls = (const char *const []){ "cpuset", NULL },
> + .save_restore = (const struct tst_path_val[]) {
> + {"/proc/sys/vm/nr_hugepages", NULL, TST_SR_TBROK},
Shouldn't here be rather TST_SR_TCONF?
Thanks for the changelog, the rest of the changes LGTM.
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v7 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-25 14:00 ` Petr Vorel
@ 2025-03-26 4:14 ` Wei Gao via ltp
2025-03-26 7:38 ` Li Wang via ltp
2025-03-26 8:38 ` Li Wang via ltp
1 sibling, 1 reply; 62+ messages in thread
From: Wei Gao via ltp @ 2025-03-26 4:14 UTC (permalink / raw)
To: Petr Vorel, chrubis; +Cc: ltp
On Tue, Mar 25, 2025 at 03:00:18PM +0100, Petr Vorel wrote:
> Hi Wei,
>
> ...
> > +static void run_test(void)
> > +{
> > + int pid;
> > + char node_id_str[256];
> > +
> > + cg_cpuset_0 = tst_cg_group_mk(tst_cg, "0");
> > +
> > + sprintf(node_id_str, "%u", check_node_id);
> > + SAFE_CG_PRINT(cg_cpuset_0, "cpuset.mems", node_id_str);
> > + SAFE_FILE_PRINTF("/proc/sys/vm/nr_hugepages", "%d", 1);
>
> You changed the /proc/sys/vm/nr_hugepages to 1, because Cyril objected the code
> in v6:
>
> SAFE_FILE_PRINTF("/proc/sys/vm/nr_hugepages", "%d", 2 * node->cnt);
>
> But as I note there [1], the original shell test did it this way and kernel docs
> allows more than 1 to allocate. I'm obviously missing something.
>
> [1] https://lore.kernel.org/ltp/20250325133611.GB372417@pevik/
>
My understanding from Cyril's comments is no need reserve more hugepages, since
this test case ONLY allocate 1 page through mmap.
@Cyril could you help confirm this?
>
> Kind regards,
> Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v7 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-26 4:14 ` Wei Gao via ltp
@ 2025-03-26 7:38 ` Li Wang via ltp
2025-03-26 8:26 ` Li Wang via ltp
2025-03-26 9:11 ` Wei Gao via ltp
0 siblings, 2 replies; 62+ messages in thread
From: Li Wang via ltp @ 2025-03-26 7:38 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
On Wed, Mar 26, 2025 at 12:15 PM Wei Gao via ltp <ltp@lists.linux.it> wrote:
> On Tue, Mar 25, 2025 at 03:00:18PM +0100, Petr Vorel wrote:
> > Hi Wei,
> >
> > ...
> > > +static void run_test(void)
> > > +{
> > > + int pid;
> > > + char node_id_str[256];
> > > +
> > > + cg_cpuset_0 = tst_cg_group_mk(tst_cg, "0");
> > > +
> > > + sprintf(node_id_str, "%u", check_node_id);
> > > + SAFE_CG_PRINT(cg_cpuset_0, "cpuset.mems", node_id_str);
> > > + SAFE_FILE_PRINTF("/proc/sys/vm/nr_hugepages", "%d", 1);
> >
> > You changed the /proc/sys/vm/nr_hugepages to 1, because Cyril objected
> the code
> > in v6:
> >
> > SAFE_FILE_PRINTF("/proc/sys/vm/nr_hugepages", "%d", 2 * node->cnt);
> >
> > But as I note there [1], the original shell test did it this way and
> kernel docs
> > allows more than 1 to allocate. I'm obviously missing something.
> >
> > [1] https://lore.kernel.org/ltp/20250325133611.GB372417@pevik/
> >
> My understanding from Cyril's comments is no need reserve more hugepages,
> since
> this test case ONLY allocate 1 page through mmap.
It depends on what you wanted there, if only 1 general huge page,
`echo 1 > /proc/sys/vm/nr_hugepages` will try to reserve 1
from a NUMA node randomly.
But if you prefer to get 1 hugepage from a specified node, we need:
`echo 1 >
/sys/devices/system/node/node%u/hugepages/hugepages-%dkB/nr_hugepages`
However, both ways won't guarantee the reservation will be 100% successful,
which is based on the memory fragmentation situations.
To be on the safe side, I would suggest using LTP unified API to reserve:
https://github.com/linux-test-project/ltp/blob/master/doc/old/C-Test-API.asciidoc#134-reserving-hugepages
You could reference usage from:
mem/hugetlb/hugemmap/hugemmap16.c,
syscalls/move_pages/move_pages12.c
>
> @Cyril could you help confirm this?
>
> >
> > Kind regards,
> > Petr
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
>
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v7 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-26 7:38 ` Li Wang via ltp
@ 2025-03-26 8:26 ` Li Wang via ltp
2025-03-26 9:11 ` Wei Gao via ltp
1 sibling, 0 replies; 62+ messages in thread
From: Li Wang via ltp @ 2025-03-26 8:26 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi Wei,
On Wed, Mar 26, 2025 at 3:38 PM Li Wang <liwang@redhat.com> wrote:
>
>
> On Wed, Mar 26, 2025 at 12:15 PM Wei Gao via ltp <ltp@lists.linux.it>
> wrote:
>
>> On Tue, Mar 25, 2025 at 03:00:18PM +0100, Petr Vorel wrote:
>> > Hi Wei,
>> >
>> > ...
>> > > +static void run_test(void)
>> > > +{
>> > > + int pid;
>> > > + char node_id_str[256];
>> > > +
>> > > + cg_cpuset_0 = tst_cg_group_mk(tst_cg, "0");
>> > > +
>> > > + sprintf(node_id_str, "%u", check_node_id);
>> > > + SAFE_CG_PRINT(cg_cpuset_0, "cpuset.mems", node_id_str);
>> > > + SAFE_FILE_PRINTF("/proc/sys/vm/nr_hugepages", "%d", 1);
>> >
>> > You changed the /proc/sys/vm/nr_hugepages to 1, because Cyril objected
>> the code
>> > in v6:
>> >
>> > SAFE_FILE_PRINTF("/proc/sys/vm/nr_hugepages", "%d", 2 * node->cnt);
>> >
>> > But as I note there [1], the original shell test did it this way and
>> kernel docs
>> > allows more than 1 to allocate. I'm obviously missing something.
>> >
>> > [1] https://lore.kernel.org/ltp/20250325133611.GB372417@pevik/
>> >
>> My understanding from Cyril's comments is no need reserve more hugepages,
>> since
>> this test case ONLY allocate 1 page through mmap.
>
>
> It depends on what you wanted there, if only 1 general huge page,
> `echo 1 > /proc/sys/vm/nr_hugepages` will try to reserve 1
> from a NUMA node randomly.
>
> But if you prefer to get 1 hugepage from a specified node, we need:
> `echo 1 >
> /sys/devices/system/node/node%u/hugepages/hugepages-%dkB/nr_hugepages`
>
> However, both ways won't guarantee the reservation will be 100% successful,
> which is based on the memory fragmentation situations.
>
> To be on the safe side, I would suggest using LTP unified API to reserve:
>
> https://github.com/linux-test-project/ltp/blob/master/doc/old/C-Test-API.asciidoc#134-reserving-hugepages
>
> You could reference usage from:
> mem/hugetlb/hugemmap/hugemmap16.c,
> syscalls/move_pages/move_pages12.c
>
I looked through all the code and got your requirements here.
The original test6 is echoing '2*$nr_mems' to the whole system
to make each node reserve some pages, then doing hugetlbfsfile
mapping to verify that the real allocated PAGE was happening
on the Cgroup set node.
(But the defect is that '2*$nr_mems' probably does not distribute to each
node ideally.
we should resolve this in the new test)
And that could be easy to convert into your C cpuset02 test, just
echo at least 1 nr_hugepages in each NUMA node, and binding the
child allocating process to the expected CGroup set, then verify
that only 1 hupage is really allocated in the correct node.
To show the idea on a two-node system is:
1. Reserve at least 1 hpage on each node and check the value is correct.
echo 1 >
/sys/devices/system/node/node0/hugepages/hugepages-%dkB/nr_hugepages
echo 1 >
/sys/devices/system/node/node1/hugepages/hugepages-%dkB/nr_hugepages
2. After folking, bind the child to the cgroup.procs.
3. Do mmap in the child with hugetlbfs file mapping (for allocating the 1
huage page).
4. Touch the memory and verify that only 1 huge page is allocated in the
expected node.
>
>
>
>>
>> @Cyril could you help confirm this?
>>
>> >
>> > Kind regards,
>> > Petr
>>
>> --
>> Mailing list info: https://lists.linux.it/listinfo/ltp
>>
>>
>
> --
> Regards,
> Li Wang
>
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v7 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-25 14:00 ` Petr Vorel
2025-03-26 4:14 ` Wei Gao via ltp
@ 2025-03-26 8:38 ` Li Wang via ltp
1 sibling, 0 replies; 62+ messages in thread
From: Li Wang via ltp @ 2025-03-26 8:38 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
Petr Vorel <pvorel@suse.cz> wrote:
> > +static struct tst_test test = {
> > + .needs_root = 1,
> > + .runs_script = 1,
> > + .mntpoint = MNTPOINT,
> > + .needs_hugetlbfs = 1,
> > + .setup = setup,
> > + .forks_child = 1,
> > + .cleanup = cleanup,
> > + .test_all = run_test,
>
> > + .hugepages = {3, TST_NEEDS},
>
This line is equal to `echo 3 > /proc/sys/vm/nr_hugepages` and check the 3
is there.
> > + .needs_checkpoints = 1,
> > + .needs_cgroup_ver = TST_CG_V1,
> > + .needs_cgroup_ctrls = (const char *const []){ "cpuset", NULL },
> > + .save_restore = (const struct tst_path_val[]) {
> > + {"/proc/sys/vm/nr_hugepages", NULL, TST_SR_TBROK},
>
If we set .hugepages then this line is redundant, because ltp-lib
already saved/restored that nr_hugepages for test.
See line#68 in /lib/tst_hugepage.c
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v7 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-26 7:38 ` Li Wang via ltp
2025-03-26 8:26 ` Li Wang via ltp
@ 2025-03-26 9:11 ` Wei Gao via ltp
2025-03-26 11:01 ` Li Wang via ltp
1 sibling, 1 reply; 62+ messages in thread
From: Wei Gao via ltp @ 2025-03-26 9:11 UTC (permalink / raw)
To: Li Wang; +Cc: ltp
On Wed, Mar 26, 2025 at 03:38:35PM +0800, Li Wang wrote:
> On Wed, Mar 26, 2025 at 12:15 PM Wei Gao via ltp <ltp@lists.linux.it> wrote:
>
> > On Tue, Mar 25, 2025 at 03:00:18PM +0100, Petr Vorel wrote:
> > > Hi Wei,
> > >
> > > ...
> > > > +static void run_test(void)
> > > > +{
> > > > + int pid;
> > > > + char node_id_str[256];
> > > > +
> > > > + cg_cpuset_0 = tst_cg_group_mk(tst_cg, "0");
> > > > +
> > > > + sprintf(node_id_str, "%u", check_node_id);
> > > > + SAFE_CG_PRINT(cg_cpuset_0, "cpuset.mems", node_id_str);
> > > > + SAFE_FILE_PRINTF("/proc/sys/vm/nr_hugepages", "%d", 1);
> > >
> > > You changed the /proc/sys/vm/nr_hugepages to 1, because Cyril objected
> > the code
> > > in v6:
> > >
> > > SAFE_FILE_PRINTF("/proc/sys/vm/nr_hugepages", "%d", 2 * node->cnt);
> > >
> > > But as I note there [1], the original shell test did it this way and
> > kernel docs
> > > allows more than 1 to allocate. I'm obviously missing something.
> > >
> > > [1] https://lore.kernel.org/ltp/20250325133611.GB372417@pevik/
> > >
> > My understanding from Cyril's comments is no need reserve more hugepages,
> > since
> > this test case ONLY allocate 1 page through mmap.
>
>
> It depends on what you wanted there, if only 1 general huge page,
> `echo 1 > /proc/sys/vm/nr_hugepages` will try to reserve 1
> from a NUMA node randomly.
Thanks for your valuable information, now i guess i find out why
original code using 2 * node->cnt instead of 1, it try to make
sure every node have at least reserve some pages.
>
> But if you prefer to get 1 hugepage from a specified node, we need:
> `echo 1 >
> /sys/devices/system/node/node%u/hugepages/hugepages-%dkB/nr_hugepages`
>
> However, both ways won't guarantee the reservation will be 100% successful,
> which is based on the memory fragmentation situations.
>
> To be on the safe side, I would suggest using LTP unified API to reserve:
> https://github.com/linux-test-project/ltp/blob/master/doc/old/C-Test-API.asciidoc#134-reserving-hugepages
>
> You could reference usage from:
> mem/hugetlb/hugemmap/hugemmap16.c,
> syscalls/move_pages/move_pages12.c
This case is check allocate memory on specific node, so if we set .hugepages = {1, TST_NEEDS},
then 1 page will reserve on NUMA node randomly, that means case still has chance to fail.
Also i guess current .hugepages can not support ".hugepages = {2 * node->cnt, TST_NEEDS}"
So the easy way is keep v6 implementation like following:
SAFE_FILE_PRINTF("/proc/sys/vm/nr_hugepages", "%d", 2 * node->cnt);
Correct me if any misunderstanding.
>
>
>
> >
> > @Cyril could you help confirm this?
> >
> > >
> > > Kind regards,
> > > Petr
> >
> > --
> > Mailing list info: https://lists.linux.it/listinfo/ltp
> >
> >
>
> --
> Regards,
> Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v7 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-26 9:11 ` Wei Gao via ltp
@ 2025-03-26 11:01 ` Li Wang via ltp
0 siblings, 0 replies; 62+ messages in thread
From: Li Wang via ltp @ 2025-03-26 11:01 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Wei Gao <wegao@suse.com> wrote:
>
> > It depends on what you wanted there, if only 1 general huge page,
> > `echo 1 > /proc/sys/vm/nr_hugepages` will try to reserve 1
> > from a NUMA node randomly.
> Thanks for your valuable information, now i guess i find out why
> original code using 2 * node->cnt instead of 1, it try to make
> sure every node have at least reserve some pages.
> >
> > But if you prefer to get 1 hugepage from a specified node, we need:
> > `echo 1 >
> > /sys/devices/system/node/node%u/hugepages/hugepages-%dkB/nr_hugepages`
> >
> > However, both ways won't guarantee the reservation will be 100%
> successful,
> > which is based on the memory fragmentation situations.
> >
> > To be on the safe side, I would suggest using LTP unified API to reserve:
> >
> https://github.com/linux-test-project/ltp/blob/master/doc/old/C-Test-API.asciidoc#134-reserving-hugepages
> >
> > You could reference usage from:
> > mem/hugetlb/hugemmap/hugemmap16.c,
> > syscalls/move_pages/move_pages12.c
>
> This case is check allocate memory on specific node, so if we set
> .hugepages = {1, TST_NEEDS},
> then 1 page will reserve on NUMA node randomly, that means case still has
> chance to fail.
>
Right.
> Also i guess current .hugepages can not support ".hugepages = {2 *
> node->cnt, TST_NEEDS}"
> So the easy way is keep v6 implementation like following:
> SAFE_FILE_PRINTF("/proc/sys/vm/nr_hugepages", "%d", 2 * node->cnt);
>
> Correct me if any misunderstanding.
>
In this case .hugepage may not fit your requirements.
We could directly keep 1 hpage reserved in each node
(in setup phase) for the coming allocation.
echo 1 > .../node0/hugepages/hugepages-%dkB/nr_hugepages
echo 1 > .../node1/hugepages/hugepages-%dkB/nr_hugepages
echo 1 > .../nodeX/hugepages/hugepages-%dkB/nr_hugepages
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* [LTP] [PATCH v8 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-24 12:00 ` [LTP] [PATCH v7 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2025-03-24 12:00 ` [LTP] [PATCH v7 1/2] " Wei Gao via ltp
2025-03-24 12:00 ` [LTP] [PATCH v7 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
@ 2025-03-28 7:59 ` Wei Gao via ltp
2025-03-28 7:59 ` [LTP] [PATCH v8 1/2] " Wei Gao via ltp
` (2 more replies)
2 siblings, 3 replies; 62+ messages in thread
From: Wei Gao via ltp @ 2025-03-28 7:59 UTC (permalink / raw)
To: ltp
Changes v7-v8:
* Update Petr's comments on v7
* Reserve at least 1 page on each node base Li Wang's suggestion
* Change check_node_id from node->map[0] to node->map[node->cnt - 1]
link to v7:
https://patchwork.ozlabs.org/project/ltp/patch/20250324120049.29270-2-wegao@suse.com/
Wei Gao (2):
cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
cpuset_memory_testset.sh: Remove test6
lib/tst_cgroup.c | 1 +
runtest/mm | 1 +
.../cpuset_memory_testset.sh | 37 +----
testcases/kernel/mem/.gitignore | 1 +
testcases/kernel/mem/cpuset/Makefile | 5 +
testcases/kernel/mem/cpuset/cpuset02.c | 138 ++++++++++++++++++
6 files changed, 148 insertions(+), 35 deletions(-)
create mode 100644 testcases/kernel/mem/cpuset/cpuset02.c
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* [LTP] [PATCH v8 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-28 7:59 ` [LTP] [PATCH v8 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
@ 2025-03-28 7:59 ` Wei Gao via ltp
2025-03-28 9:35 ` Li Wang via ltp
2025-03-28 7:59 ` [LTP] [PATCH v8 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
2025-03-31 3:19 ` [LTP] [PATCH v9 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2 siblings, 1 reply; 62+ messages in thread
From: Wei Gao via ltp @ 2025-03-28 7:59 UTC (permalink / raw)
To: ltp
Signed-off-by: Wei Gao <wegao@suse.com>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Suggested-by: Li Wang <liwang@redhat.com>
---
lib/tst_cgroup.c | 1 +
runtest/mm | 1 +
testcases/kernel/mem/.gitignore | 1 +
testcases/kernel/mem/cpuset/Makefile | 5 +
testcases/kernel/mem/cpuset/cpuset02.c | 138 +++++++++++++++++++++++++
5 files changed, 146 insertions(+)
create mode 100644 testcases/kernel/mem/cpuset/cpuset02.c
diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
index 73b696c58..545c779e7 100644
--- a/lib/tst_cgroup.c
+++ b/lib/tst_cgroup.c
@@ -204,6 +204,7 @@ static const struct cgroup_file cpuset_ctrl_files[] = {
{ "cpuset.cpus", "cpuset.cpus", CTRL_CPUSET },
{ "cpuset.mems", "cpuset.mems", CTRL_CPUSET },
{ "cpuset.memory_migrate", "cpuset.memory_migrate", CTRL_CPUSET },
+ { "cpuset.sched_load_balance", "cpuset.sched_load_balance", CTRL_CPUSET },
{ }
};
diff --git a/runtest/mm b/runtest/mm
index d8e62af81..5af29b0ea 100644
--- a/runtest/mm
+++ b/runtest/mm
@@ -75,6 +75,7 @@ ksm06_2 ksm06 -n 8000
ksm07 ksm07
cpuset01 cpuset01
+cpuset02 cpuset02
oom01 oom01
oom02 oom02
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index 699e022fb..e24e96001 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -1,4 +1,5 @@
/cpuset/cpuset01
+/cpuset/cpuset02
/hugetlb/hugefallocate/hugefallocate01
/hugetlb/hugefallocate/hugefallocate02
/hugetlb/hugefork/hugefork01
diff --git a/testcases/kernel/mem/cpuset/Makefile b/testcases/kernel/mem/cpuset/Makefile
index bac13e02b..7010c7be4 100644
--- a/testcases/kernel/mem/cpuset/Makefile
+++ b/testcases/kernel/mem/cpuset/Makefile
@@ -19,6 +19,11 @@
top_srcdir ?= ../../../..
+LTPLIBS = numa
+
include $(top_srcdir)/include/mk/testcases.mk
include $(top_srcdir)/testcases/kernel/include/lib.mk
+
+cpuset02: LTPLDLIBS = -lltpnuma
+
include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/mem/cpuset/cpuset02.c b/testcases/kernel/mem/cpuset/cpuset02.c
new file mode 100644
index 000000000..26b77f8be
--- /dev/null
+++ b/testcases/kernel/mem/cpuset/cpuset02.c
@@ -0,0 +1,138 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (c) 2025 SUSE LLC <wegao@suse.com>
+ */
+
+/*\
+ * Test checks cpuset.mems works with hugepage file.
+ * Based on test6 from cpuset_memory_testset.sh written by Miao Xie.
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include "tst_test.h"
+
+#ifdef HAVE_NUMA_V2
+#include <numaif.h>
+#include "tst_numa.h"
+
+#define MNTPOINT "hugetlbfs/"
+#define HUGE_PAGE_FILE MNTPOINT "hugepagefile"
+
+static long hpage_size;
+static struct tst_nodemap *node;
+static int check_node_id;
+static struct tst_cg_group *cg_cpuset_0;
+
+static void touch_memory_and_check_node(char *p, int size)
+{
+ int i;
+ int node = -1;
+ long ret;
+ int pagesize = sysconf(_SC_PAGESIZE);
+
+ for (i = 0; i < size; i += pagesize)
+ p[i] = 0xef;
+
+ ret = get_mempolicy(&node, NULL, 0, p, MPOL_F_NODE | MPOL_F_ADDR);
+ if (ret < 0)
+ tst_brk(TBROK | TERRNO, "get_mempolicy() failed");
+
+ if (node == check_node_id)
+ tst_res(TPASS, "check node pass");
+ else
+ tst_res(TFAIL, "check node failed");
+}
+
+static void child(void)
+{
+ char *p;
+ int fd_hugepage;
+
+ fd_hugepage = SAFE_OPEN(HUGE_PAGE_FILE, O_CREAT | O_RDWR, 0755);
+ p = SAFE_MMAP(NULL, hpage_size, PROT_WRITE | PROT_READ,
+ MAP_SHARED, fd_hugepage, 0);
+
+ touch_memory_and_check_node(p, hpage_size);
+
+ SAFE_MUNMAP(p, hpage_size);
+ SAFE_CLOSE(fd_hugepage);
+}
+
+static void run_test(void)
+{
+ int pid;
+ char node_id_str[256];
+
+ cg_cpuset_0 = tst_cg_group_mk(tst_cg, "0");
+
+ sprintf(node_id_str, "%u", check_node_id);
+ SAFE_CG_PRINT(cg_cpuset_0, "cpuset.mems", node_id_str);
+
+ pid = SAFE_FORK();
+
+ if (!pid) {
+ SAFE_CG_PRINTF(cg_cpuset_0, "cgroup.procs", "%d", pid);
+ child();
+ return;
+ }
+
+ SAFE_WAITPID(pid, NULL, 0);
+
+ cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
+}
+
+static void setup(void)
+{
+ node = tst_get_nodemap(TST_NUMA_MEM, getpagesize() / 1024);
+ if (node->cnt <= 1)
+ tst_brk(TCONF, "test requires at least 2 NUMA memory nodes");
+
+ check_node_id = node->map[node->cnt - 1];
+
+ hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;
+
+ char path[256];
+ unsigned int i;
+
+ for (i = 0; i < node->cnt; i++) {
+ unsigned int current_node_id = node->map[i];
+
+ sprintf(path,
+ "/sys/devices/system/node/node%d/hugepages/hugepages-%ldkB/nr_hugepages",
+ current_node_id, hpage_size / 1024);
+ SAFE_FILE_PRINTF(path, "%d", 1);
+ }
+}
+
+static void cleanup(void)
+{
+ if (cg_cpuset_0)
+ cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
+}
+
+static struct tst_test test = {
+ .needs_root = 1,
+ .runs_script = 1,
+ .mntpoint = MNTPOINT,
+ .needs_hugetlbfs = 1,
+ .setup = setup,
+ .forks_child = 1,
+ .cleanup = cleanup,
+ .test_all = run_test,
+ .needs_checkpoints = 1,
+ .needs_cgroup_ver = TST_CG_V1,
+ .needs_cgroup_ctrls = (const char *const []){ "cpuset", NULL },
+ .save_restore = (const struct tst_path_val[]) {
+ {"/proc/sys/vm/nr_hugepages", NULL, TST_SR_TCONF},
+ {}
+ },
+};
+
+#else
+TST_TEST_TCONF(NUMA_ERROR_MSG);
+#endif
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 62+ messages in thread
* [LTP] [PATCH v8 2/2] cpuset_memory_testset.sh: Remove test6
2025-03-28 7:59 ` [LTP] [PATCH v8 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2025-03-28 7:59 ` [LTP] [PATCH v8 1/2] " Wei Gao via ltp
@ 2025-03-28 7:59 ` Wei Gao via ltp
2025-03-31 3:19 ` [LTP] [PATCH v9 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2 siblings, 0 replies; 62+ messages in thread
From: Wei Gao via ltp @ 2025-03-28 7:59 UTC (permalink / raw)
To: ltp
Signed-off-by: Wei Gao <wegao@suse.com>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
---
.../cpuset_memory_testset.sh | 37 +------------------
1 file changed, 2 insertions(+), 35 deletions(-)
diff --git a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
index c1e7cea8f..fd41dc97a 100755
--- a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
+++ b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
@@ -162,41 +162,8 @@ check_hugetlbfs()
test6()
{
- cpuset_set "$CPUSET/0" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
- if [ $? -ne 0 ]; then
- cpuset_log_error $CPUSET_TMP/stderr
- tst_resm TFAIL "set general group parameter failed."
- return 1
- fi
-
- check_hugetlbfs
- if [ $? -eq 0 ]; then
- tst_resm TCONF "This system don't support hugetlbfs"
- return 0
- fi
-
- mkdir /hugetlb
- mount -t hugetlbfs none /hugetlb
-
- save_nr_hugepages=$(cat /proc/sys/vm/nr_hugepages)
- echo $((2*$nr_mems)) > /proc/sys/vm/nr_hugepages
-
- cpuset_memory_test --mmap-file --hugepage -s $HUGEPAGESIZE >"$MEMORY_RESULT" &
- simple_getresult $! "$CPUSET/0"
-
- umount /hugetlb
- rmdir /hugetlb
-
- echo $save_nr_hugepages > /proc/sys/vm/nr_hugepages
- if [ $(cat /proc/sys/vm/nr_hugepages) -ne $save_nr_hugepages ]; then
- tst_resm TFAIL "can't restore nr_hugepages(nr_hugepages = $save_nr_hugepages)."
- return 1
- fi
-
- if [ "$node" != "0" ]; then
- tst_resm TFAIL "allocate memory on the Node#$node(Expect: Node#0)."
- return 1
- fi
+ tst_resm TINFO "This test is replaced by testcases/kernel/mem/cpuset/cpuset02.c"
+ return 0
}
test7()
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v8 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-28 7:59 ` [LTP] [PATCH v8 1/2] " Wei Gao via ltp
@ 2025-03-28 9:35 ` Li Wang via ltp
2025-03-28 10:20 ` Petr Vorel
0 siblings, 1 reply; 62+ messages in thread
From: Li Wang via ltp @ 2025-03-28 9:35 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi Wei,
Geneally looks good, but some tiny places need improvement.
See comments inline.
On Fri, Mar 28, 2025 at 4:00 PM Wei Gao <wegao@suse.com> wrote:
> Signed-off-by: Wei Gao <wegao@suse.com>
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
> Suggested-by: Li Wang <liwang@redhat.com>
> ---
> lib/tst_cgroup.c | 1 +
> runtest/mm | 1 +
> testcases/kernel/mem/.gitignore | 1 +
> testcases/kernel/mem/cpuset/Makefile | 5 +
> testcases/kernel/mem/cpuset/cpuset02.c | 138 +++++++++++++++++++++++++
> 5 files changed, 146 insertions(+)
> create mode 100644 testcases/kernel/mem/cpuset/cpuset02.c
>
> diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
> index 73b696c58..545c779e7 100644
> --- a/lib/tst_cgroup.c
> +++ b/lib/tst_cgroup.c
> @@ -204,6 +204,7 @@ static const struct cgroup_file cpuset_ctrl_files[] = {
> { "cpuset.cpus", "cpuset.cpus", CTRL_CPUSET },
> { "cpuset.mems", "cpuset.mems", CTRL_CPUSET },
> { "cpuset.memory_migrate", "cpuset.memory_migrate", CTRL_CPUSET },
> + { "cpuset.sched_load_balance", "cpuset.sched_load_balance",
> CTRL_CPUSET },
>
cpuset.sched_load_balance is useful to enable/disable the scheduler can move
tasks between CPUs in the cpuset.
Is there any purpose to add this knob in cpuset02 patch? I didn't see you
touch it in the test.
{ }
> };
>
> diff --git a/runtest/mm b/runtest/mm
> index d8e62af81..5af29b0ea 100644
> --- a/runtest/mm
> +++ b/runtest/mm
> @@ -75,6 +75,7 @@ ksm06_2 ksm06 -n 8000
> ksm07 ksm07
>
> cpuset01 cpuset01
> +cpuset02 cpuset02
>
> oom01 oom01
> oom02 oom02
> diff --git a/testcases/kernel/mem/.gitignore
> b/testcases/kernel/mem/.gitignore
> index 699e022fb..e24e96001 100644
> --- a/testcases/kernel/mem/.gitignore
> +++ b/testcases/kernel/mem/.gitignore
> @@ -1,4 +1,5 @@
> /cpuset/cpuset01
> +/cpuset/cpuset02
> /hugetlb/hugefallocate/hugefallocate01
> /hugetlb/hugefallocate/hugefallocate02
> /hugetlb/hugefork/hugefork01
> diff --git a/testcases/kernel/mem/cpuset/Makefile
> b/testcases/kernel/mem/cpuset/Makefile
> index bac13e02b..7010c7be4 100644
> --- a/testcases/kernel/mem/cpuset/Makefile
> +++ b/testcases/kernel/mem/cpuset/Makefile
> @@ -19,6 +19,11 @@
>
> top_srcdir ?= ../../../..
>
> +LTPLIBS = numa
> +
> include $(top_srcdir)/include/mk/testcases.mk
> include $(top_srcdir)/testcases/kernel/include/lib.mk
> +
> +cpuset02: LTPLDLIBS = -lltpnuma
> +
> include $(top_srcdir)/include/mk/generic_leaf_target.mk
> diff --git a/testcases/kernel/mem/cpuset/cpuset02.c
> b/testcases/kernel/mem/cpuset/cpuset02.c
> new file mode 100644
> index 000000000..26b77f8be
> --- /dev/null
> +++ b/testcases/kernel/mem/cpuset/cpuset02.c
> @@ -0,0 +1,138 @@
> +// SPDX-License-Identifier: LGPL-2.1-or-later
> +/*
> + * Copyright (c) 2025 SUSE LLC <wegao@suse.com>
> + */
> +
> +/*\
> + * Test checks cpuset.mems works with hugepage file.
> + * Based on test6 from cpuset_memory_testset.sh written by Miao Xie.
> + */
> +
> +#define _GNU_SOURCE
> +#include <stdio.h>
> +#include <sys/mount.h>
> +#include <limits.h>
> +#include <sys/param.h>
> +#include <sys/types.h>
> +#include "tst_test.h"
> +
> +#ifdef HAVE_NUMA_V2
> +#include <numaif.h>
> +#include "tst_numa.h"
> +
> +#define MNTPOINT "hugetlbfs/"
> +#define HUGE_PAGE_FILE MNTPOINT "hugepagefile"
> +
> +static long hpage_size;
> +static struct tst_nodemap *node;
> +static int check_node_id;
> +static struct tst_cg_group *cg_cpuset_0;
> +
> +static void touch_memory_and_check_node(char *p, int size)
> +{
> + int i;
> + int node = -1;
> + long ret;
> + int pagesize = sysconf(_SC_PAGESIZE);
> +
> + for (i = 0; i < size; i += pagesize)
> + p[i] = 0xef;
> +
> + ret = get_mempolicy(&node, NULL, 0, p, MPOL_F_NODE | MPOL_F_ADDR);
> + if (ret < 0)
> + tst_brk(TBROK | TERRNO, "get_mempolicy() failed");
> +
> + if (node == check_node_id)
> + tst_res(TPASS, "check node pass");
>
I suggest printing the node for detailed info.
tst_res(TPASS, "1 huge page allocated on node-%d as expected", node);
> + else
> + tst_res(TFAIL, "check node failed");
>
tst_res(TFAIL, "1 huge page allocated on node-%d unexpected", node);
> +}
> +
> +static void child(void)
> +{
> + char *p;
> + int fd_hugepage;
> +
> + fd_hugepage = SAFE_OPEN(HUGE_PAGE_FILE, O_CREAT | O_RDWR, 0755);
> + p = SAFE_MMAP(NULL, hpage_size, PROT_WRITE | PROT_READ,
> + MAP_SHARED, fd_hugepage, 0);
> +
> + touch_memory_and_check_node(p, hpage_size);
> +
> + SAFE_MUNMAP(p, hpage_size);
> + SAFE_CLOSE(fd_hugepage);
> +}
> +
> +static void run_test(void)
> +{
> + int pid;
> + char node_id_str[256];
> +
> + cg_cpuset_0 = tst_cg_group_mk(tst_cg, "0");
> +
> + sprintf(node_id_str, "%u", check_node_id);
> + SAFE_CG_PRINT(cg_cpuset_0, "cpuset.mems", node_id_str);
> +
> + pid = SAFE_FORK();
> +
> + if (!pid) {
> + SAFE_CG_PRINTF(cg_cpuset_0, "cgroup.procs", "%d", pid);
> + child();
> + return;
> + }
> +
> + SAFE_WAITPID(pid, NULL, 0);
> +
> + cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
> +}
> +
> +static void setup(void)
> +{
> + node = tst_get_nodemap(TST_NUMA_MEM, getpagesize() / 1024);
> + if (node->cnt <= 1)
> + tst_brk(TCONF, "test requires at least 2 NUMA memory
> nodes");
> +
> + check_node_id = node->map[node->cnt - 1];
> +
> + hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;
> +
> + char path[256];
> + unsigned int i;
> +
> + for (i = 0; i < node->cnt; i++) {
> + unsigned int current_node_id = node->map[i];
> +
> + sprintf(path,
> +
> "/sys/devices/system/node/node%d/hugepages/hugepages-%ldkB/nr_hugepages",
> + current_node_id, hpage_size / 1024);
> + SAFE_FILE_PRINTF(path, "%d", 1);
>
SAFE_ macro will break if fails to set the value. However, the reservation
may not
succeed here due to memory fragmentation. So we can just use FILE_PRINTF().
Then, we need an additional check for the target node, if unable to
reserve, then TCONF there.
> + }
> +}
> +
> +static void cleanup(void)
> +{
> + if (cg_cpuset_0)
> + cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
> +}
> +
> +static struct tst_test test = {
> + .needs_root = 1,
>
> + .runs_script = 1,
>
Can we remove this line?
> + .mntpoint = MNTPOINT,
> + .needs_hugetlbfs = 1,
> + .setup = setup,
> + .forks_child = 1,
> + .cleanup = cleanup,
> + .test_all = run_test,
>
> + .needs_checkpoints = 1,
>
Remove this line?
> + .needs_cgroup_ver = TST_CG_V1,
>
The test is also useful to CG_V2, so let's remove this line as well.
> + .needs_cgroup_ctrls = (const char *const []){ "cpuset", NULL },
> + .save_restore = (const struct tst_path_val[]) {
> + {"/proc/sys/vm/nr_hugepages", NULL, TST_SR_TCONF},
> + {}
> + },
> +};
> +
> +#else
> +TST_TEST_TCONF(NUMA_ERROR_MSG);
> +#endif
> --
> 2.35.3
>
>
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v8 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-28 9:35 ` Li Wang via ltp
@ 2025-03-28 10:20 ` Petr Vorel
2025-03-28 10:57 ` Li Wang via ltp
0 siblings, 1 reply; 62+ messages in thread
From: Petr Vorel @ 2025-03-28 10:20 UTC (permalink / raw)
To: Li Wang; +Cc: ltp
Hi Li
> Hi Wei,
> Geneally looks good, but some tiny places need improvement.
> See comments inline.
Thanks for the review!
> On Fri, Mar 28, 2025 at 4:00 PM Wei Gao <wegao@suse.com> wrote:
> > Signed-off-by: Wei Gao <wegao@suse.com>
> > Reviewed-by: Petr Vorel <pvorel@suse.cz>
> > Suggested-by: Li Wang <liwang@redhat.com>
> > ---
> > lib/tst_cgroup.c | 1 +
> > runtest/mm | 1 +
> > testcases/kernel/mem/.gitignore | 1 +
> > testcases/kernel/mem/cpuset/Makefile | 5 +
> > testcases/kernel/mem/cpuset/cpuset02.c | 138 +++++++++++++++++++++++++
> > 5 files changed, 146 insertions(+)
> > create mode 100644 testcases/kernel/mem/cpuset/cpuset02.c
> > diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
> > index 73b696c58..545c779e7 100644
> > --- a/lib/tst_cgroup.c
> > +++ b/lib/tst_cgroup.c
> > @@ -204,6 +204,7 @@ static const struct cgroup_file cpuset_ctrl_files[] = {
> > { "cpuset.cpus", "cpuset.cpus", CTRL_CPUSET },
> > { "cpuset.mems", "cpuset.mems", CTRL_CPUSET },
> > { "cpuset.memory_migrate", "cpuset.memory_migrate", CTRL_CPUSET },
> > + { "cpuset.sched_load_balance", "cpuset.sched_load_balance",
> > CTRL_CPUSET },
> cpuset.sched_load_balance is useful to enable/disable the scheduler can move
> tasks between CPUs in the cpuset.
> Is there any purpose to add this knob in cpuset02 patch? I didn't see you
> touch it in the test.
Wei might had a different reason, but I see all functions in
cpuset_memory_testset.sh (including test6 being rewritten to this test) call
cpuset_funcs.sh which does 'echo 0 > .../cpuset.sched_load_balance', see:
test6()
{
...
cpuset_set "$CPUSET/0" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
cpuset_set()
{
...
local load_balance="$4"
...
/bin/echo $load_balance > $path/cpuset.sched_load_balance
I wonder whether it's good or not.
Kind regards,
Petr
> { }
> > };
> > diff --git a/runtest/mm b/runtest/mm
> > index d8e62af81..5af29b0ea 100644
> > --- a/runtest/mm
> > +++ b/runtest/mm
> > @@ -75,6 +75,7 @@ ksm06_2 ksm06 -n 8000
> > ksm07 ksm07
> > cpuset01 cpuset01
> > +cpuset02 cpuset02
> > oom01 oom01
> > oom02 oom02
> > diff --git a/testcases/kernel/mem/.gitignore
> > b/testcases/kernel/mem/.gitignore
> > index 699e022fb..e24e96001 100644
> > --- a/testcases/kernel/mem/.gitignore
> > +++ b/testcases/kernel/mem/.gitignore
> > @@ -1,4 +1,5 @@
> > /cpuset/cpuset01
> > +/cpuset/cpuset02
> > /hugetlb/hugefallocate/hugefallocate01
> > /hugetlb/hugefallocate/hugefallocate02
> > /hugetlb/hugefork/hugefork01
> > diff --git a/testcases/kernel/mem/cpuset/Makefile
> > b/testcases/kernel/mem/cpuset/Makefile
> > index bac13e02b..7010c7be4 100644
> > --- a/testcases/kernel/mem/cpuset/Makefile
> > +++ b/testcases/kernel/mem/cpuset/Makefile
> > @@ -19,6 +19,11 @@
> > top_srcdir ?= ../../../..
> > +LTPLIBS = numa
> > +
> > include $(top_srcdir)/include/mk/testcases.mk
> > include $(top_srcdir)/testcases/kernel/include/lib.mk
> > +
> > +cpuset02: LTPLDLIBS = -lltpnuma
> > +
> > include $(top_srcdir)/include/mk/generic_leaf_target.mk
> > diff --git a/testcases/kernel/mem/cpuset/cpuset02.c
> > b/testcases/kernel/mem/cpuset/cpuset02.c
> > new file mode 100644
> > index 000000000..26b77f8be
> > --- /dev/null
> > +++ b/testcases/kernel/mem/cpuset/cpuset02.c
> > @@ -0,0 +1,138 @@
> > +// SPDX-License-Identifier: LGPL-2.1-or-later
> > +/*
> > + * Copyright (c) 2025 SUSE LLC <wegao@suse.com>
> > + */
> > +
> > +/*\
> > + * Test checks cpuset.mems works with hugepage file.
> > + * Based on test6 from cpuset_memory_testset.sh written by Miao Xie.
> > + */
> > +
> > +#define _GNU_SOURCE
> > +#include <stdio.h>
> > +#include <sys/mount.h>
> > +#include <limits.h>
> > +#include <sys/param.h>
> > +#include <sys/types.h>
> > +#include "tst_test.h"
> > +
> > +#ifdef HAVE_NUMA_V2
> > +#include <numaif.h>
> > +#include "tst_numa.h"
> > +
> > +#define MNTPOINT "hugetlbfs/"
> > +#define HUGE_PAGE_FILE MNTPOINT "hugepagefile"
> > +
> > +static long hpage_size;
> > +static struct tst_nodemap *node;
> > +static int check_node_id;
> > +static struct tst_cg_group *cg_cpuset_0;
> > +
> > +static void touch_memory_and_check_node(char *p, int size)
> > +{
> > + int i;
> > + int node = -1;
> > + long ret;
> > + int pagesize = sysconf(_SC_PAGESIZE);
> > +
> > + for (i = 0; i < size; i += pagesize)
> > + p[i] = 0xef;
> > +
> > + ret = get_mempolicy(&node, NULL, 0, p, MPOL_F_NODE | MPOL_F_ADDR);
> > + if (ret < 0)
> > + tst_brk(TBROK | TERRNO, "get_mempolicy() failed");
> > +
> > + if (node == check_node_id)
> > + tst_res(TPASS, "check node pass");
> I suggest printing the node for detailed info.
> tst_res(TPASS, "1 huge page allocated on node-%d as expected", node);
> > + else
> > + tst_res(TFAIL, "check node failed");
> tst_res(TFAIL, "1 huge page allocated on node-%d unexpected", node);
> > +}
> > +
> > +static void child(void)
> > +{
> > + char *p;
> > + int fd_hugepage;
> > +
> > + fd_hugepage = SAFE_OPEN(HUGE_PAGE_FILE, O_CREAT | O_RDWR, 0755);
> > + p = SAFE_MMAP(NULL, hpage_size, PROT_WRITE | PROT_READ,
> > + MAP_SHARED, fd_hugepage, 0);
> > +
> > + touch_memory_and_check_node(p, hpage_size);
> > +
> > + SAFE_MUNMAP(p, hpage_size);
> > + SAFE_CLOSE(fd_hugepage);
> > +}
> > +
> > +static void run_test(void)
> > +{
> > + int pid;
> > + char node_id_str[256];
> > +
> > + cg_cpuset_0 = tst_cg_group_mk(tst_cg, "0");
> > +
> > + sprintf(node_id_str, "%u", check_node_id);
> > + SAFE_CG_PRINT(cg_cpuset_0, "cpuset.mems", node_id_str);
> > +
> > + pid = SAFE_FORK();
> > +
> > + if (!pid) {
> > + SAFE_CG_PRINTF(cg_cpuset_0, "cgroup.procs", "%d", pid);
> > + child();
> > + return;
> > + }
> > +
> > + SAFE_WAITPID(pid, NULL, 0);
> > +
> > + cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
> > +}
> > +
> > +static void setup(void)
> > +{
> > + node = tst_get_nodemap(TST_NUMA_MEM, getpagesize() / 1024);
> > + if (node->cnt <= 1)
> > + tst_brk(TCONF, "test requires at least 2 NUMA memory
> > nodes");
> > +
> > + check_node_id = node->map[node->cnt - 1];
> > +
> > + hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;
> > +
> > + char path[256];
> > + unsigned int i;
> > +
> > + for (i = 0; i < node->cnt; i++) {
> > + unsigned int current_node_id = node->map[i];
> > +
> > + sprintf(path,
> > +
> > "/sys/devices/system/node/node%d/hugepages/hugepages-%ldkB/nr_hugepages",
> > + current_node_id, hpage_size / 1024);
> > + SAFE_FILE_PRINTF(path, "%d", 1);
> SAFE_ macro will break if fails to set the value. However, the reservation
> may not
> succeed here due to memory fragmentation. So we can just use FILE_PRINTF().
> Then, we need an additional check for the target node, if unable to
> reserve, then TCONF there.
I suppose we cannot do the reservation via struct tst_test, right? (using
e.g. TST_SR_SKIP_RO from include/tst_sys_conf.h). That would require at least to
add tst_get_nodemap() to struct tst_test, right?
> > + }
> > +}
> > +
> > +static void cleanup(void)
> > +{
> > + if (cg_cpuset_0)
> > + cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
> > +}
> > +
> > +static struct tst_test test = {
> > + .needs_root = 1,
> > + .runs_script = 1,
> Can we remove this line?
+1, definitely not needed here (we don't use shell loader).
> > + .mntpoint = MNTPOINT,
> > + .needs_hugetlbfs = 1,
> > + .setup = setup,
> > + .forks_child = 1,
> > + .cleanup = cleanup,
> > + .test_all = run_test,
> > + .needs_checkpoints = 1,
> Remove this line?
+1, Cyril asked for removing checkpoints, this is left.
https://lore.kernel.org/ltp/Z88Ymlng3tEOKi0P@yuki.lan/
> > + .needs_cgroup_ver = TST_CG_V1,
> The test is also useful to CG_V2, so let's remove this line as well.
+1. The original shell script required v1. But C API allows to use both.
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v8 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-28 10:20 ` Petr Vorel
@ 2025-03-28 10:57 ` Li Wang via ltp
2025-03-28 11:04 ` Li Wang via ltp
2025-03-28 11:47 ` Petr Vorel
0 siblings, 2 replies; 62+ messages in thread
From: Li Wang via ltp @ 2025-03-28 10:57 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
On Fri, Mar 28, 2025 at 6:20 PM Petr Vorel <pvorel@suse.cz> wrote:
> Hi Li
>
> > Hi Wei,
>
> > Geneally looks good, but some tiny places need improvement.
> > See comments inline.
>
> Thanks for the review!
>
> > On Fri, Mar 28, 2025 at 4:00 PM Wei Gao <wegao@suse.com> wrote:
>
> > > Signed-off-by: Wei Gao <wegao@suse.com>
> > > Reviewed-by: Petr Vorel <pvorel@suse.cz>
> > > Suggested-by: Li Wang <liwang@redhat.com>
> > > ---
> > > lib/tst_cgroup.c | 1 +
> > > runtest/mm | 1 +
> > > testcases/kernel/mem/.gitignore | 1 +
> > > testcases/kernel/mem/cpuset/Makefile | 5 +
> > > testcases/kernel/mem/cpuset/cpuset02.c | 138 +++++++++++++++++++++++++
> > > 5 files changed, 146 insertions(+)
> > > create mode 100644 testcases/kernel/mem/cpuset/cpuset02.c
>
> > > diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
> > > index 73b696c58..545c779e7 100644
> > > --- a/lib/tst_cgroup.c
> > > +++ b/lib/tst_cgroup.c
> > > @@ -204,6 +204,7 @@ static const struct cgroup_file
> cpuset_ctrl_files[] = {
> > > { "cpuset.cpus", "cpuset.cpus", CTRL_CPUSET },
> > > { "cpuset.mems", "cpuset.mems", CTRL_CPUSET },
> > > { "cpuset.memory_migrate", "cpuset.memory_migrate",
> CTRL_CPUSET },
> > > + { "cpuset.sched_load_balance", "cpuset.sched_load_balance",
> > > CTRL_CPUSET },
>
>
> > cpuset.sched_load_balance is useful to enable/disable the scheduler can
> move
> > tasks between CPUs in the cpuset.
>
> > Is there any purpose to add this knob in cpuset02 patch? I didn't see you
> > touch it in the test.
>
> Wei might had a different reason, but I see all functions in
> cpuset_memory_testset.sh (including test6 being rewritten to this test)
> call
> cpuset_funcs.sh which does 'echo 0 > .../cpuset.sched_load_balance', see:
>
> test6()
> {
> ...
> cpuset_set "$CPUSET/0" "$cpu_of_node0" "0" "0" 2>
> $CPUSET_TMP/stderr
>
> cpuset_set()
> {
> ...
> local load_balance="$4"
> ...
> /bin/echo $load_balance > $path/cpuset.sched_load_balance
>
> I wonder whether it's good or not.
>
Ok, I see, it was used to disable the task from moving between CPUs
in the cpuset. But to be honest, that's _not_ necessary, because whatever
the task is bound to which CPU of the cpuset, it all belongs to that
specified
node by limited Cgroup.
So I would drop this knob setting in new C test.
>
> Kind regards,
> Petr
>
> > { }
> > > };
>
> > > diff --git a/runtest/mm b/runtest/mm
> > > index d8e62af81..5af29b0ea 100644
> > > --- a/runtest/mm
> > > +++ b/runtest/mm
> > > @@ -75,6 +75,7 @@ ksm06_2 ksm06 -n 8000
> > > ksm07 ksm07
>
> > > cpuset01 cpuset01
> > > +cpuset02 cpuset02
>
> > > oom01 oom01
> > > oom02 oom02
> > > diff --git a/testcases/kernel/mem/.gitignore
> > > b/testcases/kernel/mem/.gitignore
> > > index 699e022fb..e24e96001 100644
> > > --- a/testcases/kernel/mem/.gitignore
> > > +++ b/testcases/kernel/mem/.gitignore
> > > @@ -1,4 +1,5 @@
> > > /cpuset/cpuset01
> > > +/cpuset/cpuset02
> > > /hugetlb/hugefallocate/hugefallocate01
> > > /hugetlb/hugefallocate/hugefallocate02
> > > /hugetlb/hugefork/hugefork01
> > > diff --git a/testcases/kernel/mem/cpuset/Makefile
> > > b/testcases/kernel/mem/cpuset/Makefile
> > > index bac13e02b..7010c7be4 100644
> > > --- a/testcases/kernel/mem/cpuset/Makefile
> > > +++ b/testcases/kernel/mem/cpuset/Makefile
> > > @@ -19,6 +19,11 @@
>
> > > top_srcdir ?= ../../../..
>
> > > +LTPLIBS = numa
> > > +
> > > include $(top_srcdir)/include/mk/testcases.mk
> > > include $(top_srcdir)/testcases/kernel/include/lib.mk
> > > +
> > > +cpuset02: LTPLDLIBS = -lltpnuma
> > > +
> > > include $(top_srcdir)/include/mk/generic_leaf_target.mk
> > > diff --git a/testcases/kernel/mem/cpuset/cpuset02.c
> > > b/testcases/kernel/mem/cpuset/cpuset02.c
> > > new file mode 100644
> > > index 000000000..26b77f8be
> > > --- /dev/null
> > > +++ b/testcases/kernel/mem/cpuset/cpuset02.c
> > > @@ -0,0 +1,138 @@
> > > +// SPDX-License-Identifier: LGPL-2.1-or-later
> > > +/*
> > > + * Copyright (c) 2025 SUSE LLC <wegao@suse.com>
> > > + */
> > > +
> > > +/*\
> > > + * Test checks cpuset.mems works with hugepage file.
> > > + * Based on test6 from cpuset_memory_testset.sh written by Miao Xie.
> > > + */
> > > +
> > > +#define _GNU_SOURCE
> > > +#include <stdio.h>
> > > +#include <sys/mount.h>
> > > +#include <limits.h>
> > > +#include <sys/param.h>
> > > +#include <sys/types.h>
> > > +#include "tst_test.h"
> > > +
> > > +#ifdef HAVE_NUMA_V2
> > > +#include <numaif.h>
> > > +#include "tst_numa.h"
> > > +
> > > +#define MNTPOINT "hugetlbfs/"
> > > +#define HUGE_PAGE_FILE MNTPOINT "hugepagefile"
> > > +
> > > +static long hpage_size;
> > > +static struct tst_nodemap *node;
> > > +static int check_node_id;
> > > +static struct tst_cg_group *cg_cpuset_0;
> > > +
> > > +static void touch_memory_and_check_node(char *p, int size)
> > > +{
> > > + int i;
> > > + int node = -1;
> > > + long ret;
> > > + int pagesize = sysconf(_SC_PAGESIZE);
> > > +
> > > + for (i = 0; i < size; i += pagesize)
> > > + p[i] = 0xef;
> > > +
> > > + ret = get_mempolicy(&node, NULL, 0, p, MPOL_F_NODE |
> MPOL_F_ADDR);
> > > + if (ret < 0)
> > > + tst_brk(TBROK | TERRNO, "get_mempolicy() failed");
> > > +
> > > + if (node == check_node_id)
> > > + tst_res(TPASS, "check node pass");
>
>
> > I suggest printing the node for detailed info.
> > tst_res(TPASS, "1 huge page allocated on node-%d as expected", node);
>
>
> > > + else
> > > + tst_res(TFAIL, "check node failed");
>
>
> > tst_res(TFAIL, "1 huge page allocated on node-%d unexpected", node);
>
>
>
> > > +}
> > > +
> > > +static void child(void)
> > > +{
> > > + char *p;
> > > + int fd_hugepage;
> > > +
> > > + fd_hugepage = SAFE_OPEN(HUGE_PAGE_FILE, O_CREAT | O_RDWR,
> 0755);
> > > + p = SAFE_MMAP(NULL, hpage_size, PROT_WRITE | PROT_READ,
> > > + MAP_SHARED, fd_hugepage, 0);
> > > +
> > > + touch_memory_and_check_node(p, hpage_size);
> > > +
> > > + SAFE_MUNMAP(p, hpage_size);
> > > + SAFE_CLOSE(fd_hugepage);
> > > +}
> > > +
> > > +static void run_test(void)
> > > +{
> > > + int pid;
> > > + char node_id_str[256];
> > > +
> > > + cg_cpuset_0 = tst_cg_group_mk(tst_cg, "0");
> > > +
> > > + sprintf(node_id_str, "%u", check_node_id);
> > > + SAFE_CG_PRINT(cg_cpuset_0, "cpuset.mems", node_id_str);
> > > +
> > > + pid = SAFE_FORK();
> > > +
> > > + if (!pid) {
> > > + SAFE_CG_PRINTF(cg_cpuset_0, "cgroup.procs", "%d", pid);
> > > + child();
> > > + return;
> > > + }
> > > +
> > > + SAFE_WAITPID(pid, NULL, 0);
> > > +
> > > + cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
> > > +}
> > > +
> > > +static void setup(void)
> > > +{
> > > + node = tst_get_nodemap(TST_NUMA_MEM, getpagesize() / 1024);
> > > + if (node->cnt <= 1)
> > > + tst_brk(TCONF, "test requires at least 2 NUMA memory
> > > nodes");
> > > +
> > > + check_node_id = node->map[node->cnt - 1];
> > > +
> > > + hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;
> > > +
> > > + char path[256];
> > > + unsigned int i;
> > > +
> > > + for (i = 0; i < node->cnt; i++) {
> > > + unsigned int current_node_id = node->map[i];
> > > +
> > > + sprintf(path,
> > > +
> > >
> "/sys/devices/system/node/node%d/hugepages/hugepages-%ldkB/nr_hugepages",
> > > + current_node_id, hpage_size / 1024);
> > > + SAFE_FILE_PRINTF(path, "%d", 1);
>
>
> > SAFE_ macro will break if fails to set the value. However, the
> reservation
> > may not
> > succeed here due to memory fragmentation. So we can just use
> FILE_PRINTF().
>
> > Then, we need an additional check for the target node, if unable to
> > reserve, then TCONF there.
>
> I suppose we cannot do the reservation via struct tst_test, right? (using
> e.g. TST_SR_SKIP_RO from include/tst_sys_conf.h). That would require at
> least to
> add tst_get_nodemap() to struct tst_test, right?
>
You're right.
Do tst_test.hugepage reservation is not precise to a specified node.
We have to request that with dedicated code so far.
Maybe we can add something to the hpage reservation to support that,
but I don't see that feature as widely needed in LTP test. It might not
valuable to bring more complexity to the code just for this rarely used.
> > > + }
> > > +}
> > > +
> > > +static void cleanup(void)
> > > +{
> > > + if (cg_cpuset_0)
> > > + cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
> > > +}
> > > +
> > > +static struct tst_test test = {
> > > + .needs_root = 1,
>
>
>
> > > + .runs_script = 1,
>
>
> > Can we remove this line?
>
> +1, definitely not needed here (we don't use shell loader).
>
>
> > > + .mntpoint = MNTPOINT,
> > > + .needs_hugetlbfs = 1,
> > > + .setup = setup,
> > > + .forks_child = 1,
> > > + .cleanup = cleanup,
> > > + .test_all = run_test,
>
>
>
> > > + .needs_checkpoints = 1,
>
>
> > Remove this line?
>
> +1, Cyril asked for removing checkpoints, this is left.
>
> https://lore.kernel.org/ltp/Z88Ymlng3tEOKi0P@yuki.lan/
>
> > > + .needs_cgroup_ver = TST_CG_V1,
>
>
> > The test is also useful to CG_V2, so let's remove this line as well.
>
> +1. The original shell script required v1. But C API allows to use both.
>
> Kind regards,
> Petr
>
>
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v8 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-28 10:57 ` Li Wang via ltp
@ 2025-03-28 11:04 ` Li Wang via ltp
2025-03-28 11:47 ` Petr Vorel
1 sibling, 0 replies; 62+ messages in thread
From: Li Wang via ltp @ 2025-03-28 11:04 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
Li Wang <liwang@redhat.com> wrote:
> Ok, I see, it was used to disable the task from moving between CPUs
> in the cpuset. But to be honest, that's _not_ necessary, because whatever
> the task is bound to which CPU of the cpuset, it all belongs to that
> specified
> node by limited Cgroup.
>
One more word, this only applies to test6 (in cpuset_memory_testset.sh),
as it only makes use of one cpuset :).
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v8 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-28 10:57 ` Li Wang via ltp
2025-03-28 11:04 ` Li Wang via ltp
@ 2025-03-28 11:47 ` Petr Vorel
1 sibling, 0 replies; 62+ messages in thread
From: Petr Vorel @ 2025-03-28 11:47 UTC (permalink / raw)
To: Li Wang; +Cc: ltp
Hi Li, Wei,
...
> Ok, I see, it was used to disable the task from moving between CPUs
> in the cpuset. But to be honest, that's _not_ necessary, because whatever
> the task is bound to which CPU of the cpuset, it all belongs to that
> specified
> node by limited Cgroup.
> So I would drop this knob setting in new C test.
+1. Maybe worth to mention this in the commit message.
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* [LTP] [PATCH v9 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-28 7:59 ` [LTP] [PATCH v8 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2025-03-28 7:59 ` [LTP] [PATCH v8 1/2] " Wei Gao via ltp
2025-03-28 7:59 ` [LTP] [PATCH v8 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
@ 2025-03-31 3:19 ` Wei Gao via ltp
2025-03-31 3:19 ` [LTP] [PATCH v9 1/2] " Wei Gao via ltp
` (3 more replies)
2 siblings, 4 replies; 62+ messages in thread
From: Wei Gao via ltp @ 2025-03-31 3:19 UTC (permalink / raw)
To: ltp
Changes v8-v9:
* Remove .needs_cgroup_ver = TST_CG_V1, let case support both v1 and v2
* Remove cpuset.sched_load_balance knob
* Update base Li Wang and Petr's improvement suggestions on v8
link to v8:
https://patchwork.ozlabs.org/project/ltp/cover/20250328075958.7616-1-wegao@suse.com/
Wei Gao (2):
cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
cpuset_memory_testset.sh: Remove test6
runtest/mm | 1 +
.../cpuset_memory_testset.sh | 37 +----
testcases/kernel/mem/.gitignore | 1 +
testcases/kernel/mem/cpuset/Makefile | 5 +
testcases/kernel/mem/cpuset/cpuset02.c | 140 ++++++++++++++++++
5 files changed, 149 insertions(+), 35 deletions(-)
create mode 100644 testcases/kernel/mem/cpuset/cpuset02.c
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* [LTP] [PATCH v9 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-31 3:19 ` [LTP] [PATCH v9 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
@ 2025-03-31 3:19 ` Wei Gao via ltp
2025-03-31 5:05 ` Li Wang via ltp
2025-03-31 10:37 ` Petr Vorel
2025-03-31 3:19 ` [LTP] [PATCH v9 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
` (2 subsequent siblings)
3 siblings, 2 replies; 62+ messages in thread
From: Wei Gao via ltp @ 2025-03-31 3:19 UTC (permalink / raw)
To: ltp
Improvements compare with test6 shell test:
* Remove /bin/echo $load_balance > $path/cpuset.sched_load_balance
since test focus on verify huge page is really allocated in the correct
node, task no need bind to specific cpuset.
* Directly keep 1 hpage reserved in each node otherwise test case has
chance to fail, since `echo 1 > /proc/sys/vm/nr_hugepages` will try to
reserve 1 pages from a NUMA node randomly.
Signed-off-by: Wei Gao <wegao@suse.com>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Suggested-by: Li Wang <liwang@redhat.com>
---
runtest/mm | 1 +
testcases/kernel/mem/.gitignore | 1 +
testcases/kernel/mem/cpuset/Makefile | 5 +
testcases/kernel/mem/cpuset/cpuset02.c | 140 +++++++++++++++++++++++++
4 files changed, 147 insertions(+)
create mode 100644 testcases/kernel/mem/cpuset/cpuset02.c
diff --git a/runtest/mm b/runtest/mm
index d8e62af81..5af29b0ea 100644
--- a/runtest/mm
+++ b/runtest/mm
@@ -75,6 +75,7 @@ ksm06_2 ksm06 -n 8000
ksm07 ksm07
cpuset01 cpuset01
+cpuset02 cpuset02
oom01 oom01
oom02 oom02
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index 699e022fb..e24e96001 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -1,4 +1,5 @@
/cpuset/cpuset01
+/cpuset/cpuset02
/hugetlb/hugefallocate/hugefallocate01
/hugetlb/hugefallocate/hugefallocate02
/hugetlb/hugefork/hugefork01
diff --git a/testcases/kernel/mem/cpuset/Makefile b/testcases/kernel/mem/cpuset/Makefile
index bac13e02b..7010c7be4 100644
--- a/testcases/kernel/mem/cpuset/Makefile
+++ b/testcases/kernel/mem/cpuset/Makefile
@@ -19,6 +19,11 @@
top_srcdir ?= ../../../..
+LTPLIBS = numa
+
include $(top_srcdir)/include/mk/testcases.mk
include $(top_srcdir)/testcases/kernel/include/lib.mk
+
+cpuset02: LTPLDLIBS = -lltpnuma
+
include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/mem/cpuset/cpuset02.c b/testcases/kernel/mem/cpuset/cpuset02.c
new file mode 100644
index 000000000..1e239afa3
--- /dev/null
+++ b/testcases/kernel/mem/cpuset/cpuset02.c
@@ -0,0 +1,140 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (c) 2025 SUSE LLC <wegao@suse.com>
+ */
+
+/*\
+ * Test checks cpuset.mems works with hugepage file.
+ * Based on test6 from cpuset_memory_testset.sh written by Miao Xie.
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include "tst_test.h"
+
+#ifdef HAVE_NUMA_V2
+#include <numaif.h>
+#include "tst_numa.h"
+
+#define MNTPOINT "hugetlbfs/"
+#define HUGE_PAGE_FILE MNTPOINT "hugepagefile"
+
+static long hpage_size;
+static struct tst_nodemap *node;
+static int check_node_id;
+static struct tst_cg_group *cg_cpuset_0;
+
+static void touch_memory_and_check_node(char *p, int size)
+{
+ int i;
+ int node = -1;
+ long ret;
+ int pagesize = sysconf(_SC_PAGESIZE);
+
+ for (i = 0; i < size; i += pagesize)
+ p[i] = 0xef;
+
+ ret = get_mempolicy(&node, NULL, 0, p, MPOL_F_NODE | MPOL_F_ADDR);
+ if (ret < 0)
+ tst_brk(TBROK | TERRNO, "get_mempolicy() failed");
+
+ if (node == check_node_id)
+ tst_res(TPASS, "1 huge page allocated on node-%d as expected", node);
+ else
+ tst_res(TFAIL, "1 huge page allocated on node-%d unexpected", node);
+}
+
+static void child(void)
+{
+ char *p;
+ int fd_hugepage;
+
+ fd_hugepage = SAFE_OPEN(HUGE_PAGE_FILE, O_CREAT | O_RDWR, 0755);
+TST_EXP_PASS_SILENT(system("cat /proc/meminfo"));
+ p = SAFE_MMAP(NULL, hpage_size, PROT_WRITE | PROT_READ,
+ MAP_SHARED, fd_hugepage, 0);
+
+ touch_memory_and_check_node(p, hpage_size);
+
+ SAFE_MUNMAP(p, hpage_size);
+ SAFE_CLOSE(fd_hugepage);
+}
+
+static void run_test(void)
+{
+ int pid;
+ char node_id_str[256];
+
+ cg_cpuset_0 = tst_cg_group_mk(tst_cg, "0");
+
+ sprintf(node_id_str, "%u", check_node_id);
+ SAFE_CG_PRINT(cg_cpuset_0, "cpuset.mems", node_id_str);
+
+ pid = SAFE_FORK();
+
+ if (!pid) {
+ SAFE_CG_PRINTF(cg_cpuset_0, "cgroup.procs", "%d", pid);
+ child();
+ return;
+ }
+
+ SAFE_WAITPID(pid, NULL, 0);
+
+ cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
+}
+
+static void setup(void)
+{
+ node = tst_get_nodemap(TST_NUMA_MEM, getpagesize() / 1024);
+ if (node->cnt <= 1)
+ tst_brk(TCONF, "test requires at least 2 NUMA memory nodes");
+
+ check_node_id = node->map[node->cnt - 1];
+
+ hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;
+
+ char path[256];
+ unsigned int i;
+ unsigned int nr_hugepages;
+
+ for (i = 0; i < node->cnt; i++) {
+ unsigned int current_node_id = node->map[i];
+
+ sprintf(path,
+ "/sys/devices/system/node/node%d/hugepages/hugepages-%ldkB/nr_hugepages",
+ current_node_id, hpage_size / 1024);
+ FILE_PRINTF(path, "%d", 1);
+ SAFE_FILE_SCANF(path, "%d", &nr_hugepages);
+ if (nr_hugepages != 1)
+ tst_brk(TCONF, "reserve 1 huge page on node%d failed", current_node_id);
+ }
+}
+
+static void cleanup(void)
+{
+ if (cg_cpuset_0)
+ cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
+}
+
+static struct tst_test test = {
+ .needs_root = 1,
+ .mntpoint = MNTPOINT,
+ .needs_hugetlbfs = 1,
+ .setup = setup,
+ .forks_child = 1,
+ .cleanup = cleanup,
+ .test_all = run_test,
+ .needs_cgroup_ctrls = (const char *const []){ "cpuset", NULL },
+ .save_restore = (const struct tst_path_val[]) {
+ {"/proc/sys/vm/nr_hugepages", NULL, TST_SR_TCONF},
+ {}
+ },
+};
+
+#else
+TST_TEST_TCONF(NUMA_ERROR_MSG);
+#endif
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 62+ messages in thread
* [LTP] [PATCH v9 2/2] cpuset_memory_testset.sh: Remove test6
2025-03-31 3:19 ` [LTP] [PATCH v9 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2025-03-31 3:19 ` [LTP] [PATCH v9 1/2] " Wei Gao via ltp
@ 2025-03-31 3:19 ` Wei Gao via ltp
2025-03-31 5:05 ` Li Wang via ltp
2025-03-31 10:58 ` Petr Vorel
2025-03-31 10:21 ` [LTP] [PATCH v9 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Petr Vorel
2025-03-31 13:25 ` [LTP] [PATCH v10 " Wei Gao via ltp
3 siblings, 2 replies; 62+ messages in thread
From: Wei Gao via ltp @ 2025-03-31 3:19 UTC (permalink / raw)
To: ltp
Signed-off-by: Wei Gao <wegao@suse.com>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
---
.../cpuset_memory_testset.sh | 37 +------------------
1 file changed, 2 insertions(+), 35 deletions(-)
diff --git a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
index c1e7cea8f..fd41dc97a 100755
--- a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
+++ b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
@@ -162,41 +162,8 @@ check_hugetlbfs()
test6()
{
- cpuset_set "$CPUSET/0" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
- if [ $? -ne 0 ]; then
- cpuset_log_error $CPUSET_TMP/stderr
- tst_resm TFAIL "set general group parameter failed."
- return 1
- fi
-
- check_hugetlbfs
- if [ $? -eq 0 ]; then
- tst_resm TCONF "This system don't support hugetlbfs"
- return 0
- fi
-
- mkdir /hugetlb
- mount -t hugetlbfs none /hugetlb
-
- save_nr_hugepages=$(cat /proc/sys/vm/nr_hugepages)
- echo $((2*$nr_mems)) > /proc/sys/vm/nr_hugepages
-
- cpuset_memory_test --mmap-file --hugepage -s $HUGEPAGESIZE >"$MEMORY_RESULT" &
- simple_getresult $! "$CPUSET/0"
-
- umount /hugetlb
- rmdir /hugetlb
-
- echo $save_nr_hugepages > /proc/sys/vm/nr_hugepages
- if [ $(cat /proc/sys/vm/nr_hugepages) -ne $save_nr_hugepages ]; then
- tst_resm TFAIL "can't restore nr_hugepages(nr_hugepages = $save_nr_hugepages)."
- return 1
- fi
-
- if [ "$node" != "0" ]; then
- tst_resm TFAIL "allocate memory on the Node#$node(Expect: Node#0)."
- return 1
- fi
+ tst_resm TINFO "This test is replaced by testcases/kernel/mem/cpuset/cpuset02.c"
+ return 0
}
test7()
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v9 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-31 3:19 ` [LTP] [PATCH v9 1/2] " Wei Gao via ltp
@ 2025-03-31 5:05 ` Li Wang via ltp
2025-03-31 6:13 ` Wei Gao via ltp
2025-03-31 10:25 ` Petr Vorel
2025-03-31 10:37 ` Petr Vorel
1 sibling, 2 replies; 62+ messages in thread
From: Li Wang via ltp @ 2025-03-31 5:05 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
On Mon, Mar 31, 2025 at 11:20 AM Wei Gao <wegao@suse.com> wrote:
> Improvements compare with test6 shell test:
> * Remove /bin/echo $load_balance > $path/cpuset.sched_load_balance
> since test focus on verify huge page is really allocated in the correct
> node, task no need bind to specific cpuset.
> * Directly keep 1 hpage reserved in each node otherwise test case has
> chance to fail, since `echo 1 > /proc/sys/vm/nr_hugepages` will try to
> reserve 1 pages from a NUMA node randomly.
>
> Signed-off-by: Wei Gao <wegao@suse.com>
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
> Suggested-by: Li Wang <liwang@redhat.com>
>
Reviewed-by: Li Wang <liwang@redhat.com>
> +static void child(void)
> +{
> + char *p;
> + int fd_hugepage;
> +
> + fd_hugepage = SAFE_OPEN(HUGE_PAGE_FILE, O_CREAT | O_RDWR, 0755);
>
> +TST_EXP_PASS_SILENT(system("cat /proc/meminfo"));
>
This line is for debugging purposes, I guess, and it should be removed in
the formal patch.
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v9 2/2] cpuset_memory_testset.sh: Remove test6
2025-03-31 3:19 ` [LTP] [PATCH v9 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
@ 2025-03-31 5:05 ` Li Wang via ltp
2025-03-31 10:58 ` Petr Vorel
1 sibling, 0 replies; 62+ messages in thread
From: Li Wang via ltp @ 2025-03-31 5:05 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
On Mon, Mar 31, 2025 at 11:20 AM Wei Gao via ltp <ltp@lists.linux.it> wrote:
> Signed-off-by: Wei Gao <wegao@suse.com>
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
>
Reviewed-by: Li Wang <liwang@redhat.com>
---
> .../cpuset_memory_testset.sh | 37 +------------------
> 1 file changed, 2 insertions(+), 35 deletions(-)
>
> diff --git
> a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
> b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
> index c1e7cea8f..fd41dc97a 100755
> ---
> a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
> +++
> b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
> @@ -162,41 +162,8 @@ check_hugetlbfs()
>
> test6()
> {
> - cpuset_set "$CPUSET/0" "$cpu_of_node0" "0" "0" 2>
> $CPUSET_TMP/stderr
> - if [ $? -ne 0 ]; then
> - cpuset_log_error $CPUSET_TMP/stderr
> - tst_resm TFAIL "set general group parameter failed."
> - return 1
> - fi
> -
> - check_hugetlbfs
> - if [ $? -eq 0 ]; then
> - tst_resm TCONF "This system don't support hugetlbfs"
> - return 0
> - fi
> -
> - mkdir /hugetlb
> - mount -t hugetlbfs none /hugetlb
> -
> - save_nr_hugepages=$(cat /proc/sys/vm/nr_hugepages)
> - echo $((2*$nr_mems)) > /proc/sys/vm/nr_hugepages
> -
> - cpuset_memory_test --mmap-file --hugepage -s $HUGEPAGESIZE
> >"$MEMORY_RESULT" &
> - simple_getresult $! "$CPUSET/0"
> -
> - umount /hugetlb
> - rmdir /hugetlb
> -
> - echo $save_nr_hugepages > /proc/sys/vm/nr_hugepages
> - if [ $(cat /proc/sys/vm/nr_hugepages) -ne $save_nr_hugepages ];
> then
> - tst_resm TFAIL "can't restore nr_hugepages(nr_hugepages =
> $save_nr_hugepages)."
> - return 1
> - fi
> -
> - if [ "$node" != "0" ]; then
> - tst_resm TFAIL "allocate memory on the Node#$node(Expect:
> Node#0)."
> - return 1
> - fi
> + tst_resm TINFO "This test is replaced by
> testcases/kernel/mem/cpuset/cpuset02.c"
> + return 0
> }
>
> test7()
> --
> 2.35.3
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
>
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v9 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-31 5:05 ` Li Wang via ltp
@ 2025-03-31 6:13 ` Wei Gao via ltp
2025-03-31 10:25 ` Petr Vorel
1 sibling, 0 replies; 62+ messages in thread
From: Wei Gao via ltp @ 2025-03-31 6:13 UTC (permalink / raw)
To: Li Wang; +Cc: ltp
On Mon, Mar 31, 2025 at 01:05:38PM +0800, Li Wang wrote:
> On Mon, Mar 31, 2025 at 11:20 AM Wei Gao <wegao@suse.com> wrote:
>
> > Improvements compare with test6 shell test:
> > * Remove /bin/echo $load_balance > $path/cpuset.sched_load_balance
> > since test focus on verify huge page is really allocated in the correct
> > node, task no need bind to specific cpuset.
> > * Directly keep 1 hpage reserved in each node otherwise test case has
> > chance to fail, since `echo 1 > /proc/sys/vm/nr_hugepages` will try to
> > reserve 1 pages from a NUMA node randomly.
> >
> > Signed-off-by: Wei Gao <wegao@suse.com>
> > Reviewed-by: Petr Vorel <pvorel@suse.cz>
> > Suggested-by: Li Wang <liwang@redhat.com>
> >
>
> Reviewed-by: Li Wang <liwang@redhat.com>
>
>
> > +static void child(void)
> > +{
> > + char *p;
> > + int fd_hugepage;
> > +
> > + fd_hugepage = SAFE_OPEN(HUGE_PAGE_FILE, O_CREAT | O_RDWR, 0755);
> >
>
>
> > +TST_EXP_PASS_SILENT(system("cat /proc/meminfo"));
> >
>
> This line is for debugging purposes, I guess, and it should be removed in
> the formal patch.
Sorry, forget remove this debug line after done different scenario's verification.
i will wait for a while, if no more comments receive by end of today i will update
another new patch.
Thanks.
>
>
> --
> Regards,
> Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v9 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-31 3:19 ` [LTP] [PATCH v9 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2025-03-31 3:19 ` [LTP] [PATCH v9 1/2] " Wei Gao via ltp
2025-03-31 3:19 ` [LTP] [PATCH v9 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
@ 2025-03-31 10:21 ` Petr Vorel
2025-03-31 13:25 ` [LTP] [PATCH v10 " Wei Gao via ltp
3 siblings, 0 replies; 62+ messages in thread
From: Petr Vorel @ 2025-03-31 10:21 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
> Changes v8-v9:
> * Remove .needs_cgroup_ver = TST_CG_V1, let case support both v1 and v2
> * Remove cpuset.sched_load_balance knob
> * Update base Li Wang and Petr's improvement suggestions on v8
3rd point means:
* removed .runs_script = 1
* .needs_checkpoints = 1,
* SAFE_FILE_PRINTF() => FILE_PRINTF() and SAFE_FILE_SCANF() with TCONF check
Kind regards,
Petr
> link to v8:
> https://patchwork.ozlabs.org/project/ltp/cover/20250328075958.7616-1-wegao@suse.com/
> Wei Gao (2):
> cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
> cpuset_memory_testset.sh: Remove test6
> runtest/mm | 1 +
> .../cpuset_memory_testset.sh | 37 +----
> testcases/kernel/mem/.gitignore | 1 +
> testcases/kernel/mem/cpuset/Makefile | 5 +
> testcases/kernel/mem/cpuset/cpuset02.c | 140 ++++++++++++++++++
> 5 files changed, 149 insertions(+), 35 deletions(-)
> create mode 100644 testcases/kernel/mem/cpuset/cpuset02.c
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v9 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-31 5:05 ` Li Wang via ltp
2025-03-31 6:13 ` Wei Gao via ltp
@ 2025-03-31 10:25 ` Petr Vorel
1 sibling, 0 replies; 62+ messages in thread
From: Petr Vorel @ 2025-03-31 10:25 UTC (permalink / raw)
To: Li Wang; +Cc: ltp
> On Mon, Mar 31, 2025 at 11:20 AM Wei Gao <wegao@suse.com> wrote:
> > Improvements compare with test6 shell test:
> > * Remove /bin/echo $load_balance > $path/cpuset.sched_load_balance
> > since test focus on verify huge page is really allocated in the correct
> > node, task no need bind to specific cpuset.
> > * Directly keep 1 hpage reserved in each node otherwise test case has
> > chance to fail, since `echo 1 > /proc/sys/vm/nr_hugepages` will try to
> > reserve 1 pages from a NUMA node randomly.
> > Signed-off-by: Wei Gao <wegao@suse.com>
> > Reviewed-by: Petr Vorel <pvorel@suse.cz>
> > Suggested-by: Li Wang <liwang@redhat.com>
> Reviewed-by: Li Wang <liwang@redhat.com>
> > +static void child(void)
> > +{
> > + char *p;
> > + int fd_hugepage;
> > +
> > + fd_hugepage = SAFE_OPEN(HUGE_PAGE_FILE, O_CREAT | O_RDWR, 0755);
> > +TST_EXP_PASS_SILENT(system("cat /proc/meminfo"));
> This line is for debugging purposes, I guess, and it should be removed in
> the formal patch.
+1
With that changed you can keep my RBT. I hope v10 could be final.
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v9 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-31 3:19 ` [LTP] [PATCH v9 1/2] " Wei Gao via ltp
2025-03-31 5:05 ` Li Wang via ltp
@ 2025-03-31 10:37 ` Petr Vorel
2025-03-31 11:05 ` Li Wang via ltp
2025-03-31 11:30 ` Wei Gao via ltp
1 sibling, 2 replies; 62+ messages in thread
From: Petr Vorel @ 2025-03-31 10:37 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi Wei, Li, Cyril,
...
> +static void setup(void)
> +{
> + node = tst_get_nodemap(TST_NUMA_MEM, getpagesize() / 1024);
> + if (node->cnt <= 1)
> + tst_brk(TCONF, "test requires at least 2 NUMA memory nodes");
Naive question: why test requires 2 memory nodes? Wouldn't be 1 enough?
Kind regards,
Petr
> +
> + check_node_id = node->map[node->cnt - 1];
> +
> + hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;
> +
> + char path[256];
> + unsigned int i;
> + unsigned int nr_hugepages;
> +
> + for (i = 0; i < node->cnt; i++) {
> + unsigned int current_node_id = node->map[i];
> +
> + sprintf(path,
> + "/sys/devices/system/node/node%d/hugepages/hugepages-%ldkB/nr_hugepages",
> + current_node_id, hpage_size / 1024);
> + FILE_PRINTF(path, "%d", 1);
> + SAFE_FILE_SCANF(path, "%d", &nr_hugepages);
> + if (nr_hugepages != 1)
> + tst_brk(TCONF, "reserve 1 huge page on node%d failed", current_node_id);
> + }
> +}
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v9 2/2] cpuset_memory_testset.sh: Remove test6
2025-03-31 3:19 ` [LTP] [PATCH v9 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
2025-03-31 5:05 ` Li Wang via ltp
@ 2025-03-31 10:58 ` Petr Vorel
1 sibling, 0 replies; 62+ messages in thread
From: Petr Vorel @ 2025-03-31 10:58 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi Wei,
> Signed-off-by: Wei Gao <wegao@suse.com>
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
> ---
> .../cpuset_memory_testset.sh | 37 +------------------
> 1 file changed, 2 insertions(+), 35 deletions(-)
> diff --git a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
> index c1e7cea8f..fd41dc97a 100755
> --- a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
> +++ b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
> @@ -162,41 +162,8 @@ check_hugetlbfs()
> test6()
> {
> - cpuset_set "$CPUSET/0" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
> - if [ $? -ne 0 ]; then
> - cpuset_log_error $CPUSET_TMP/stderr
> - tst_resm TFAIL "set general group parameter failed."
> - return 1
> - fi
> -
> - check_hugetlbfs
> - if [ $? -eq 0 ]; then
> - tst_resm TCONF "This system don't support hugetlbfs"
> - return 0
> - fi
> -
> - mkdir /hugetlb
> - mount -t hugetlbfs none /hugetlb
> -
> - save_nr_hugepages=$(cat /proc/sys/vm/nr_hugepages)
> - echo $((2*$nr_mems)) > /proc/sys/vm/nr_hugepages
> -
> - cpuset_memory_test --mmap-file --hugepage -s $HUGEPAGESIZE >"$MEMORY_RESULT" &
> - simple_getresult $! "$CPUSET/0"
> -
> - umount /hugetlb
> - rmdir /hugetlb
> -
> - echo $save_nr_hugepages > /proc/sys/vm/nr_hugepages
> - if [ $(cat /proc/sys/vm/nr_hugepages) -ne $save_nr_hugepages ]; then
> - tst_resm TFAIL "can't restore nr_hugepages(nr_hugepages = $save_nr_hugepages)."
> - return 1
> - fi
> -
> - if [ "$node" != "0" ]; then
> - tst_resm TFAIL "allocate memory on the Node#$node(Expect: Node#0)."
> - return 1
> - fi
> + tst_resm TINFO "This test is replaced by testcases/kernel/mem/cpuset/cpuset02.c"
> + return 0
In new C shell API this would fail because test is not propagating any result. I
suppose this will work on old API, but wouldn't be better just remove whole
test6(), renumber tests and set TST_TOTAL=17?
Kind regards,
Petr
> }
> test7()
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v9 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-31 10:37 ` Petr Vorel
@ 2025-03-31 11:05 ` Li Wang via ltp
2025-03-31 11:30 ` Wei Gao via ltp
1 sibling, 0 replies; 62+ messages in thread
From: Li Wang via ltp @ 2025-03-31 11:05 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
On Mon, Mar 31, 2025 at 6:37 PM Petr Vorel <pvorel@suse.cz> wrote:
> Hi Wei, Li, Cyril,
>
> ...
> > +static void setup(void)
> > +{
> > + node = tst_get_nodemap(TST_NUMA_MEM, getpagesize() / 1024);
> > + if (node->cnt <= 1)
> > + tst_brk(TCONF, "test requires at least 2 NUMA memory
> nodes");
>
> Naive question: why test requires 2 memory nodes? Wouldn't be 1 enough?
>
Because test6 verify that hugepage + cpuset works well, so if we only use
1 node for testing, the allocated hugepage will always happen on that node.
Then we would lose the chance to find bug that there possibly allocated
from other nodes when setting the cpuset.
So this test needs at least two NUMA nodes.
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v9 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-31 10:37 ` Petr Vorel
2025-03-31 11:05 ` Li Wang via ltp
@ 2025-03-31 11:30 ` Wei Gao via ltp
1 sibling, 0 replies; 62+ messages in thread
From: Wei Gao via ltp @ 2025-03-31 11:30 UTC (permalink / raw)
To: Petr Vorel; +Cc: ltp
On Mon, Mar 31, 2025 at 12:37:51PM +0200, Petr Vorel wrote:
> Hi Wei, Li, Cyril,
>
> ...
> > +static void setup(void)
> > +{
> > + node = tst_get_nodemap(TST_NUMA_MEM, getpagesize() / 1024);
> > + if (node->cnt <= 1)
> > + tst_brk(TCONF, "test requires at least 2 NUMA memory nodes");
> Naive question: why test requires 2 memory nodes? Wouldn't be 1 enough?
Depend on what test's purpuse, if you need check kernel select correct node, i
suppose we need at least 2 nodes. Of course, test case also can support 1 node check.
>
> Kind regards,
> Petr
>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* [LTP] [PATCH v10 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-31 3:19 ` [LTP] [PATCH v9 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
` (2 preceding siblings ...)
2025-03-31 10:21 ` [LTP] [PATCH v9 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Petr Vorel
@ 2025-03-31 13:25 ` Wei Gao via ltp
2025-03-31 13:25 ` [LTP] [PATCH v10 1/2] " Wei Gao via ltp
2025-03-31 13:25 ` [LTP] [PATCH v10 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
3 siblings, 2 replies; 62+ messages in thread
From: Wei Gao via ltp @ 2025-03-31 13:25 UTC (permalink / raw)
To: ltp
Changes v9-v10:
* Remove debug line
* Remove whole test6(), renumber tests and set TST_TOTAL=17
link to v9:
https://patchwork.ozlabs.org/project/ltp/cover/20250331031945.5948-1-wegao@suse.com/
Wei Gao (2):
cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
cpuset_memory_testset.sh: Remove test6
runtest/mm | 1 +
.../cpuset_memory_testset.sh | 63 ++------
testcases/kernel/mem/.gitignore | 1 +
testcases/kernel/mem/cpuset/Makefile | 5 +
testcases/kernel/mem/cpuset/cpuset02.c | 139 ++++++++++++++++++
5 files changed, 158 insertions(+), 51 deletions(-)
create mode 100644 testcases/kernel/mem/cpuset/cpuset02.c
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
* [LTP] [PATCH v10 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-31 13:25 ` [LTP] [PATCH v10 " Wei Gao via ltp
@ 2025-03-31 13:25 ` Wei Gao via ltp
2025-04-01 9:58 ` Li Wang via ltp
2025-03-31 13:25 ` [LTP] [PATCH v10 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
1 sibling, 1 reply; 62+ messages in thread
From: Wei Gao via ltp @ 2025-03-31 13:25 UTC (permalink / raw)
To: ltp
Improvements compare with test6 shell test:
* Remove /bin/echo $load_balance > $path/cpuset.sched_load_balance
since test focus on verify huge page is really allocated in the correct
node, task no need bind to specific cpuset.
* Directly keep 1 hpage reserved in each node otherwise test case has
chance to fail, since `echo 1 > /proc/sys/vm/nr_hugepages` will try to
reserve 1 pages from a NUMA node randomly.
Signed-off-by: Wei Gao <wegao@suse.com>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Suggested-by: Li Wang <liwang@redhat.com>
Reviewed-by: Li Wang <liwang@redhat.com>
---
runtest/mm | 1 +
testcases/kernel/mem/.gitignore | 1 +
testcases/kernel/mem/cpuset/Makefile | 5 +
testcases/kernel/mem/cpuset/cpuset02.c | 139 +++++++++++++++++++++++++
4 files changed, 146 insertions(+)
create mode 100644 testcases/kernel/mem/cpuset/cpuset02.c
diff --git a/runtest/mm b/runtest/mm
index 871e1f026..5566a7742 100644
--- a/runtest/mm
+++ b/runtest/mm
@@ -68,6 +68,7 @@ ksm06_2 ksm06 -n 8000
ksm07 ksm07
cpuset01 cpuset01
+cpuset02 cpuset02
oom01 oom01
oom02 oom02
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index 699e022fb..e24e96001 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -1,4 +1,5 @@
/cpuset/cpuset01
+/cpuset/cpuset02
/hugetlb/hugefallocate/hugefallocate01
/hugetlb/hugefallocate/hugefallocate02
/hugetlb/hugefork/hugefork01
diff --git a/testcases/kernel/mem/cpuset/Makefile b/testcases/kernel/mem/cpuset/Makefile
index bac13e02b..7010c7be4 100644
--- a/testcases/kernel/mem/cpuset/Makefile
+++ b/testcases/kernel/mem/cpuset/Makefile
@@ -19,6 +19,11 @@
top_srcdir ?= ../../../..
+LTPLIBS = numa
+
include $(top_srcdir)/include/mk/testcases.mk
include $(top_srcdir)/testcases/kernel/include/lib.mk
+
+cpuset02: LTPLDLIBS = -lltpnuma
+
include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/mem/cpuset/cpuset02.c b/testcases/kernel/mem/cpuset/cpuset02.c
new file mode 100644
index 000000000..ad5fae536
--- /dev/null
+++ b/testcases/kernel/mem/cpuset/cpuset02.c
@@ -0,0 +1,139 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (c) 2025 SUSE LLC <wegao@suse.com>
+ */
+
+/*\
+ * Test checks cpuset.mems works with hugepage file.
+ * Based on test6 from cpuset_memory_testset.sh written by Miao Xie.
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include "tst_test.h"
+
+#ifdef HAVE_NUMA_V2
+#include <numaif.h>
+#include "tst_numa.h"
+
+#define MNTPOINT "hugetlbfs/"
+#define HUGE_PAGE_FILE MNTPOINT "hugepagefile"
+
+static long hpage_size;
+static struct tst_nodemap *node;
+static int check_node_id;
+static struct tst_cg_group *cg_cpuset_0;
+
+static void touch_memory_and_check_node(char *p, int size)
+{
+ int i;
+ int node = -1;
+ long ret;
+ int pagesize = sysconf(_SC_PAGESIZE);
+
+ for (i = 0; i < size; i += pagesize)
+ p[i] = 0xef;
+
+ ret = get_mempolicy(&node, NULL, 0, p, MPOL_F_NODE | MPOL_F_ADDR);
+ if (ret < 0)
+ tst_brk(TBROK | TERRNO, "get_mempolicy() failed");
+
+ if (node == check_node_id)
+ tst_res(TPASS, "1 huge page allocated on node-%d as expected", node);
+ else
+ tst_res(TFAIL, "1 huge page allocated on node-%d unexpected", node);
+}
+
+static void child(void)
+{
+ char *p;
+ int fd_hugepage;
+
+ fd_hugepage = SAFE_OPEN(HUGE_PAGE_FILE, O_CREAT | O_RDWR, 0755);
+ p = SAFE_MMAP(NULL, hpage_size, PROT_WRITE | PROT_READ,
+ MAP_SHARED, fd_hugepage, 0);
+
+ touch_memory_and_check_node(p, hpage_size);
+
+ SAFE_MUNMAP(p, hpage_size);
+ SAFE_CLOSE(fd_hugepage);
+}
+
+static void run_test(void)
+{
+ int pid;
+ char node_id_str[256];
+
+ cg_cpuset_0 = tst_cg_group_mk(tst_cg, "0");
+
+ sprintf(node_id_str, "%u", check_node_id);
+ SAFE_CG_PRINT(cg_cpuset_0, "cpuset.mems", node_id_str);
+
+ pid = SAFE_FORK();
+
+ if (!pid) {
+ SAFE_CG_PRINTF(cg_cpuset_0, "cgroup.procs", "%d", pid);
+ child();
+ return;
+ }
+
+ SAFE_WAITPID(pid, NULL, 0);
+
+ cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
+}
+
+static void setup(void)
+{
+ node = tst_get_nodemap(TST_NUMA_MEM, getpagesize() / 1024);
+ if (node->cnt <= 1)
+ tst_brk(TCONF, "test requires at least 2 NUMA memory nodes");
+
+ check_node_id = node->map[node->cnt - 1];
+
+ hpage_size = SAFE_READ_MEMINFO(MEMINFO_HPAGE_SIZE)*1024;
+
+ char path[256];
+ unsigned int i;
+ unsigned int nr_hugepages;
+
+ for (i = 0; i < node->cnt; i++) {
+ unsigned int current_node_id = node->map[i];
+
+ sprintf(path,
+ "/sys/devices/system/node/node%d/hugepages/hugepages-%ldkB/nr_hugepages",
+ current_node_id, hpage_size / 1024);
+ FILE_PRINTF(path, "%d", 1);
+ SAFE_FILE_SCANF(path, "%d", &nr_hugepages);
+ if (nr_hugepages != 1)
+ tst_brk(TCONF, "reserve 1 huge page on node%d failed", current_node_id);
+ }
+}
+
+static void cleanup(void)
+{
+ if (cg_cpuset_0)
+ cg_cpuset_0 = tst_cg_group_rm(cg_cpuset_0);
+}
+
+static struct tst_test test = {
+ .needs_root = 1,
+ .mntpoint = MNTPOINT,
+ .needs_hugetlbfs = 1,
+ .setup = setup,
+ .forks_child = 1,
+ .cleanup = cleanup,
+ .test_all = run_test,
+ .needs_cgroup_ctrls = (const char *const []){ "cpuset", NULL },
+ .save_restore = (const struct tst_path_val[]) {
+ {"/proc/sys/vm/nr_hugepages", NULL, TST_SR_TCONF},
+ {}
+ },
+};
+
+#else
+TST_TEST_TCONF(NUMA_ERROR_MSG);
+#endif
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 62+ messages in thread
* [LTP] [PATCH v10 2/2] cpuset_memory_testset.sh: Remove test6
2025-03-31 13:25 ` [LTP] [PATCH v10 " Wei Gao via ltp
2025-03-31 13:25 ` [LTP] [PATCH v10 1/2] " Wei Gao via ltp
@ 2025-03-31 13:25 ` Wei Gao via ltp
1 sibling, 0 replies; 62+ messages in thread
From: Wei Gao via ltp @ 2025-03-31 13:25 UTC (permalink / raw)
To: ltp
Signed-off-by: Wei Gao <wegao@suse.com>
---
.../cpuset_memory_testset.sh | 63 ++++---------------
1 file changed, 12 insertions(+), 51 deletions(-)
diff --git a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
index c1e7cea8f..e81d22293 100755
--- a/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
+++ b/testcases/kernel/controllers/cpuset/cpuset_memory_test/cpuset_memory_testset.sh
@@ -23,7 +23,7 @@
################################################################################
export TCID="cpuset_memory"
-export TST_TOTAL=18
+export TST_TOTAL=17
export TST_COUNT=1
. cpuset_funcs.sh
@@ -181,45 +181,6 @@ test6()
save_nr_hugepages=$(cat /proc/sys/vm/nr_hugepages)
echo $((2*$nr_mems)) > /proc/sys/vm/nr_hugepages
- cpuset_memory_test --mmap-file --hugepage -s $HUGEPAGESIZE >"$MEMORY_RESULT" &
- simple_getresult $! "$CPUSET/0"
-
- umount /hugetlb
- rmdir /hugetlb
-
- echo $save_nr_hugepages > /proc/sys/vm/nr_hugepages
- if [ $(cat /proc/sys/vm/nr_hugepages) -ne $save_nr_hugepages ]; then
- tst_resm TFAIL "can't restore nr_hugepages(nr_hugepages = $save_nr_hugepages)."
- return 1
- fi
-
- if [ "$node" != "0" ]; then
- tst_resm TFAIL "allocate memory on the Node#$node(Expect: Node#0)."
- return 1
- fi
-}
-
-test7()
-{
- cpuset_set "$CPUSET/0" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
- if [ $? -ne 0 ]; then
- cpuset_log_error $CPUSET_TMP/stderr
- tst_resm TFAIL "set general group parameter failed."
- return 1
- fi
-
- check_hugetlbfs
- if [ $? -eq 0 ]; then
- tst_resm TCONF "This system don't support hugetlbfs"
- return 0
- fi
-
- mkdir /hugetlb
- mount -t hugetlbfs none /hugetlb
-
- save_nr_hugepages=$(cat /proc/sys/vm/nr_hugepages)
- echo $((2*$nr_mems)) > /proc/sys/vm/nr_hugepages
-
cpuset_memory_test --shm --hugepage -s $HUGEPAGESIZE --key=7 >"$MEMORY_RESULT" &
simple_getresult $! "$CPUSET/0"
@@ -238,7 +199,7 @@ test7()
fi
}
-test8()
+test7()
{
cpuset_set "$CPUSET/0" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
if [ $? -ne 0 ]; then
@@ -255,7 +216,7 @@ test8()
fi
}
-test9()
+test8()
{
cpuset_set "$CPUSET/0" "$cpu_of_node0" "1" "0" 2> $CPUSET_TMP/stderr
if [ $? -ne 0 ]; then
@@ -291,7 +252,7 @@ talk2memory_test_for_case_10_11()
wait $1
}
-test10()
+test9()
{
cpuset_set "$CPUSET/1" "$cpus_all" "0" "0" 2> $CPUSET_TMP/stderr
if [ $? -ne 0 ]; then
@@ -329,7 +290,7 @@ test10()
fi
}
-test11()
+test10()
{
cpuset_set "$CPUSET/1" "$cpus_all" "0" "0" 2> $CPUSET_TMP/stderr
if [ $? -ne 0 ]; then
@@ -395,7 +356,7 @@ talk2memory_test_for_case_12_13()
}
-test12()
+test11()
{
cpuset_set "$CPUSET/0" "$cpu_of_node0" "1" "0" 2> $CPUSET_TMP/stderr
if [ $? -ne 0 ]; then
@@ -423,7 +384,7 @@ test12()
}
-test13()
+test12()
{
cpuset_set "$CPUSET/0" "$cpu_of_node0" "1" "0" 2> $CPUSET_TMP/stderr
if [ $? -ne 0 ]; then
@@ -479,7 +440,7 @@ get_the_second()
)
}
-test14()
+test13()
{
cpuset_set "$CPUSET/1" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
if [ $? -ne 0 ]; then
@@ -527,7 +488,7 @@ test14()
fi
}
-test15()
+test14()
{
cpuset_set "$CPUSET/1" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
if [ $? -ne 0 ]; then
@@ -583,7 +544,7 @@ test15()
fi
}
-test16()
+test15()
{
cpuset_set "$CPUSET/1" "$cpu_of_node0" "0" "0" 2> $CPUSET_TMP/stderr
if [ $? -ne 0 ]; then
@@ -650,7 +611,7 @@ test16()
fi
}
-test17()
+test16()
{
cpuset_set "$CPUSET/1" "$cpu_of_node0" "1" "0" 2> $CPUSET_TMP/stderr
if [ $? -ne 0 ]; then
@@ -725,7 +686,7 @@ test17()
fi
}
-test18()
+test17()
{
cpuset_set "$CPUSET/1" "$cpu_of_node0" "1" "0" 2> $CPUSET_TMP/stderr
if [ $? -ne 0 ]; then
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 62+ messages in thread
* Re: [LTP] [PATCH v10 1/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code
2025-03-31 13:25 ` [LTP] [PATCH v10 1/2] " Wei Gao via ltp
@ 2025-04-01 9:58 ` Li Wang via ltp
0 siblings, 0 replies; 62+ messages in thread
From: Li Wang via ltp @ 2025-04-01 9:58 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Pushed with minor improvements.
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 62+ messages in thread
end of thread, other threads:[~2025-04-01 9:59 UTC | newest]
Thread overview: 62+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-01 10:40 [LTP] [PATCH v1] cpuset_memory_test.c: Use $TMPDIR as prefix for HUGEPAGE file path Wei Gao via ltp
2024-08-01 12:16 ` Petr Vorel
2024-08-01 12:20 ` Cyril Hrubis
2024-08-19 4:49 ` [LTP] [PATCH v2] cpuset02: Reimplementing the test6 of cpuset_memory_testset.sh as a separate C testcase Wei Gao via ltp
2024-09-26 6:19 ` [LTP] [PATCH v3] " Wei Gao via ltp
2024-09-27 10:30 ` Cyril Hrubis
2024-09-30 13:58 ` [LTP] [PATCH v4] " Wei Gao via ltp
2024-11-01 10:58 ` Petr Vorel
2024-11-05 5:30 ` Wei Gao via ltp
2024-11-05 11:44 ` Petr Vorel
2024-11-07 4:20 ` Wei Gao via ltp
2024-11-08 5:45 ` Wei Gao via ltp
2024-12-09 6:01 ` [LTP] [PATCH v5 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2024-12-09 6:01 ` [LTP] [PATCH v5 1/2] " Wei Gao via ltp
2025-02-27 16:02 ` Petr Vorel
2024-12-09 6:01 ` [LTP] [PATCH v5 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
2025-02-27 16:04 ` Petr Vorel
2025-03-05 4:29 ` Wei Gao via ltp
2025-03-05 5:08 ` [LTP] [PATCH v6 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2025-03-05 5:08 ` [LTP] [PATCH v6 1/2] " Wei Gao via ltp
2025-03-06 18:35 ` Petr Vorel
2025-03-10 16:51 ` Cyril Hrubis
2025-03-25 13:36 ` Petr Vorel
2025-03-05 5:08 ` [LTP] [PATCH v6 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
2025-03-06 18:32 ` Petr Vorel
2025-03-24 12:00 ` [LTP] [PATCH v7 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2025-03-24 12:00 ` [LTP] [PATCH v7 1/2] " Wei Gao via ltp
2025-03-25 14:00 ` Petr Vorel
2025-03-26 4:14 ` Wei Gao via ltp
2025-03-26 7:38 ` Li Wang via ltp
2025-03-26 8:26 ` Li Wang via ltp
2025-03-26 9:11 ` Wei Gao via ltp
2025-03-26 11:01 ` Li Wang via ltp
2025-03-26 8:38 ` Li Wang via ltp
2025-03-24 12:00 ` [LTP] [PATCH v7 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
2025-03-24 15:32 ` Petr Vorel
2025-03-25 3:32 ` Wei Gao via ltp
2025-03-25 3:54 ` Wei Gao via ltp
2025-03-28 7:59 ` [LTP] [PATCH v8 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2025-03-28 7:59 ` [LTP] [PATCH v8 1/2] " Wei Gao via ltp
2025-03-28 9:35 ` Li Wang via ltp
2025-03-28 10:20 ` Petr Vorel
2025-03-28 10:57 ` Li Wang via ltp
2025-03-28 11:04 ` Li Wang via ltp
2025-03-28 11:47 ` Petr Vorel
2025-03-28 7:59 ` [LTP] [PATCH v8 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
2025-03-31 3:19 ` [LTP] [PATCH v9 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Wei Gao via ltp
2025-03-31 3:19 ` [LTP] [PATCH v9 1/2] " Wei Gao via ltp
2025-03-31 5:05 ` Li Wang via ltp
2025-03-31 6:13 ` Wei Gao via ltp
2025-03-31 10:25 ` Petr Vorel
2025-03-31 10:37 ` Petr Vorel
2025-03-31 11:05 ` Li Wang via ltp
2025-03-31 11:30 ` Wei Gao via ltp
2025-03-31 3:19 ` [LTP] [PATCH v9 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
2025-03-31 5:05 ` Li Wang via ltp
2025-03-31 10:58 ` Petr Vorel
2025-03-31 10:21 ` [LTP] [PATCH v9 0/2] cpuset02: Convert the test6 from cpuset_memory_testset.sh to C code Petr Vorel
2025-03-31 13:25 ` [LTP] [PATCH v10 " Wei Gao via ltp
2025-03-31 13:25 ` [LTP] [PATCH v10 1/2] " Wei Gao via ltp
2025-04-01 9:58 ` Li Wang via ltp
2025-03-31 13:25 ` [LTP] [PATCH v10 2/2] cpuset_memory_testset.sh: Remove test6 Wei Gao via ltp
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox