Skip to content

Commit d1c41b5

Browse files
yosrym93kelsey-steele
authored andcommitted
selftests: cgroup: fix alloc_anon_noexit() instantly freeing memory
Currently, alloc_anon_noexit() calls alloc_anon() which instantly frees the allocated memory. alloc_anon_noexit() is usually used with cg_run_nowait() to run a process in the background that allocates memory. It makes sense for the background process to keep the memory allocated and not instantly free it (otherwise there is no point of running it in the background). Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Yosry Ahmed <[email protected]> Acked-by: Roman Gushchin <[email protected]> Acked-by: Shakeel Butt <[email protected]> Acked-by: David Rientjes <[email protected]> Cc: Chen Wandun <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Greg Thelen <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Michal Hocko <[email protected]> Cc: "Michal Koutn" <[email protected]> Cc: Shuah Khan <[email protected]> Cc: Tejun Heo <[email protected]> Cc: Tim Chen <[email protected]> Cc: Vaibhav Jain <[email protected]> Cc: Wei Xu <[email protected]> Cc: Yu Zhao <[email protected]> Cc: Zefan Li <[email protected]> Signed-off-by: Andrew Morton <[email protected]> [kms: backport to 5.15] Signed-off-by: Kelsey Steele <[email protected]>
1 parent 49298dd commit d1c41b5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tools/testing/selftests/cgroup/test_memcontrol.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,17 @@ static int alloc_pagecache_50M_noexit(const char *cgroup, void *arg)
210210
static int alloc_anon_noexit(const char *cgroup, void *arg)
211211
{
212212
int ppid = getppid();
213+
size_t size = (unsigned long)arg;
214+
char *buf, *ptr;
213215

214-
if (alloc_anon(cgroup, arg))
215-
return -1;
216+
buf = malloc(size);
217+
for (ptr = buf; ptr < buf + size; ptr += PAGE_SIZE)
218+
*ptr = 0;
216219

217220
while (getppid() == ppid)
218221
sleep(1);
219222

223+
free(buf);
220224
return 0;
221225
}
222226

0 commit comments

Comments
 (0)