mirror of
https://github.com/torvalds/linux.git
synced 2026-08-01 20:22:08 +02:00
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>
This commit is contained in:
commit
0c55d4817a
|
|
@ -9,8 +9,6 @@ struct memcg_query {
|
|||
unsigned long nr_shmem;
|
||||
unsigned long nr_file_pages;
|
||||
unsigned long nr_file_mapped;
|
||||
/* some memcg_stat_item */
|
||||
unsigned long memcg_kmem;
|
||||
/* some vm_event_item */
|
||||
unsigned long pgfault;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -126,32 +126,6 @@ static void test_shmem(struct bpf_link *link, struct memcg_query *memcg_query)
|
|||
shm_unlink("/tmp_shmem");
|
||||
}
|
||||
|
||||
#define NR_PIPES 64
|
||||
static void test_kmem(struct bpf_link *link, struct memcg_query *memcg_query)
|
||||
{
|
||||
int fds[NR_PIPES][2], i;
|
||||
|
||||
/*
|
||||
* Increase kmem value by creating pipes which will allocate some
|
||||
* kernel buffers.
|
||||
*/
|
||||
for (i = 0; i < NR_PIPES; i++) {
|
||||
if (!ASSERT_OK(pipe(fds[i]), "pipe"))
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!ASSERT_OK(read_stats(link), "read stats"))
|
||||
goto cleanup;
|
||||
|
||||
ASSERT_GT(memcg_query->memcg_kmem, 0, "kmem value");
|
||||
|
||||
cleanup:
|
||||
for (i = i - 1; i >= 0; i--) {
|
||||
close(fds[i][0]);
|
||||
close(fds[i][1]);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_pgfault(struct bpf_link *link, struct memcg_query *memcg_query)
|
||||
{
|
||||
void *map;
|
||||
|
|
@ -209,8 +183,6 @@ void test_cgroup_iter_memcg(void)
|
|||
test_shmem(link, &skel->data_query->memcg_query);
|
||||
if (test__start_subtest("cgroup_iter_memcg__file"))
|
||||
test_file(link, &skel->data_query->memcg_query);
|
||||
if (test__start_subtest("cgroup_iter_memcg__kmem"))
|
||||
test_kmem(link, &skel->data_query->memcg_query);
|
||||
if (test__start_subtest("cgroup_iter_memcg__pgfault"))
|
||||
test_pgfault(link, &skel->data_query->memcg_query);
|
||||
|
||||
|
|
|
|||
|
|
@ -26,12 +26,18 @@ int cgroup_memcg_query(struct bpf_iter__cgroup *ctx)
|
|||
|
||||
bpf_mem_cgroup_flush_stats(memcg);
|
||||
|
||||
memcg_query.nr_anon_mapped = bpf_mem_cgroup_page_state(memcg, NR_ANON_MAPPED);
|
||||
memcg_query.nr_shmem = bpf_mem_cgroup_page_state(memcg, NR_SHMEM);
|
||||
memcg_query.nr_file_pages = bpf_mem_cgroup_page_state(memcg, NR_FILE_PAGES);
|
||||
memcg_query.nr_file_mapped = bpf_mem_cgroup_page_state(memcg, NR_FILE_MAPPED);
|
||||
memcg_query.memcg_kmem = bpf_mem_cgroup_page_state(memcg, MEMCG_KMEM);
|
||||
memcg_query.pgfault = bpf_mem_cgroup_vm_events(memcg, PGFAULT);
|
||||
memcg_query.nr_anon_mapped = bpf_mem_cgroup_page_state(
|
||||
memcg,
|
||||
bpf_core_enum_value(enum node_stat_item, NR_ANON_MAPPED));
|
||||
memcg_query.nr_shmem = bpf_mem_cgroup_page_state(
|
||||
memcg, bpf_core_enum_value(enum node_stat_item, NR_SHMEM));
|
||||
memcg_query.nr_file_pages = bpf_mem_cgroup_page_state(
|
||||
memcg, bpf_core_enum_value(enum node_stat_item, NR_FILE_PAGES));
|
||||
memcg_query.nr_file_mapped = bpf_mem_cgroup_page_state(
|
||||
memcg,
|
||||
bpf_core_enum_value(enum node_stat_item, NR_FILE_MAPPED));
|
||||
memcg_query.pgfault = bpf_mem_cgroup_vm_events(
|
||||
memcg, bpf_core_enum_value(enum vm_event_item, PGFAULT));
|
||||
|
||||
bpf_put_mem_cgroup(memcg);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user