[LTP] [RFC PATCH] getrusage03: account for percpu RSS counter batching

Nirmoy Das nirmoyd@nvidia.com
Tue Aug 25 17:25:44 CEST 2026


getrusage03 allows ru_maxrss to differ from the expected value by a
fixed 20 MiB. That can be too small on large systems after Linux commit
f1a7941243c1 ("mm: convert mm's rss stats into percpu_counter").

The fast RSS read may miss percpu counter batches, and the batch size
scales with the number of online CPUs. The test child is single threaded,
but it can migrate while faulting memory, so allow two batches worth of
slack based on the online CPU count and page size. Keep the existing
20 MiB floor for smaller systems.

This is sent as RFC because it makes the test tolerate Linux's current
percpu counter batching behavior instead of treating the smaller
ru_maxrss value as a kernel failure.

Signed-off-by: Nirmoy Das <nirmoyd@nvidia.com>
---
 .../kernel/syscalls/getrusage/getrusage03.h     | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/syscalls/getrusage/getrusage03.h b/testcases/kernel/syscalls/getrusage/getrusage03.h
index 58a98b430..9a7d8e8fa 100644
--- a/testcases/kernel/syscalls/getrusage/getrusage03.h
+++ b/testcases/kernel/syscalls/getrusage/getrusage03.h
@@ -7,9 +7,20 @@
 #define LTP_GETRUSAGE03_H
 
 #include <sched.h>
+#include "tst_cpu.h"
 #include "tst_test.h"
 
-#define DELTA_MAX 20480
+#define DELTA_MAX 20480L
+#define MAXRSS_BATCHES 2L
+
+static long maxrss_delta(void)
+{
+	long batch = MAX(32L, tst_ncpus() * 2);
+	long delta = MAXRSS_BATCHES * batch * SAFE_SYSCONF(_SC_PAGESIZE) / 1024;
+
+	/* Linux RSS counters can miss percpu counter batches after migration. */
+	return MAX(DELTA_MAX, delta);
+}
 
 static void force_context_switches(int iterations)
 {
@@ -40,7 +51,9 @@ static void consume_mb(int consume_nr)
 
 static int is_in_delta(long value)
 {
-	return (value >= -DELTA_MAX && value <= DELTA_MAX);
+	long delta = maxrss_delta();
+
+	return (value >= -delta && value <= delta);
 }
 
 #endif //LTP_GETRUSAGE03_H
-- 
2.43.0



More information about the ltp mailing list