[LTP] [PATCH] memcontrol03: Account for process size in cgroup allocation

Cyril Hrubis chrubis@suse.cz
Wed May 7 16:23:30 CEST 2025


Hi!
> The first trunk_G allocation has 2MB safety margin to avoid triggering
> OOM killer. However, on systems with 64K pagesize, this may not be enough.
> Account for process size as reported by cgroup memory stats before
> allocating memory in child processes.

Is there a reason to keep the 2MB safety after this patch?

Or can we do:

diff --git a/testcases/kernel/controllers/memcg/memcontrol03.c b/testcases/kernel/controllers/memcg/memcontrol03.c
index b5bbb9954..e7f126880 100644
--- a/testcases/kernel/controllers/memcg/memcontrol03.c
+++ b/testcases/kernel/controllers/memcg/memcontrol03.c
@@ -200,7 +200,7 @@ static void test_memcg_min(void)
                sleep(1);
        }

-       alloc_anon_in_child(trunk_cg[G], MB(148), 0);
+       alloc_anon_in_child(trunk_cg[G], MB(150), 0);

        SAFE_CG_SCANF(trunk_cg[B], "memory.current", "%ld", c);
        TST_EXP_EXPR(values_close(c[0], MB(50), 5),

> --- a/testcases/kernel/controllers/memcg/memcontrol03.c
> +++ b/testcases/kernel/controllers/memcg/memcontrol03.c
> @@ -94,17 +94,23 @@ static void cleanup_sub_groups(void)
>  }
>  
>  static void alloc_anon_in_child(const struct tst_cg_group *const cg,
> -				const size_t size, const int expect_oom)
> +	size_t size, const int expect_oom)
>  {
>  	int status;
>  	const pid_t pid = SAFE_FORK();
> +	size_t cgmem;
>  
>  	if (!pid) {
>  		SAFE_CG_PRINTF(cg, "cgroup.procs", "%d", getpid());
> +		SAFE_CG_SCANF(cg, "memory.current", "%zu", &cgmem);
> +		size = size > cgmem ? size - cgmem : 0;

Here we depend on the fact that process memory has been properly
accounted for when it starts running its code. Are you sure that we can
rely on this or does this just happen to work?

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list