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 --- 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 #include #include +#include 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