Skip to contentSkip to conversation

selftests/cgroup: test_zswap: skip test_no_kmem_bypass if debugfs is unavailable

PATCH Superseded Wilson Felipe Pereira 3 participants 3 messages Aug 1 – Aug 3

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/cgroup: test_zswap: skip test_no_kmem_bypass if debugfs is unavailable

test_no_kmem_bypass() needs to read /sys/kernel/debug/zswap/stored_pages via get_zswap_stored_pages() to verify that compressed pages are charged to the memcg.

When running in an environment where debugfs is not mounted or CONFIG_DEBUG_FS is disabled, get_zswap_stored_pages() fails, causing the loop to terminate early and report a false negative (KSFT_FAIL).

Selftests should not fail when if debugfs is unavailable, and it should print a message when it is skipped.

---
 tools/testing/selftests/cgroup/test_zswap.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
tools/testing/selftests/cgroup/test_zswap.c +8 -2
index 49b36ee791606..c4f7b66f1b206 100644
@@ -566,12 +566,19 @@ static int test_no_kmem_bypass(const char *root)
 	int child_status;
 	char *test_group = NULL;
 	pid_t child_pid;
+	size_t stored_pages;
 
 	/* Read sys info and compute test values accordingly */
 	if (sysinfo(&sys_info) != 0)
 		return KSFT_FAIL;
-	if (sys_info.totalram > 5000000000)
+	if (sys_info.totalram > 5000000000) {
+		ksft_print_msg("requires less than 5000000000 total ram\n");
 		return KSFT_SKIP;
+	}
+	if (get_zswap_stored_pages(&stored_pages)) {
+		ksft_print_msg("debugfs at /sys/kernel/debug is required\n");
+		return KSFT_SKIP;
+	}
 	values = mmap(0, sizeof(struct no_kmem_bypass_child_args), PROT_READ |
 			PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
 	if (values == MAP_FAILED)
@@ -604,7 +611,6 @@ static int test_no_kmem_bypass(const char *root)
 	/* Try to wakeup kswapd and let it push child memory to zswap */
 	set_min_free_kb(min_free_kb_high);
 	for (int i = 0; i < 20; i++) {
-		size_t stored_pages;
 		char *trigger_allocation = malloc(trigger_allocation_size);
 
 		if (!trigger_allocation)
Signature · 1 line
2.55.0.508.g3f0d502094-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Wilson Felipe Pereira

test_no_kmem_bypass() needs to read /sys/kernel/debug/zswap/stored_pages via get_zswap_stored_pages() to verify that compressed pages are charged to the memcg.

When running in an environment where debugfs is not mounted or CONFIG_DEBUG_FS is disabled, get_zswap_stored_pages() fails, causing the loop to terminate early and report a false negative (KSFT_FAIL).

Selftests should not fail when if debugfs is unavailable, and it should print a message when it is skipped.

Agreed.

Quoted 12 lines
---
 tools/testing/selftests/cgroup/test_zswap.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
tools/testing/selftests/cgroup/test_zswap.c +0 -0
index 49b36ee791606..c4f7b66f1b206 100644
@@ -566,12 +566,19 @@ static int test_no_kmem_bypass(const char *root)
 	int child_status;

tools/testing/selftests/cgroup/test_zswap.c static int test_no_kmem_bypass(const char *root) · line 575

Quoted 10 lines
tools/testing/selftests/cgroup/test_zswap.c +3 -1
 	char *test_group = NULL;
 	pid_t child_pid;
+	size_t stored_pages;
 
 	/* Read sys info and compute test values accordingly */
 	if (sysinfo(&sys_info) != 0)
 		return KSFT_FAIL;
-	if (sys_info.totalram > 5000000000)
+	if (sys_info.totalram > 5000000000) {
+		ksft_print_msg("requires less than 5000000000 total ram\n");

Agreed - should not silently just skip the test.

tools/testing/selftests/cgroup/test_zswap.c static int test_no_kmem_bypass(const char *root) · line 579

Quoted 4 lines
tools/testing/selftests/cgroup/test_zswap.c +3 -0
 		return KSFT_SKIP;
+	}
+	if (get_zswap_stored_pages(&stored_pages)) {
+		ksft_print_msg("debugfs at /sys/kernel/debug is required\n");

Could the error message here match that in gup_test.c for consistency and probably later on these could be factored out in a macro constant

ksft_print_msg("mount debugfs at /sys/kernel/debug\n");

Quoted 16 lines
tools/testing/selftests/cgroup/test_zswap.c +2 -1
+		return KSFT_SKIP;
+	}
 	values = mmap(0, sizeof(struct no_kmem_bypass_child_args), PROT_READ |
 			PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
 	if (values == MAP_FAILED)
@@ -604,7 +611,6 @@ static int test_no_kmem_bypass(const char *root)
 	/* Try to wakeup kswapd and let it push child memory to zswap */
 	set_min_free_kb(min_free_kb_high);
 	for (int i = 0; i < 20; i++) {
-		size_t stored_pages;
 		char *trigger_allocation = malloc(trigger_allocation_size);
 
 		if (!trigger_allocation)
Signature · 1 line
2.55.0.508.g3f0d502094-goog

Otherwise LGTM.

maintainer
#2 lore raw
In reply to Wilson Felipe Pereira
Quoted 10 lines · Wilson Felipe Pereira

test_no_kmem_bypass() needs to read /sys/kernel/debug/zswap/stored_pages via get_zswap_stored_pages() to verify that compressed pages are charged to the memcg.

When running in an environment where debugfs is not mounted or CONFIG_DEBUG_FS is disabled, get_zswap_stored_pages() fails, causing the loop to terminate early and report a false negative (KSFT_FAIL).

Selftests should not fail when if debugfs is unavailable, and it

Nit: I think either "when" or "if" here :)

Quoted 13 lines

should print a message when it is skipped.

---
 tools/testing/selftests/cgroup/test_zswap.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
tools/testing/selftests/cgroup/test_zswap.c +0 -0
index 49b36ee791606..c4f7b66f1b206 100644
@@ -566,12 +566,19 @@ static int test_no_kmem_bypass(const char *root)
        int child_status;

tools/testing/selftests/cgroup/test_zswap.c static int test_no_kmem_bypass(const char *root) · line 575

Quoted 10 lines
tools/testing/selftests/cgroup/test_zswap.c +3 -1
        char *test_group = NULL;
        pid_t child_pid;
+       size_t stored_pages;
 
        /* Read sys info and compute test values accordingly */
        if (sysinfo(&sys_info) != 0)
                return KSFT_FAIL;
-       if (sys_info.totalram > 5000000000)
+       if (sys_info.totalram > 5000000000) {
+               ksft_print_msg("requires less than 5000000000 total ram\n");

The message is hard to parse, we should probably write 5G instead of 5000000000, and probably change 5000000000 to the actual number for 5G, 5368709120. I would write it as (5 << 30), MB(5 * 1024), or add GB() to tools/testing/selftests/cgroup/lib/include/cgroup_util.h. It might also help to print sys_info.totalram as well (in MB or GB).

Also, the comment above the function says 4G while this checks for 5G, so maybe change this to 4G while at it (or update the comment).

tools/testing/selftests/cgroup/test_zswap.c static int test_no_kmem_bypass(const char *root) · line 579

Quoted 4 lines
tools/testing/selftests/cgroup/test_zswap.c +3 -0
                return KSFT_SKIP;
+       }
+       if (get_zswap_stored_pages(&stored_pages)) {
+               ksft_print_msg("debugfs at /sys/kernel/debug is required\n");

IIUC get_zswap_stored_pages() can fail for other reasons, at least theoretically, than debugfs not being mounted. Should we explicitly check for the existence of sys/kernel/debug/zswap/stored_pages instead?

Quoted 16 lines
tools/testing/selftests/cgroup/test_zswap.c +2 -2
+               return KSFT_SKIP;
+       }
        values = mmap(0, sizeof(struct no_kmem_bypass_child_args), PROT_READ |
                        PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
        if (values == MAP_FAILED)
@@ -604,7 +611,6 @@ static int test_no_kmem_bypass(const char *root)
        /* Try to wakeup kswapd and let it push child memory to zswap */
        set_min_free_kb(min_free_kb_high);
        for (int i = 0; i < 20; i++) {
-               size_t stored_pages;
                char *trigger_allocation = malloc(trigger_allocation_size);
 
                if (!trigger_allocation)
--

2.55.0.508.g3f0d502094-goog