From: Kunwu Chan <kunwu.chan@linux.dev>
To: sj@kernel.org, akpm@linux-foundation.org
Cc: damon@lists.linux.dev, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, Kunwu Chan <chentao@kylinos.cn>,
Wang Lian <lianux.mm@gmail.com>
Subject: [PATCH] mm/damon: fix stale TLB young-state handling on arm64
Date: Mon, 25 May 2026 22:48:46 +0800 [thread overview]
Message-ID: <20260525144846.604907-1-kunwu.chan@linux.dev> (raw)
From: Kunwu Chan <chentao@kylinos.cn>
damon_ptep_mkold() clears the PTE Access Flag so that a later
access will set it again and damon_folio_young() can observe it
via pte_young().
On arm64, however, ptep_test_and_clear_young() clears AF in the
page tables without invalidating the corresponding TLB entry.
Subsequent accesses can therefore continue hitting a stale TLB
entry without a page table walk. The PTE AF bit stays clear,
pte_young() reports false, and DAMON treats the region as
unaccessed.
folio_set_idle() does not help here. It updates only software
state, and accesses through a stale TLB entry do not clear the
idle flag.
As a result, nr_accesses stays low regardless of the real access
pattern. DAMOS schemes fail to match, WSS estimation reports
zero, and actions like pageout never trigger.
Fix this by switching to ptep_clear_flush_young() and
pmdp_clear_flush_young().
On arm64 these perform the required TLB invalidation after
clearing AF. The invalidation is deferred, but still sufficient
for DAMON's sampling granularity.
On x86, ptep_clear_flush_young() is equivalent to
ptep_test_and_clear_young() for base pages, so there is no
behavioral change. pmdp_clear_flush_young() additionally performs
a flush at PMD level, matching the existing x86 implementation.
On powerpc, riscv, and s390, the clear_flush variants currently
map back to test_and_clear implementations, so this patch does not
change their behavior.
Reproduced on arm64 (128 CPUs, 7.1.0-rc4):
before:
WSS estimation: 50th percentile error 100% (reported as zero)
apply_interval: schemes never tried
after:
WSS estimation: 50th percentile error 0.08%
apply_interval: passes
Co-developed-by: Wang Lian <lianux.mm@gmail.com>
Signed-off-by: Wang Lian <lianux.mm@gmail.com>
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
Tested-by: Kunwu Chan <chentao@kylinos.cn>
---
mm/damon/ops-common.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mm/damon/ops-common.c b/mm/damon/ops-common.c
index 8c6d61342..33d689c14 100644
--- a/mm/damon/ops-common.c
+++ b/mm/damon/ops-common.c
@@ -63,7 +63,7 @@ void damon_ptep_mkold(pte_t *pte, struct vm_area_struct *vma, unsigned long addr
* device aspects.
*/
if (likely(pte_present(pteval)))
- young |= ptep_test_and_clear_young(vma, addr, pte);
+ young |= ptep_clear_flush_young(vma, addr, pte);
young |= mmu_notifier_clear_young(vma->vm_mm, addr, addr + PAGE_SIZE);
if (young)
folio_set_young(folio);
@@ -90,7 +90,7 @@ void damon_pmdp_mkold(pmd_t *pmd, struct vm_area_struct *vma, unsigned long addr
return;
if (likely(pmd_present(pmdval)))
- young |= pmdp_test_and_clear_young(vma, addr, pmd);
+ young |= pmdp_clear_flush_young(vma, addr, pmd);
young |= mmu_notifier_clear_young(vma->vm_mm, addr, addr + HPAGE_PMD_SIZE);
if (young)
folio_set_young(folio);
--
2.43.0
next reply other threads:[~2026-05-25 14:50 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-25 14:48 Kunwu Chan [this message]
2026-05-25 15:34 ` [PATCH] mm/damon: fix stale TLB young-state handling on arm64 sashiko-bot
2026-05-25 17:46 ` SeongJae Park
2026-05-26 8:57 ` Kunwu Chan
2026-05-26 14:50 ` SeongJae Park
2026-05-31 12:16 ` Kunwu Chan
2026-05-31 16:24 ` SeongJae Park
2026-06-01 2:09 ` Kunwu Chan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260525144846.604907-1-kunwu.chan@linux.dev \
--to=kunwu.chan@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=chentao@kylinos.cn \
--cc=damon@lists.linux.dev \
--cc=lianux.mm@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=sj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.