All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] memcontrol03: Account for process size in cgroup allocation
@ 2025-05-05 10:53 Martin Doucha
  2025-05-06  6:59 ` Li Wang via ltp
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Martin Doucha @ 2025-05-05 10:53 UTC (permalink / raw)
  To: ltp

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.

Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
 .../kernel/controllers/memcg/memcontrol03.c   | 20 +++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/testcases/kernel/controllers/memcg/memcontrol03.c b/testcases/kernel/controllers/memcg/memcontrol03.c
index b5bbb9954..d2e489ad6 100644
--- 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;
 
 		tst_res(TINFO, "Child %d in %s: Allocating anon: %"PRIdPTR,
 		getpid(), tst_cg_group_name(cg), size);
-		alloc_anon(size);
+
+		if (size)
+			alloc_anon(size);
+
 		exit(0);
 	}
 
@@ -128,9 +134,10 @@ static void alloc_anon_in_child(const struct tst_cg_group *const cg,
 }
 
 static void alloc_pagecache_in_child(const struct tst_cg_group *const cg,
-				     const size_t size)
+	size_t size)
 {
 	const pid_t pid = SAFE_FORK();
+	size_t cgmem;
 
 	if (pid) {
 		TST_CHECKPOINT_WAIT(CHILD_IDLE);
@@ -138,10 +145,15 @@ static void alloc_pagecache_in_child(const struct tst_cg_group *const cg,
 	}
 
 	SAFE_CG_PRINTF(cg, "cgroup.procs", "%d", getpid());
+	SAFE_CG_SCANF(cg, "memory.current", "%zu", &cgmem);
+	size = size > cgmem ? size - cgmem : 0;
 
 	tst_res(TINFO, "Child %d in %s: Allocating pagecache: %"PRIdPTR,
 		getpid(), tst_cg_group_name(cg), size);
-	alloc_pagecache(fd, size);
+
+	if (size)
+		alloc_pagecache(fd, size);
+
 	SAFE_FSYNC(fd);
 
 	TST_CHECKPOINT_WAKE(CHILD_IDLE);
-- 
2.49.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2025-09-03  9:19 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-05 10:53 [LTP] [PATCH] memcontrol03: Account for process size in cgroup allocation Martin Doucha
2025-05-06  6:59 ` Li Wang via ltp
2025-05-07 14:23 ` Cyril Hrubis
2025-05-07 15:36   ` Martin Doucha
2025-05-09  9:21     ` Cyril Hrubis
2025-05-09  9:40       ` Martin Doucha
2025-05-09 10:01         ` Cyril Hrubis
2025-05-09 10:11           ` Martin Doucha
2025-05-20 15:29             ` Martin Doucha
     [not found]           ` <qbca5sxzfw53o6nku5ulu2dl2xygxqghgsuerjjjfoea62bacs@a5qm6cl7hhnu>
2025-05-09 14:41             ` Martin Doucha
2025-05-20 17:57               ` ALOK TIWARI via ltp
2025-05-26 13:52                 ` Martin Doucha
     [not found]               ` <6msduqbs42k7lnysck7oxoqyicbo6yzktstxdjan5ktpv4qzrx@s2xpicy3johi>
2025-05-28 12:04                 ` [LTP] [TEST PATCH] memcontrol: Wait for draining of remote stocks when charging Martin Doucha
2025-05-30 11:44                 ` Martin Doucha
2025-07-03  9:36                 ` Martin Doucha
2025-09-03  9:19 ` [LTP] [PATCH] memcontrol03: Account for process size in cgroup allocation Cyril Hrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.