RE: [PATCH] mm/vma: predicate vma_assert_stabilised() on CONFIG_DEBUG_VM
From: Seunghyun An
Date: Tue Nov 10 2026 - 13:10:08 EST
On Tue, Nov 10, 2026, Lorenzo Stoakes (ARM) wrote:
> I'm disinclined to do something like that patch, as it's rather a hack.
I agree on this point. I used it here as a probe to measure the
cost of that read.
> Cna you give me the workload you're actually exercising here? Ideally
> something that's easy for me to run + analyse locally.
Sure. The "shared-VMA faults" numbers come from a small test that boils
down to the program below: one anonymous mapping (a single VMA), one
thread per CPU given on the command line, each thread writing one byte
per page of its own 128M slice and then MADV_DONTNEED'ing the slice, in
a loop.
On your Zen 5 I'd compare one thread per CCD (8 threads, one CPU from
each L3 domain) against 8 threads in a single CCD. perf c2c record on
the cross-CCD run should show the vm_refcnt line and the loads on it.
For pft, e.g. on the 9634 (7 cores per CCD), one CPU per CCD:
taskset -c 4,11,18,25,32,39,46,53,60,67,74,81 ./pft -a -m 48G -t 12
(shared_vma_faults takes the same CPUs as arguments). This pft revision
does not enumerate sparse CPU masks correctly, so I used this fix
(against b5cfe1b in https://github.com/gormanm/pft):
diff --git a/pft.c b/pft.c
--- a/pft.c
+++ b/pft.c
@@ -317,11 +317,11 @@ cpus_allowed_init(void)
* Populate cpus_allowed[] dense array.
*/
nr_cpus_allowed = 0;
- cpus_allowed = calloc(sizeof(int), max_cpus_allowed);
+ cpus_allowed = calloc(sizeof(int), numa_num_possible_cpus());
if (!cpus_allowed)
perrorx("Can't allocate cpus_allowed array");
- for (i=0; i < max_cpus_allowed; ++i) {
+ for (i=0; i < numa_num_possible_cpus(); ++i) {
if (cpu_allowed(i)) {
max_cpu_allowed = i;
cpus_allowed[nr_cpus_allowed++] = i;
--- shared_vma_faults.c ---
// Threads fault disjoint slices of ONE anonymous VMA concurrently.
// Thread i is pinned to the i-th CPU given and loops: write one byte per
// 4K page of its slice, then MADV_DONTNEED the slice. THP is disabled on
// the mapping, so every write to a fresh page is one 4K fault.
// Prints faults/s.
//
// Build: gcc -O2 -pthread -o shared_vma_faults shared_vma_faults.c
// Run: ./shared_vma_faults <seconds> <cpu> [<cpu> ...]
#define _GNU_SOURCE
#include <pthread.h>
#include <sched.h>
#include <stdatomic.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <time.h>
#include <unistd.h>
#define SLICE (128UL << 20) /* per-thread slice */
#define MAXT 512
static char *base;
static long pgsz;
static atomic_int go, stop;
static pthread_barrier_t ready;
static unsigned long faults[MAXT];
struct arg { int idx, cpu, nthreads; };
static void *worker(void *p)
{
struct arg *a = p;
cpu_set_t set;
char *s = base + (unsigned long)a->idx * SLICE;
/* stagger the first pass so threads do not fault and zap in lockstep */
unsigned long off = SLICE / pgsz * a->idx / a->nthreads * pgsz;
unsigned long n = 0;
int err;
CPU_ZERO(&set);
CPU_SET(a->cpu, &set);
err = pthread_setaffinity_np(pthread_self(), sizeof(set), &set);
if (err) {
fprintf(stderr, "pthread_setaffinity_np(cpu %d): %s\n",
a->cpu, strerror(err));
exit(1);
}
pthread_barrier_wait(&ready);
while (!atomic_load_explicit(&go, memory_order_acquire))
;
while (!atomic_load_explicit(&stop, memory_order_relaxed)) {
for (; off < SLICE; off += pgsz, n++)
s[off] = 1;
if (madvise(s, SLICE, MADV_DONTNEED)) {
perror("madvise(MADV_DONTNEED)");
exit(1);
}
off = 0;
}
faults[a->idx] = n; /* all faults, including the last pass */
return NULL;
}
int main(int argc, char **argv)
{
int nthreads = argc - 2, secs, err;
pthread_t th[MAXT];
struct arg args[MAXT];
struct timespec t0, t1;
unsigned long total = 0;
if (argc < 3 || nthreads > MAXT) {
fprintf(stderr, "usage: %s <seconds> <cpu> [<cpu> ...]\n",
argv[0]);
return 2;
}
secs = atoi(argv[1]);
if (secs <= 0) {
fprintf(stderr, "seconds must be > 0\n");
return 2;
}
for (int i = 0; i < nthreads; i++) {
int cpu = atoi(argv[i + 2]);
if (cpu < 0 || cpu >= CPU_SETSIZE) {
fprintf(stderr, "bad cpu %s\n", argv[i + 2]);
return 2;
}
}
pgsz = sysconf(_SC_PAGESIZE);
base = mmap(NULL, nthreads * SLICE, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (base == MAP_FAILED) {
perror("mmap");
return 1;
}
if (madvise(base, nthreads * SLICE, MADV_NOHUGEPAGE)) {
perror("madvise(MADV_NOHUGEPAGE)");
return 1;
}
pthread_barrier_init(&ready, NULL, nthreads + 1);
for (int i = 0; i < nthreads; i++) {
args[i] = (struct arg){ .idx = i, .cpu = atoi(argv[i + 2]),
.nthreads = nthreads };
err = pthread_create(&th[i], NULL, worker, &args[i]);
if (err) {
fprintf(stderr, "pthread_create: %s\n", strerror(err));
return 1;
}
}
pthread_barrier_wait(&ready); /* all workers pinned */
clock_gettime(CLOCK_MONOTONIC, &t0);
atomic_store_explicit(&go, 1, memory_order_release);
sleep(secs);
atomic_store(&stop, 1);
for (int i = 0; i < nthreads; i++)
pthread_join(th[i], NULL);
clock_gettime(CLOCK_MONOTONIC, &t1); /* includes the last pass */
for (int i = 0; i < nthreads; i++)
total += faults[i];
printf("%d threads: %.3f M faults/s\n", nthreads,
total / ((t1.tv_sec - t0.tv_sec) +
(t1.tv_nsec - t0.tv_nsec) / 1e9) / 1e6);
return 0;
}
Thanks,
Seunghyun