* [PATCH] selftests/damon/access_memory: disable THP for deterministic access pattern
@ 2026-12-05 14:59 Enze Li
2026-12-05 15:09 ` sashiko-bot
2026-12-05 16:49 ` SJ Park
0 siblings, 2 replies; 3+ 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] 3+ messages in thread
* Re: [PATCH] selftests/damon/access_memory: disable THP for deterministic access pattern
2026-12-05 14:59 [PATCH] selftests/damon/access_memory: disable THP for deterministic access pattern Enze Li
@ 2026-12-05 15:09 ` sashiko-bot
2026-12-05 16:49 ` SJ Park
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-12-05 15:09 UTC (permalink / raw)
To: Enze Li; +Cc: damon
> 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>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205145917.875356-1-lienze@kylinos.cn?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] selftests/damon/access_memory: disable THP for deterministic access pattern
2026-12-05 14:59 [PATCH] selftests/damon/access_memory: disable THP for deterministic access pattern Enze Li
2026-12-05 15:09 ` sashiko-bot
@ 2026-12-05 16:49 ` SJ Park
1 sibling, 0 replies; 3+ messages in thread
From: SJ Park @ 2026-12-05 16:49 UTC (permalink / raw)
To: Enze Li; +Cc: SJ Park, shuah, damon, linux-mm, linux-kselftest
Hello Enze,
On Sat, 5 Dec 2026 22:59:17 +0800 Enze Li <lienze@kylinos.cn> wrote:
> 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.
Awesome, thank you for this patch.
>
> Signed-off-by: Enze Li <lienze@kylinos.cn>
Reviewed-by: SJ Park <sj@kernel.org>
This patch is applied to damon/next [1] tree. I will repost it soon (~1 week)
as an mm.git merge request. So, no action from your side is needed for now.
[1] https://origin.kernel.org/doc/html/latest/mm/damon/maintainer-profile.html#scm-trees
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-05 16:50 UTC | newest]
Thread overview: 3+ 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 15:09 ` sashiko-bot
2026-12-05 16:49 ` SJ Park
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.