From: Li Wang <li.wang@linux.dev>
To: Yu Miao <yumiao@kylinos.cn>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH] memcg_lib.sh: poll for expected values in check_mem_stat()
Date: Fri, 20 Nov 2026 16:56:34 +0800 [thread overview]
Message-ID: <awALQmqJEzv_pCXv@linux.dev> (raw)
In-Reply-To: <20261116013147.69993-1-yumiao@kylinos.cn>
> Reading memory.stat does not always return up-to-date values: the
> kernel only flushes the pending stats updates synchronously when they
> exceed a threshold (MEMCG_CHARGE_BATCH * num_online_cpus()), otherwise
> the updates are applied by the periodic async flusher, so the values
> can be stale for up to 2 seconds.
>
> The tests only touch 65 pages (260KiB), which may generate fewer
> stat updates than the threshold on machines with multiple CPUs, so
> the checks right after the memory has been touched may read stale
> values and fail, e.g. on 7.3.0 with 4 CPUs:
>
> memcg_stat_rss 1 TFAIL: rss is 0, 266240 expected
>
> Poll for the expected value with a 3s timeout instead, which follows
> the polling pattern already used by signal_memcg_process() in this
> file.
Patch merged, with some minor polishing:
--- a/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
+++ b/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
@@ -160,15 +160,17 @@ shmmax_cleanup()
check_mem_stat()
{
local item_size
- local cms_iter
+ local loops=30
- for cms_iter in $(seq 30); do
+ while [ $loops -gt 0 ]; do
if [ -e $1 ]; then
item_size=$(cat $1)
else
item_size=$(grep -w $1 memory.stat | cut -d " " -f 2)
fi
+ [ -z "$item_size" ] && break
+
if [ "$3" ]; then
if [ $item_size -ge $2 ] && [ $item_size -le $3 ]; then
tst_res TPASS "$1 is ${2}-${3} as expected"
@@ -179,7 +181,8 @@ check_mem_stat()
return
fi
- tst_sleep 100ms
+ loops=$((loops - 1))
+ [ $loops -gt 0 ] && tst_sleep 100ms
done
if [ "$3" ]; then
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
prev parent reply other threads:[~2026-11-20 8:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 1:31 [LTP] [PATCH] memcg_lib.sh: poll for expected values in check_mem_stat() Yu Miao
2026-11-16 3:10 ` [LTP] " linuxtestproject.agent
2026-11-20 8:56 ` Li Wang [this message]
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=awALQmqJEzv_pCXv@linux.dev \
--to=li.wang@linux.dev \
--cc=ltp@lists.linux.it \
--cc=yumiao@kylinos.cn \
/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.