Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: cgroup: fix unexpected failure on test_memcg_sock

Before server got a client connection, there were some memory allocations
in the test memcg, such as user stack. So do not count those allocations
which are not related to socket when checking socket memory accounting.

Link: https://lkml.kernel.org/r/20230619124735.2124-1-haifeng.xu@shopee.com
Signed-off-by: Haifeng Xu <haifeng.xu@shopee.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Michal Koutný <mkoutny@suse.com>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Shakeel Butt <shakeelb@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Haifeng Xu and committed by
Andrew Morton
3360cd30 91f0dcce

+4 -1
+4 -1
tools/testing/selftests/cgroup/test_memcontrol.c
··· 989 989 char servport[6]; 990 990 int retries = 0x10; /* nice round number */ 991 991 int sk, ret; 992 + long allocated; 992 993 994 + allocated = cg_read_long(cgroup, "memory.current"); 993 995 snprintf(servport, sizeof(servport), "%hd", port); 994 996 ret = getaddrinfo(server, servport, NULL, &ai); 995 997 if (ret) ··· 1019 1017 if (current < 0 || sock < 0) 1020 1018 goto close_sk; 1021 1019 1022 - if (values_close(current, sock, 10)) { 1020 + /* exclude the memory not related to socket connection */ 1021 + if (values_close(current - allocated, sock, 10)) { 1023 1022 ret = KSFT_PASS; 1024 1023 break; 1025 1024 }