Skip to content

Commit

Permalink
selftests: cgroup: fix unexpected failure on test_memcg_sock
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Haifeng Xu authored and Andrew Morton committed Jun 23, 2023
1 parent 91f0dcc commit 3360cd3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tools/testing/selftests/cgroup/test_memcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,9 @@ static int tcp_client(const char *cgroup, unsigned short port)
char servport[6];
int retries = 0x10; /* nice round number */
int sk, ret;
long allocated;

allocated = cg_read_long(cgroup, "memory.current");
snprintf(servport, sizeof(servport), "%hd", port);
ret = getaddrinfo(server, servport, NULL, &ai);
if (ret)
Expand Down Expand Up @@ -1017,7 +1019,8 @@ static int tcp_client(const char *cgroup, unsigned short port)
if (current < 0 || sock < 0)
goto close_sk;

if (values_close(current, sock, 10)) {
/* exclude the memory not related to socket connection */
if (values_close(current - allocated, sock, 10)) {
ret = KSFT_PASS;
break;
}
Expand Down

0 comments on commit 3360cd3

Please sign in to comment.