Skip to content

Commit 0c55d48

Browse files
author
Alexei Starovoitov
committed
Merge branch 'fix-test_cgroup_iter_memcg-issues-found-during-back-porting'
Hui Zhu says: ==================== Fix test_cgroup_iter_memcg issues found during back-porting While back-porting "mm: bpf kfuncs to access memcg data", I encountered issues with test_cgroup_iter_memcg, specifically in test_kmem. The test_cgroup_iter_memcg test would falsely pass when bpf_mem_cgroup_page_state() failed due to incompatible enum values across kernel versions. Additionally, test_kmem would fail on systems with cgroup.memory=nokmem enabled. These patches are my fixes for the problems I encountered. Changelog: v5: According to the comments of Emil Tsalapatis and JP Kobryn, dropped "selftests/bpf: Check bpf_mem_cgroup_page_state return value". v4: Fixed wrong git commit log in "bpf: Use bpf_core_enum_value for stats in cgroup_iter_memcg". v3: According to the comments of JP Kobryn, remove kmem subtest from cgroup_iter_memcg and fix assertion string in test_pgfault. v2: According to the comments of JP Kobryn, added bpf_core_enum_value() usage in the BPF program to handle cross-kernel enum value differences at load-time instead of compile-time. Dropped the mm/memcontrol.c patch. Modified test_kmem handling: instead of skipping when nokmem is set, verify that kmem value is zero as expected. According to the comments of bot, fixed assertion message: changed "bpf_mem_cgroup_page_state" to "bpf_mem_cgroup_vm_events" for PGFAULT check. ==================== Link: https://patch.msgid.link/cover.1772505399.git.zhuhui@kylinos.cn Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2 parents 437350d + da99028 commit 0c55d48

File tree

3 files changed

+12
-36
lines changed

3 files changed

+12
-36
lines changed

tools/testing/selftests/bpf/cgroup_iter_memcg.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ struct memcg_query {
99
unsigned long nr_shmem;
1010
unsigned long nr_file_pages;
1111
unsigned long nr_file_mapped;
12-
/* some memcg_stat_item */
13-
unsigned long memcg_kmem;
1412
/* some vm_event_item */
1513
unsigned long pgfault;
1614
};

tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -126,32 +126,6 @@ static void test_shmem(struct bpf_link *link, struct memcg_query *memcg_query)
126126
shm_unlink("/tmp_shmem");
127127
}
128128

129-
#define NR_PIPES 64
130-
static void test_kmem(struct bpf_link *link, struct memcg_query *memcg_query)
131-
{
132-
int fds[NR_PIPES][2], i;
133-
134-
/*
135-
* Increase kmem value by creating pipes which will allocate some
136-
* kernel buffers.
137-
*/
138-
for (i = 0; i < NR_PIPES; i++) {
139-
if (!ASSERT_OK(pipe(fds[i]), "pipe"))
140-
goto cleanup;
141-
}
142-
143-
if (!ASSERT_OK(read_stats(link), "read stats"))
144-
goto cleanup;
145-
146-
ASSERT_GT(memcg_query->memcg_kmem, 0, "kmem value");
147-
148-
cleanup:
149-
for (i = i - 1; i >= 0; i--) {
150-
close(fds[i][0]);
151-
close(fds[i][1]);
152-
}
153-
}
154-
155129
static void test_pgfault(struct bpf_link *link, struct memcg_query *memcg_query)
156130
{
157131
void *map;
@@ -209,8 +183,6 @@ void test_cgroup_iter_memcg(void)
209183
test_shmem(link, &skel->data_query->memcg_query);
210184
if (test__start_subtest("cgroup_iter_memcg__file"))
211185
test_file(link, &skel->data_query->memcg_query);
212-
if (test__start_subtest("cgroup_iter_memcg__kmem"))
213-
test_kmem(link, &skel->data_query->memcg_query);
214186
if (test__start_subtest("cgroup_iter_memcg__pgfault"))
215187
test_pgfault(link, &skel->data_query->memcg_query);
216188

tools/testing/selftests/bpf/progs/cgroup_iter_memcg.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,18 @@ int cgroup_memcg_query(struct bpf_iter__cgroup *ctx)
2626

2727
bpf_mem_cgroup_flush_stats(memcg);
2828

29-
memcg_query.nr_anon_mapped = bpf_mem_cgroup_page_state(memcg, NR_ANON_MAPPED);
30-
memcg_query.nr_shmem = bpf_mem_cgroup_page_state(memcg, NR_SHMEM);
31-
memcg_query.nr_file_pages = bpf_mem_cgroup_page_state(memcg, NR_FILE_PAGES);
32-
memcg_query.nr_file_mapped = bpf_mem_cgroup_page_state(memcg, NR_FILE_MAPPED);
33-
memcg_query.memcg_kmem = bpf_mem_cgroup_page_state(memcg, MEMCG_KMEM);
34-
memcg_query.pgfault = bpf_mem_cgroup_vm_events(memcg, PGFAULT);
29+
memcg_query.nr_anon_mapped = bpf_mem_cgroup_page_state(
30+
memcg,
31+
bpf_core_enum_value(enum node_stat_item, NR_ANON_MAPPED));
32+
memcg_query.nr_shmem = bpf_mem_cgroup_page_state(
33+
memcg, bpf_core_enum_value(enum node_stat_item, NR_SHMEM));
34+
memcg_query.nr_file_pages = bpf_mem_cgroup_page_state(
35+
memcg, bpf_core_enum_value(enum node_stat_item, NR_FILE_PAGES));
36+
memcg_query.nr_file_mapped = bpf_mem_cgroup_page_state(
37+
memcg,
38+
bpf_core_enum_value(enum node_stat_item, NR_FILE_MAPPED));
39+
memcg_query.pgfault = bpf_mem_cgroup_vm_events(
40+
memcg, bpf_core_enum_value(enum vm_event_item, PGFAULT));
3541

3642
bpf_put_mem_cgroup(memcg);
3743

0 commit comments

Comments
 (0)