From: Wei Gao via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v5] min_free_kbytes: Handle transient memory drops in check_monitor
Date: Wed, 29 Jul 2026 05:37:51 +0000 [thread overview]
Message-ID: <20260729053803.9823-1-wegao@suse.com> (raw)
In-Reply-To: <20260602010137.27226-1-wegao@suse.com>
High memory pressure can cause MemFree to temporarily drop below the
min_free_kbytes threshold before the kernel reclaimer can catch up.
This results in intermittent test failures, observed on openQA aarch64
virtual machines.
Implement a 2-second grace period with high-accuracy 10ms fixed polling
in check_monitor() to allow the kernel time to reclaim memory.
Introduce a 10% tolerance (90% threshold) for the MemFree check.
Measurements under extreme pressure show MemFree can dip as low as
~50% to ~70% of the target. While it typically recovers above 90%
within one second, hitting the exact 100% watermark sometimes can take
significantly longer. This tolerance prevents false positives during the
slow recovery tail while still ensuring memory is maintained near the
required level.
Also, increase the monitor's idle polling frequency from 2s to 100ms
to improve responsiveness during the test run.
Enhanced diagnostics are added to report the minimum memory level seen
during the pressure period to aid in future calibration.
Signed-off-by: Wei Gao <wegao@suse.com>
---
v4->v5:
- Formatted output messages and commit messages
- Rebase
.../kernel/mem/tunable/min_free_kbytes.c | 45 +++++++++++++++----
1 file changed, 37 insertions(+), 8 deletions(-)
diff --git a/testcases/kernel/mem/tunable/min_free_kbytes.c b/testcases/kernel/mem/tunable/min_free_kbytes.c
index 4f991025a..2b4c69b95 100644
--- a/testcases/kernel/mem/tunable/min_free_kbytes.c
+++ b/testcases/kernel/mem/tunable/min_free_kbytes.c
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
- * Copyright (c) Linux Test Project, 2012-2025
+ * Copyright (c) Linux Test Project, 2012-2026
* Copyright (C) 2012-2017 Red Hat, Inc.
*/
@@ -169,21 +169,50 @@ static int eatup_mem(unsigned long overcommit_policy)
static void check_monitor(void)
{
int violated = 0;
- unsigned long tune;
- unsigned long memfree;
+ unsigned long tune, threshold;
+ unsigned long memfree, min_memfree;
+ int i;
while (!end) {
memfree = SAFE_READ_MEMINFO("MemFree:");
tune = TST_SYS_CONF_LONG_GET(PATH_VM_MIN_FREE_KBYTES);
+ /*
+ * Allow 10% tolerance to account for transient states.
+ */
+ threshold = tune * 9 / 10;
if (memfree < tune) {
- tst_res(TINFO, "MemFree is %lu kB, "
- "min_free_kbytes is %lu kB", memfree, tune);
- tst_res(TFAIL, "MemFree < min_free_kbytes");
- violated = 1;
+ min_memfree = memfree;
+ /*
+ * Give it some time to reclaim. The kernel should keep
+ * MemFree above min_free_kbytes, but transient drops
+ * are possible under high pressure.
+ * Check every 10ms for up to 2 seconds for high accuracy.
+ */
+ for (i = 10; i <= 2000; i += 10) {
+ usleep(10000);
+ memfree = SAFE_READ_MEMINFO("MemFree:");
+ if (memfree < min_memfree)
+ min_memfree = memfree;
+
+ if (memfree >= tune)
+ break;
+ }
+
+ if (memfree < threshold) {
+ tst_res(TFAIL, "MemFree %lu kB < 90%% of min_free_kbytes %lu kB (MinSeen: %lu%%) after 2s",
+ memfree, tune, (min_memfree * 100 / tune));
+ violated = 1;
+ } else if (memfree < tune) {
+ tst_res(TINFO, "MemFree (%lu kB) stayed within 10%% tolerance (min %lu%%) after ~2s",
+ memfree, (min_memfree * 100 / tune));
+ } else {
+ tst_res(TINFO, "MemFree recovered to %lu kB (min %lu%%) after %d ms",
+ memfree, (min_memfree * 100 / tune), i);
+ }
}
- sleep(2);
+ usleep(100000);
}
if (!violated)
--
2.54.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-07-29 5:38 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-27 5:08 [LTP] [PATCH v2] mem/min_free_kbytes: Add grace period for memory reclaim Wei Gao via ltp
2026-05-27 5:31 ` [LTP] " linuxtestproject.agent
2026-05-27 15:40 ` [LTP] [PATCH v2] " Cyril Hrubis
2026-05-29 16:07 ` Petr Vorel
2026-05-31 13:51 ` Wei Gao via ltp
2026-05-31 13:40 ` [LTP] [PATCH v3] min_free_kbytes: Handle transient memory drops in check_monitor Wei Gao via ltp
2026-06-01 6:42 ` [LTP] " linuxtestproject.agent
2026-06-02 1:00 ` [LTP] [PATCH v4] " Wei Gao via ltp
2026-06-02 4:02 ` [LTP] " linuxtestproject.agent
2026-06-02 7:46 ` Wei Gao via ltp
2026-06-02 16:07 ` Andrea Cervesato via ltp
2026-06-03 3:07 ` Wei Gao via ltp
2026-07-28 12:28 ` Andrea Cervesato via ltp
2026-07-28 13:09 ` Andrea Cervesato via ltp
2026-07-29 4:52 ` Wei Gao via ltp
2026-07-29 5:37 ` Wei Gao via ltp [this message]
2026-07-29 5:52 ` linuxtestproject.agent
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=20260729053803.9823-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 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.