getrusage03: account for percpu RSS counter batching
PATCH v3 1/1 getrusage03: account for percpu RSS counter batching
After f1a7941243c1 ("mm: convert mm's rss stats into percpu_counter"), the fixed 20 MiB tolerance can be too small on large systems. Pinning limits pending RSS updates to one CPU, but that CPU can still hold one batch outside the fast RSS read.
Pin the test to its current CPU and allow one batch of lower-side slack for the 100, 300 and 400 MiB allocation checks. Keep the existing upper and inheritance tolerances, and skip if one batch is at least 100 MiB.
On 352 CPUs with 64 KiB pages, one batch is 44 MiB. Pinning alone reported 270336 KiB for the 300 MiB check, outside the 20 MiB tolerance. The updated test passed 10/10 runs on the 352-CPU Vera system.
---
Changes in v3:
- Use tst_ncpus() and pin to the current CPU (Cyril).
- Allocate the CPU mask dynamically and log the allowance.
v2: https://lore.kernel.org/ltp/[email protected]/
.../kernel/syscalls/getrusage/getrusage03.c | 87 +++++++++++++++---- 1 file changed, 71 insertions(+), 16 deletions(-)
testcases/kernel/syscalls/getrusage/getrusage03.c +71 -16
@@ -13,22 +13,88 @@* this program. */ -#include <stdlib.h> +#define _GNU_SOURCE#include <stdio.h> +#include <stdlib.h> #include "tst_test.h" +#include "lapi/cpuset.h" +#include "lapi/sched.h" #include "getrusage03.h" #define TESTBIN "getrusage03_child"static struct rusage ru;static long maxrss_init; +static long lower_allowance;static const char *const resource[] = {TESTBIN ,NULL , }; +/* +* Pin the test to the CPU it runs on. Every forked or exec'd child inherits +* the affinity, so only that CPU can hold RSS counter updates outside the +* fast percpu_counter read. +*/ +static void pin_to_current_cpu (void ) +{ +unsigned int cpu; +cpu_set_t *set; +size_t size; + +if (getcpu (&cpu,NULL )) +tst_brk (TBROK |TERRNO ,"getcpu() failed" ); + + set =CPU_ALLOC (cpu +1 ); +if (!set) +tst_brk (TBROK |TERRNO ,"CPU_ALLOC() failed" ); + + size =CPU_ALLOC_SIZE (cpu +1 ); +CPU_ZERO_S (size, set); +CPU_SET_S (cpu, size, set); +if (sched_setaffinity (0 , size, set)) +tst_brk (TBROK |TERRNO ,"sched_setaffinity() failed" ); + +CPU_FREE (set); +tst_res (TINFO ,"Pinned to CPU %u" , cpu); +} + +/* +* The pinned CPU can still hold up to one percpu_counter batch, +* max(32, 2 * online CPUs) pages, outside the fast RSS read. Count CPUs +* before pinning because some libc implementations count only the affinity +* mask. +*/ +static void setup (void ) +{ +long online_cpus =tst_ncpus (); +long batch =MAX (32L , online_cpus *2 ); +long page_size =SAFE_SYSCONF (_SC_PAGESIZE); +long batch_kib = batch * page_size /1024 ; + + lower_allowance =MAX (20 *1024L , batch_kib); +if (lower_allowance >=102400L ) +tst_brk (TCONF ,"Per-CPU RSS allowance is too large: %li KiB" , + lower_allowance); + +tst_res (TINFO ,"%li online CPUs, lower RSS allowance %li KiB" , + online_cpus, lower_allowance); + +pin_to_current_cpu (); +} + +static void check_maxrss (long actual,long expected,const char *name, +const char *size) +{ +if (actual >= expected - lower_allowance && + actual <= expected +DELTA_MAX ) +tst_res (TPASS ,"%s ~= %s" , name, size); +else +tst_res (TFAIL ,"%s = %li, expected %li" , name, actual, expected); +} +static void inherit_fork1 (void ) {SAFE_GETRUSAGE (RUSAGE_SELF , &ru);
@@ -51,11 +117,7 @@ static void inherit_fork2(void) {SAFE_GETRUSAGE (RUSAGE_CHILDREN , &ru); -if (is_in_delta (ru.ru_maxrss -102400 )) -tst_res (TPASS ,"initial.children ~= 100MB" ); -else -tst_res (TFAIL ,"initial.children = %li, expected %i" , - ru.ru_maxrss,102400 ); +check_maxrss (ru.ru_maxrss,102400 ,"initial.children" ,"100MB" );if (!SAFE_FORK ()) {SAFE_GETRUSAGE (RUSAGE_CHILDREN , &ru);
@@ -78,11 +140,7 @@ static void grandchild_maxrss(void)tst_reap_children ();SAFE_GETRUSAGE (RUSAGE_CHILDREN , &ru); -if (is_in_delta (ru.ru_maxrss -307200 )) -tst_res (TPASS ,"child.children ~= 300MB" ); -else -tst_res (TFAIL ,"child.children = %li, expected %i" , - ru.ru_maxrss,307200 ); +check_maxrss (ru.ru_maxrss,307200 ,"child.children" ,"300MB" ); }static void zombie (void )
@@ -106,11 +164,7 @@ static void zombie(void)tst_reap_children ();SAFE_GETRUSAGE (RUSAGE_CHILDREN , &ru); -if (is_in_delta (ru.ru_maxrss -409600 )) -tst_res (TPASS ,"post_wait.children ~= 400MB" ); -else -tst_res (TFAIL ,"post_wait.children = %li, expected %i" , - ru.ru_maxrss,409600 ); +check_maxrss (ru.ru_maxrss,409600 ,"post_wait.children" ,"400MB" ); }static void sig_ign (void )
@@ -174,6 +228,7 @@ static void run(unsigned int i)static struct tst_test test = { .forks_child =1 , .child_needs_reinit =1 , + .setup = setup, .resource_files = resource, .min_mem_avail =512 , .tags = (const struct tst_tag []) {
base-commit: dca9f0d272b2923256852fc37abd222b533d91e0
Signature · 4 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Nirmoy,
Quoted 4 lines · Nirmoy Das
getrusage03: account for percpu RSS counter batching
long online_cpus = tst_ncpus(); long batch = MAX(32L, online_cpus * 2);
Medium: On musl, tst_ncpus() counts the calling thread's affinity mask, so an inherited taskset/cpuset restriction still underestimates the kernel's global batch even before pinning. With 352 online CPUs, 64 KiB pages and single-CPU inherited affinity, this chooses 20 MiB rather than 44 MiB and rejects a valid 270336 KiB result for the 300 MiB allocation. Obtain the system-wide online count independently of affinity, for example by counting the CPU ranges in /sys/devices/system/cpu/online.
Verdict - Needs revision
---
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
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp