summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorWilson Felipe Pereira <wfelipe@google.com>2026-08-11 05:14:11 +0000
committerAndrew Morton <akpm@linux-foundation.org>2026-08-24 18:43:21 -0700
commit6f615890b84820c2e223bd14238319f0415eae88 (patch)
tree42e5f14d2de737f5fee580bffbfc66dcee2a6998 /tools
parentbd1ad3cf07d11fbf203ac362222807113321dfbb (diff)
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 if debugfs is unavailable, and it should print a message when it is skipped. While I'm here, also add a warning message if the test is being skipped due to totalram size and make the check for totalram more readable. [akpm@linux-foundation.org: clarify debugfs-unavailable error message] Link: https://lore.kernel.org/20260812050848.848882-1-wfelipe@google.com Link: https://lore.kernel.org/20260811051434.3805648-1-wfelipe@google.com Signed-off-by: Wilson Felipe Pereira <wfelipe@google.com> Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com> Reviewed-by: SJ Park <sj@kernel.org> Cc: Chengming Zhou <chengming.zhou@linux.dev> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Michal Koutný <mkoutny@suse.com> Cc: Nhat Pham <nphamcs@gmail.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Tejun Heo <tj@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/cgroup/lib/include/cgroup_util.h1
-rw-r--r--tools/testing/selftests/cgroup/test_zswap.c13
2 files changed, 12 insertions, 2 deletions
diff --git a/tools/testing/selftests/cgroup/lib/include/cgroup_util.h b/tools/testing/selftests/cgroup/lib/include/cgroup_util.h
index febc1723d090..c0f07226b222 100644
--- a/tools/testing/selftests/cgroup/lib/include/cgroup_util.h
+++ b/tools/testing/selftests/cgroup/lib/include/cgroup_util.h
@@ -7,6 +7,7 @@
#endif
#define MB(x) (x << 20)
+#define GB(x) ((unsigned long long)(x) << 30)
#define USEC_PER_SEC 1000000L
#define NSEC_PER_SEC 1000000000L
diff --git a/tools/testing/selftests/cgroup/test_zswap.c b/tools/testing/selftests/cgroup/test_zswap.c
index 49b36ee79160..f7b4c4370db6 100644
--- a/tools/testing/selftests/cgroup/test_zswap.c
+++ b/tools/testing/selftests/cgroup/test_zswap.c
@@ -20,6 +20,7 @@ static int page_size;
#define PATH_ZSWAP "/sys/module/zswap"
#define PATH_ZSWAP_ENABLED "/sys/module/zswap/parameters/enabled"
+#define PATH_ZSWAP_STORED_PAGES "/sys/kernel/debug/zswap/stored_pages"
static int read_int(const char *path, size_t *value)
{
@@ -55,7 +56,7 @@ static int read_min_free_kb(size_t *value)
static int get_zswap_stored_pages(size_t *value)
{
- return read_int("/sys/kernel/debug/zswap/stored_pages", value);
+ return read_int(PATH_ZSWAP_STORED_PAGES, value);
}
static long get_cg_wb_count(const char *cg)
@@ -570,8 +571,16 @@ static int test_no_kmem_bypass(const char *root)
/* 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 > GB(4)) {
+ ksft_print_msg(
+ "requires less than 4GB total ram, sys_info.totalram: %.1fGB\n",
+ (double)sys_info.totalram / GB(1));
return KSFT_SKIP;
+ }
+ if (access(PATH_ZSWAP_STORED_PAGES, R_OK)) {
+ ksft_print_msg("debugfs not mounted at /sys/kernel/debug\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)