All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] memcg_lib.sh: poll for expected values in check_mem_stat()
@ 2026-11-16  1:31 Yu Miao
  2026-11-16  3:10 ` [LTP] " linuxtestproject.agent
  0 siblings, 1 reply; 2+ messages in thread
From: Yu Miao @ 2026-11-16  1:31 UTC (permalink / raw)
  To: ltp

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.

Signed-off-by: Yu Miao <yumiao@kylinos.cn>
---
 .../controllers/memcg/functional/memcg_lib.sh | 33 ++++++++++++-------
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/testcases/kernel/controllers/memcg/functional/memcg_lib.sh b/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
index 5efede9..6960d72 100755
--- a/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
+++ b/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
@@ -160,21 +160,30 @@ shmmax_cleanup()
 check_mem_stat()
 {
 	local item_size
+	local cms_iter
 
-	if [ -e $1 ]; then
-		item_size=$(cat $1)
-	else
-		item_size=$(grep -w $1 memory.stat | cut -d " " -f 2)
-	fi
-
-	if [ "$3" ]; then
-		if [ $item_size -ge $2 ] && [ $item_size -le $3 ]; then
-			tst_res TPASS "$1 is ${2}-${3} as expected"
+	for cms_iter in $(seq 30); do
+		if [ -e $1 ]; then
+			item_size=$(cat $1)
 		else
-			tst_res TFAIL "$1 is $item_size, ${2}-${3} expected"
+			item_size=$(grep -w $1 memory.stat | cut -d " " -f 2)
+		fi
+
+		if [ "$3" ]; then
+			if [ $item_size -ge $2 ] && [ $item_size -le $3 ]; then
+				tst_res TPASS "$1 is ${2}-${3} as expected"
+				return
+			fi
+		elif [ "$2" = "$item_size" ]; then
+			tst_res TPASS "$1 is $2 as expected"
+			return
 		fi
-	elif [ "$2" = "$item_size" ]; then
-		tst_res TPASS "$1 is $2 as expected"
+
+		tst_sleep 100ms
+	done
+
+	if [ "$3" ]; then
+		tst_res TFAIL "$1 is $item_size, ${2}-${3} expected"
 	else
 		tst_res TFAIL "$1 is $item_size, $2 expected"
 	fi
-- 
2.43.0


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

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

* Re: [LTP] memcg_lib.sh: poll for expected values in check_mem_stat()
  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 ` linuxtestproject.agent
  0 siblings, 0 replies; 2+ messages in thread
From: linuxtestproject.agent @ 2026-11-16  3:10 UTC (permalink / raw)
  To: Yu Miao; +Cc: ltp

Hi Yu,

On Mon, Nov 16, 2026 at 09:31:47AM +0800, Yu Miao wrote:
> memcg_lib.sh: poll for expected values in check_mem_stat()

Verdict - Reviewed

---
Note:

The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

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

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

end of thread, other threads:[~2026-11-16  3:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

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.