Linux Test Project
 help / color / mirror / Atom feed
From: Wei Gao via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2] mmapstress06: Use memory.high in cgroup v2 to start swapping early
Date: Wed,  2 Sep 2026 02:57:12 +0000	[thread overview]
Message-ID: <20260902025816.3915-1-wegao@suse.com> (raw)
In-Reply-To: <20260825022926.9649-1-wegao@suse.com>

Set memory.high to slightly smaller than memory.max in cgroup v2 to
start swapping earlier. In cgroup v2, the asynchronous swap writeback
does not start until we are over the limit (memory.max). Setting
memory.high starts the reclaiming/swapping once memory.high is reached,
preventing the child process from hitting the memory.max limit and
getting killed by the OOM-killer.

Signed-off-by: Wei Gao <wegao@suse.com>
Suggested-by: Cyril Hrubis <chrubis@suse.cz>
---
v1->v2:
- Update solution base Cyril's suggestion

 lib/tst_cgroup.c                               | 1 +
 testcases/kernel/mem/mmapstress/mmapstress06.c | 7 +++++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
index 7c6ecd4d2..3ee9d32a4 100644
--- a/lib/tst_cgroup.c
+++ b/lib/tst_cgroup.c
@@ -180,6 +180,7 @@ static const struct cgroup_file memory_ctrl_files[] = {
 	{ "memory.events", NULL, CTRL_MEMORY },
 	{ "memory.low", NULL, CTRL_MEMORY },
 	{ "memory.min", NULL, CTRL_MEMORY },
+	{ "memory.high", "memory.soft_limit_in_bytes", CTRL_MEMORY },
 	{ "memory.max", "memory.limit_in_bytes", CTRL_MEMORY },
 	{ "memory.stat", "memory.stat", CTRL_MEMORY },
 	{ "memory.swappiness", "memory.swappiness", CTRL_MEMORY },
diff --git a/testcases/kernel/mem/mmapstress/mmapstress06.c b/testcases/kernel/mem/mmapstress/mmapstress06.c
index 4e6023399..7cc17fc75 100644
--- a/testcases/kernel/mem/mmapstress/mmapstress06.c
+++ b/testcases/kernel/mem/mmapstress/mmapstress06.c
@@ -37,10 +37,13 @@ static void run_test(void)
 	/* Set memory limit to force swapping of the mapping */
 	SAFE_CG_PRINTF(cg_child, "memory.max", "%lu", (unsigned long)mem_limit);
 
-	if (TST_CG_VER_IS_V1(cg_child, "memory"))
+	if (TST_CG_VER_IS_V1(cg_child, "memory")) {
 		SAFE_CG_PRINT(cg_child, "memory.swap.max", "-1");
-	else
+	} else {
 		SAFE_CG_PRINT(cg_child, "memory.swap.max", "max");
+		SAFE_CG_PRINTF(cg_child, "memory.high", "%lu",
+			       (unsigned long)(mem_limit - mem_limit / 8));
+	}
 
 	child_pid = SAFE_FORK();
 	if (!child_pid) {
-- 
2.55.0


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

  parent reply	other threads:[~2026-09-02  2:58 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-25  2:13 [LTP] [PATCH v1] mmapstress06: Rate limit page-dirtying loop to prevent MemCG OOM-kills Wei Gao via ltp
2026-08-25  3:00 ` [LTP] " linuxtestproject.agent
2026-08-25 12:16 ` [LTP] [PATCH v1] " Andrea Cervesato via ltp
2026-08-26  7:13   ` Wei Gao via ltp
2026-08-26  7:58     ` Andrea Cervesato via ltp
2026-08-26  9:31       ` Wei Gao via ltp
2026-08-26  9:49         ` Andrea Cervesato via ltp
2026-08-26 13:38           ` Wei Gao via ltp
2026-08-27  8:06             ` Andrea Cervesato via ltp
2026-08-27 14:21               ` Cyril Hrubis
2026-09-01  2:04                 ` Wei Gao via ltp
2026-09-01  7:38                   ` Andrea Cervesato via ltp
2026-09-01  8:22                     ` Wei Gao via ltp
2026-09-01  8:47                   ` Cyril Hrubis
2026-09-02  2:57 ` Wei Gao via ltp [this message]
2026-09-02  8:28   ` [LTP] mmapstress06: Use memory.high in cgroup v2 to start swapping early linuxtestproject.agent
2026-09-04  8:53   ` [LTP] [PATCH v2] " Andrea Cervesato via ltp
2026-09-04 10:23   ` Cyril Hrubis
2026-09-04 10:43   ` Andrea Cervesato via ltp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260902025816.3915-1-wegao@suse.com \
    --to=ltp@lists.linux.it \
    --cc=wegao@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox