Linux Kernel Selftest development
 help / color / mirror / Atom feed
* [PATCH] selftests/damon/access_memory: disable THP for deterministic access pattern
@ 2026-12-05 14:59 Enze Li
  2026-12-05 16:49 ` SJ Park
  0 siblings, 1 reply; 2+ messages in thread
From: Enze Li @ 2026-12-05 14:59 UTC (permalink / raw)
  To: sj, shuah; +Cc: damon, linux-mm, linux-kselftest, Enze Li

The WSS estimation selftest always reports zero with a 100% error when
the system runs with THP='always'.  The reason is that DAMON clears the
page table Accessed bits but does not flush the TLB.  If the TLB still
covers the whole workload, the CPU never walks the page table again, so
DAMON sees no accesses at all.

Commit 891d206e27dc ("selftests/damon/wss_estimation: test for up to 160
MiB working set size") tried to fix this by making the workload bigger.
That only works with base pages, though.  With THP='always', khugepage
turns the workload into 2MB pages, so even a big working set fits in
just a few TLB entries.  TLB sizes also differ a lot between CPUs, so
there is no single working set size that works everywhere.

On a 4 vCPU / 8 GB x86_64 VM, the test fails with THP='always':

    50-th percentile error 1.000000 (expect 10485760, result 0)

Setting THP to 'never' makes it pass at 20MB:

    50-th percentile error 0.001758 (expect 20971520, result 20934656)
    75-th percentile error 0.002734 (expect 20971520, result 21028864)

So make the workload itself predictable: turn off THP for access_memory
with prctl(PR_SET_THP_DISABLE).  Then it only uses base pages and DAMON
can see the accesses no matter how the system is configured.  It is a
process-wide setting, so one call before the allocations is enough.

Signed-off-by: Enze Li <lienze@kylinos.cn>
---
 tools/testing/selftests/damon/access_memory.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/testing/selftests/damon/access_memory.c b/tools/testing/selftests/damon/access_memory.c
index 567793b11107..9bdd6244b3ba 100644
--- a/tools/testing/selftests/damon/access_memory.c
+++ b/tools/testing/selftests/damon/access_memory.c
@@ -7,6 +7,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
+#include <sys/prctl.h>
 
 enum access_mode {
 	ACCESS_MODE_ONCE,
@@ -37,6 +38,11 @@ int main(int argc, char *argv[])
 	if (argc > 4 && !strcmp(argv[4], "repeat"))
 		mode = ACCESS_MODE_REPEAT;
 
+	if (prctl(PR_SET_THP_DISABLE, 1, 0, 0, 0)) {
+		printf("prctl(PR_SET_THP_DISABLE) failed.\n");
+		return -1;
+	}
+
 	regions = malloc(sizeof(*regions) * nr_regions);
 	for (i = 0; i < nr_regions; i++)
 		regions[i] = malloc(sz_region);

base-commit: d0d65ff2e433e741c23715e8359c4a248d432179
-- 
2.53.0


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

end of thread, other threads:[~2026-12-05 16:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 14:59 [PATCH] selftests/damon/access_memory: disable THP for deterministic access pattern Enze Li
2026-12-05 16:49 ` SJ Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox