* [PATCH v3 1/3] mm/damon: move damon_hugetlb_mkold() from vaddr to ops-common
2026-09-08 13:51 [PATCH v3 0/3] mm/damon: support access monitoring of hugetlb-backed memory SJ Park
@ 2026-09-08 13:51 ` SJ Park
2026-09-08 13:51 ` [PATCH v3 2/3] mm/damon/ops-common: handle hugetlb folios in folio mkold/young rmap walkers SJ Park
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: SJ Park @ 2026-09-08 13:51 UTC (permalink / raw)
To: Andrew Morton; +Cc: Krishna Iyer, SJ Park, damon, linux-kernel, linux-mm
From: Krishna Iyer <kiyer@crusoe.ai>
damon_hugetlb_mkold() clears the accessed bit of a hugetlb-mapping huge
PTE and propagates the aging to secondary MMUs via
mmu_notifier_clear_young(), spanning the whole huge page size. It
currently lives in vaddr.c, and is thus usable only by the virtual
address space monitoring operations set.
The physical address space monitoring operations set will need the same
logic, to support access monitoring of hugetlb-backed memory. Move the
function to ops-common as-is, with no behavioral change. A follow-up
change will use it from the folio-granular rmap walkers.
Link: https://lore.kernel.org/20260902025700.17975-2-kiyer@crusoe.ai
Cc: Andrew Morton <akpm@linux-foundation.org>
Assisted-by: Claude:claude-fable-5
Signed-off-by: Krishna Iyer <kiyer@crusoe.ai>
Reviewed-by: SJ Park <sj@kernel.org>
Signed-off-by: SJ Park <sj@kernel.org>
---
mm/damon/ops-common.c | 37 +++++++++++++++++++++++++++++++++++++
mm/damon/ops-common.h | 9 +++++++++
mm/damon/vaddr.c | 34 ----------------------------------
3 files changed, 46 insertions(+), 34 deletions(-)
diff --git a/mm/damon/ops-common.c b/mm/damon/ops-common.c
index 7219c608b1952..995cc1f3b9f32 100644
--- a/mm/damon/ops-common.c
+++ b/mm/damon/ops-common.c
@@ -3,6 +3,7 @@
* Common Code for Data Access Monitoring
*/
+#include <linux/hugetlb.h>
#include <linux/migrate.h>
#include <linux/mmu_notifier.h>
#include <linux/page_idle.h>
@@ -103,6 +104,42 @@ void damon_pmdp_mkold(pmd_t *pmd, struct vm_area_struct *vma, unsigned long addr
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
}
+#ifdef CONFIG_HUGETLB_PAGE
+static bool damon_hugetlb_ptep_mkold(pte_t *pte, struct mm_struct *mm,
+ struct vm_area_struct *vma, unsigned long addr, pte_t *entry)
+{
+ unsigned long psize = huge_page_size(hstate_vma(vma));
+
+ if (!pte_young(*entry))
+ return false;
+ *entry = huge_ptep_get_and_clear(mm, addr, pte, psize);
+ *entry = pte_mkold(*entry);
+ set_huge_pte_at(mm, addr, pte, *entry, psize);
+ return true;
+}
+
+void damon_hugetlb_mkold(pte_t *pte, struct mm_struct *mm,
+ struct vm_area_struct *vma, unsigned long addr)
+{
+ bool referenced = false;
+ pte_t entry = huge_ptep_get(mm, addr, pte);
+ struct folio *folio = pfn_folio(pte_pfn(entry));
+
+ folio_get(folio);
+
+ referenced = damon_hugetlb_ptep_mkold(pte, mm, vma, addr, &entry);
+ if (mmu_notifier_clear_young(mm, addr,
+ addr + huge_page_size(hstate_vma(vma))))
+ referenced = true;
+
+ if (referenced)
+ folio_set_young(folio);
+
+ folio_set_idle(folio);
+ folio_put(folio);
+}
+#endif /* CONFIG_HUGETLB_PAGE */
+
#define DAMON_MAX_SUBSCORE (100)
#define DAMON_MAX_AGE_IN_LOG (32)
diff --git a/mm/damon/ops-common.h b/mm/damon/ops-common.h
index 38d295488fa18..f7811c9c7a024 100644
--- a/mm/damon/ops-common.h
+++ b/mm/damon/ops-common.h
@@ -9,6 +9,15 @@ struct folio *damon_get_folio(unsigned long pfn);
void damon_ptep_mkold(pte_t *pte, struct vm_area_struct *vma, unsigned long addr);
void damon_pmdp_mkold(pmd_t *pmd, struct vm_area_struct *vma, unsigned long addr);
+#ifdef CONFIG_HUGETLB_PAGE
+void damon_hugetlb_mkold(pte_t *pte, struct mm_struct *mm,
+ struct vm_area_struct *vma, unsigned long addr);
+#else
+static inline void damon_hugetlb_mkold(pte_t *pte, struct mm_struct *mm,
+ struct vm_area_struct *vma, unsigned long addr)
+{
+}
+#endif /* CONFIG_HUGETLB_PAGE */
void damon_folio_mkold(struct folio *folio);
bool damon_folio_young(struct folio *folio);
diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c
index 91a0d441c1f94..af9e1b82454cc 100644
--- a/mm/damon/vaddr.c
+++ b/mm/damon/vaddr.c
@@ -283,40 +283,6 @@ static int damon_mkold_pmd_entry(pmd_t *pmd, unsigned long addr,
}
#ifdef CONFIG_HUGETLB_PAGE
-static bool damon_hugetlb_ptep_mkold(pte_t *pte, struct mm_struct *mm,
- struct vm_area_struct *vma, unsigned long addr, pte_t *entry)
-{
- unsigned long psize = huge_page_size(hstate_vma(vma));
-
- if (!pte_young(*entry))
- return false;
- *entry = huge_ptep_get_and_clear(mm, addr, pte, psize);
- *entry = pte_mkold(*entry);
- set_huge_pte_at(mm, addr, pte, *entry, psize);
- return true;
-}
-
-static void damon_hugetlb_mkold(pte_t *pte, struct mm_struct *mm,
- struct vm_area_struct *vma, unsigned long addr)
-{
- bool referenced = false;
- pte_t entry = huge_ptep_get(mm, addr, pte);
- struct folio *folio = pfn_folio(pte_pfn(entry));
-
- folio_get(folio);
-
- referenced = damon_hugetlb_ptep_mkold(pte, mm, vma, addr, &entry);
- if (mmu_notifier_clear_young(mm, addr,
- addr + huge_page_size(hstate_vma(vma))))
- referenced = true;
-
- if (referenced)
- folio_set_young(folio);
-
- folio_set_idle(folio);
- folio_put(folio);
-}
-
static int damon_mkold_hugetlb_entry(pte_t *pte, unsigned long hmask,
unsigned long addr, unsigned long end,
struct mm_walk *walk)
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v3 2/3] mm/damon/ops-common: handle hugetlb folios in folio mkold/young rmap walkers
2026-09-08 13:51 [PATCH v3 0/3] mm/damon: support access monitoring of hugetlb-backed memory SJ Park
2026-09-08 13:51 ` [PATCH v3 1/3] mm/damon: move damon_hugetlb_mkold() from vaddr to ops-common SJ Park
@ 2026-09-08 13:51 ` SJ Park
2026-09-08 13:51 ` [PATCH v3 3/3] mm/damon/paddr: support hugetlb folios in access monitoring SJ Park
2026-09-08 14:48 ` [PATCH v3 0/3] mm/damon: support access monitoring of hugetlb-backed memory SJ Park
3 siblings, 0 replies; 5+ messages in thread
From: SJ Park @ 2026-09-08 13:51 UTC (permalink / raw)
To: Andrew Morton; +Cc: Krishna Iyer, SJ Park, damon, linux-kernel, linux-mm
From: Krishna Iyer <kiyer@crusoe.ai>
damon_folio_mkold_one() and damon_folio_young_one() assume the folios
they walk are mapped by normal PTEs or THP PMDs. When the folio is a
hugetlb folio, page_vma_mapped_walk() returns the huge PTE in pvmw.pte
with its page table lock held, but the walkers treat it as a normal
PTE: they read and age it with PAGE_SIZE-granularity helpers, which is
wrong for huge PTEs (up to PUD level), and notify secondary MMUs for
only PAGE_SIZE of the mapping.
Add hugetlb branches to both walkers. The mkold walker reuses
damon_hugetlb_mkold(), which the virtual address space operations set
has been using for hugetlb aging: it clears the young bit of the huge
PTE via set_huge_pte_at() and calls mmu_notifier_clear_young() spanning
the whole huge page size. The young walker gets an equivalent new
helper, damon_hugetlb_young(), which reads the huge PTE with
huge_ptep_get() and consults the page idle flag and
mmu_notifier_test_young() like the existing PTE branch.
Locking mirrors what page_vma_mapped_walk() provides: the huge PTE's
page table lock is held inside the walk, and for shared hugetlb
mappings (the only ones subject to huge PMD sharing), rmap_walk_file()
already holds i_mmap_rwsem, satisfying hugetlb_walk()'s locking
requirements.
This is currently dead code: both rmap walkers are only reachable
through damon_get_folio(), which rejects hugetlb folios since they are
not on the LRU lists. A following commit will let the physical address
space monitoring primitives opt in to hugetlb folios.
Link: https://lore.kernel.org/20260902025700.17975-3-kiyer@crusoe.ai
Cc: Andrew Morton <akpm@linux-foundation.org>
Assisted-by: Claude:claude-fable-5
Signed-off-by: Krishna Iyer <kiyer@crusoe.ai>
Reviewed-by: SJ Park <sj@kernel.org>
Signed-off-by: SJ Park <sj@kernel.org>
---
mm/damon/ops-common.c | 61 +++++++++++++++++++++++++++++++++----------
1 file changed, 47 insertions(+), 14 deletions(-)
diff --git a/mm/damon/ops-common.c b/mm/damon/ops-common.c
index 995cc1f3b9f32..349e1604cc1b1 100644
--- a/mm/damon/ops-common.c
+++ b/mm/damon/ops-common.c
@@ -205,10 +205,15 @@ static bool damon_folio_mkold_one(struct folio *folio,
while (page_vma_mapped_walk(&pvmw)) {
addr = pvmw.address;
- if (pvmw.pte)
- damon_ptep_mkold(pvmw.pte, vma, addr);
- else
+ if (pvmw.pte) {
+ if (folio_test_hugetlb(folio))
+ damon_hugetlb_mkold(pvmw.pte, vma->vm_mm, vma,
+ addr);
+ else
+ damon_ptep_mkold(pvmw.pte, vma, addr);
+ } else {
damon_pmdp_mkold(pvmw.pmd, vma, addr);
+ }
}
return true;
}
@@ -233,27 +238,55 @@ void damon_folio_mkold(struct folio *folio)
}
+#ifdef CONFIG_HUGETLB_PAGE
+static bool damon_hugetlb_young(pte_t *pte, struct vm_area_struct *vma,
+ unsigned long addr, struct folio *folio)
+{
+ pte_t entry = huge_ptep_get(vma->vm_mm, addr, pte);
+
+ return (pte_present(entry) && pte_young(entry)) ||
+ !folio_test_idle(folio) ||
+ mmu_notifier_test_young(vma->vm_mm, addr);
+}
+#else
+static bool damon_hugetlb_young(pte_t *pte, struct vm_area_struct *vma,
+ unsigned long addr, struct folio *folio)
+{
+ return false;
+}
+#endif /* CONFIG_HUGETLB_PAGE */
+
+static bool damon_pte_young(pte_t *pte, struct vm_area_struct *vma,
+ unsigned long addr, struct folio *folio)
+{
+ pte_t entry = ptep_get(pte);
+
+ /*
+ * PFN swap PTEs, such as device-exclusive ones, that actually map
+ * pages are "old" from a CPU perspective. The MMU notifier takes care
+ * of any device aspects.
+ */
+ return (pte_present(entry) && pte_young(entry)) ||
+ !folio_test_idle(folio) ||
+ mmu_notifier_test_young(vma->vm_mm, addr);
+}
+
static bool damon_folio_young_one(struct folio *folio,
struct vm_area_struct *vma, unsigned long addr, void *arg)
{
bool *accessed = arg;
DEFINE_FOLIO_VMA_WALK(pvmw, folio, vma, addr, 0);
- pte_t pte;
*accessed = false;
while (page_vma_mapped_walk(&pvmw)) {
addr = pvmw.address;
if (pvmw.pte) {
- pte = ptep_get(pvmw.pte);
-
- /*
- * PFN swap PTEs, such as device-exclusive ones, that
- * actually map pages are "old" from a CPU perspective.
- * The MMU notifier takes care of any device aspects.
- */
- *accessed = (pte_present(pte) && pte_young(pte)) ||
- !folio_test_idle(folio) ||
- mmu_notifier_test_young(vma->vm_mm, addr);
+ if (folio_test_hugetlb(folio))
+ *accessed = damon_hugetlb_young(pvmw.pte, vma,
+ addr, folio);
+ else
+ *accessed = damon_pte_young(pvmw.pte, vma,
+ addr, folio);
} else {
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
pmd_t pmd = pmdp_get(pvmw.pmd);
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v3 3/3] mm/damon/paddr: support hugetlb folios in access monitoring
2026-09-08 13:51 [PATCH v3 0/3] mm/damon: support access monitoring of hugetlb-backed memory SJ Park
2026-09-08 13:51 ` [PATCH v3 1/3] mm/damon: move damon_hugetlb_mkold() from vaddr to ops-common SJ Park
2026-09-08 13:51 ` [PATCH v3 2/3] mm/damon/ops-common: handle hugetlb folios in folio mkold/young rmap walkers SJ Park
@ 2026-09-08 13:51 ` SJ Park
2026-09-08 14:48 ` [PATCH v3 0/3] mm/damon: support access monitoring of hugetlb-backed memory SJ Park
3 siblings, 0 replies; 5+ messages in thread
From: SJ Park @ 2026-09-08 13:51 UTC (permalink / raw)
To: Andrew Morton; +Cc: Krishna Iyer, SJ Park, damon, linux-kernel, linux-mm
From: Krishna Iyer <kiyer@crusoe.ai>
DAMON's physical address space monitoring is blind to hugetlb-backed
memory. Every access check starts at damon_get_folio(), which rejects
folios that are not on the LRU lists. Hugetlb folios are managed
outside of the LRU by design, so every sampling attempt on
hugetlb-backed memory silently fails and the pages are reported as
never accessed.
This is a significant blind spot on virtualization hosts. Cloud
hypervisor hosts commonly back guest memory with 1 GiB hugetlbfs pages,
covering the vast majority of the machine's memory. On such hosts,
modules like DAMON_STAT observe only the host-side remainder (page
cache, daemons) and report all guest working sets as permanently
idle, defeating the purpose of host-level access monitoring. In
testing on a 1 TiB host, an hour of 4-thread random access over 842 GiB
inside a guest was statistically indistinguishable from an idle host,
while a 40x smaller host-side workload produced a quantitatively
correct response.
Add damon_get_monitor_folio(), which additionally accepts hugetlb
folios, and use it in the two paddr access monitoring primitives,
damon_pa_mkold() and damon_pa_young(). With the previous commit
teaching the folio-granular rmap walkers to age huge PTEs and to call
the mmu notifiers spanning the whole huge page, this makes guest
accesses visible through secondary MMU (e.g. KVM/EPT) young bits.
Free hugetlb pool folios have a zero refcount, so folio_try_get()
naturally keeps rejecting them.
The DAMOS action appliers (damon_pa_pageout(),
damon_pa_mark_accessed_or_deactivate(), damon_pa_migrate(),
damon_pa_stat()) keep using damon_get_folio(): reclaim, LRU
manipulation and migration cannot act on hugetlb folios, so their
behavior is unchanged.
Note that the access check granularity for hugetlb-backed memory is the
huge page size: one touched byte reports the whole (up to 1 GiB) page
as accessed. Also, DAMON now consumes secondary MMU young bits that
KVM's own aging uses; at DAMON's sampling rate (one page per region per
sampling interval) the interference is negligible.
Link: https://lore.kernel.org/20260902025700.17975-4-kiyer@crusoe.ai
Cc: Andrew Morton <akpm@linux-foundation.org>
Assisted-by: Claude:claude-fable-5
Signed-off-by: Krishna Iyer <kiyer@crusoe.ai>
Reviewed-by: SJ Park <sj@kernel.org>
Signed-off-by: SJ Park <sj@kernel.org>
---
mm/damon/ops-common.c | 25 +++++++++++++++++++++----
mm/damon/ops-common.h | 1 +
mm/damon/paddr.c | 4 ++--
3 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/mm/damon/ops-common.c b/mm/damon/ops-common.c
index 349e1604cc1b1..acf8f216c51cc 100644
--- a/mm/damon/ops-common.c
+++ b/mm/damon/ops-common.c
@@ -15,14 +15,20 @@
#include "../internal.h"
#include "ops-common.h"
+static bool damon_folio_acceptable(struct folio *folio, bool monitor)
+{
+ return folio_test_lru(folio) ||
+ (monitor && folio_test_hugetlb(folio));
+}
+
/*
- * Get an online page for a pfn if it's in the LRU list. Otherwise, returns
- * NULL.
+ * Get an online page for a pfn if it's in the LRU list, or a hugetlb folio if
+ * @monitor is set. Otherwise, returns NULL.
*
* The body of this function is stolen from the 'page_idle_get_folio()'. We
* steal rather than reuse it because the code is quite simple.
*/
-struct folio *damon_get_folio(unsigned long pfn)
+static struct folio *__damon_get_folio(unsigned long pfn, bool monitor)
{
struct page *page = pfn_to_online_page(pfn);
struct folio *folio;
@@ -33,13 +39,24 @@ struct folio *damon_get_folio(unsigned long pfn)
folio = page_folio(page);
if (!folio_try_get(folio))
return NULL;
- if (unlikely(page_folio(page) != folio) || !folio_test_lru(folio)) {
+ if (unlikely(page_folio(page) != folio) ||
+ !damon_folio_acceptable(folio, monitor)) {
folio_put(folio);
folio = NULL;
}
return folio;
}
+struct folio *damon_get_folio(unsigned long pfn)
+{
+ return __damon_get_folio(pfn, false);
+}
+
+struct folio *damon_get_monitor_folio(unsigned long pfn)
+{
+ return __damon_get_folio(pfn, true);
+}
+
void damon_ptep_mkold(pte_t *pte, struct vm_area_struct *vma, unsigned long addr)
{
pte_t pteval = ptep_get(pte);
diff --git a/mm/damon/ops-common.h b/mm/damon/ops-common.h
index f7811c9c7a024..172f0f17c4a84 100644
--- a/mm/damon/ops-common.h
+++ b/mm/damon/ops-common.h
@@ -6,6 +6,7 @@
#include <linux/damon.h>
struct folio *damon_get_folio(unsigned long pfn);
+struct folio *damon_get_monitor_folio(unsigned long pfn);
void damon_ptep_mkold(pte_t *pte, struct vm_area_struct *vma, unsigned long addr);
void damon_pmdp_mkold(pmd_t *pmd, struct vm_area_struct *vma, unsigned long addr);
diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index c1e7d7a4f40df..d2173a448d0b0 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -37,7 +37,7 @@ static unsigned long damon_pa_core_addr(
static void damon_pa_mkold(phys_addr_t paddr)
{
- struct folio *folio = damon_get_folio(PHYS_PFN(paddr));
+ struct folio *folio = damon_get_monitor_folio(PHYS_PFN(paddr));
if (!folio)
return;
@@ -67,7 +67,7 @@ static void damon_pa_prepare_access_checks(struct damon_ctx *ctx)
static bool damon_pa_young(phys_addr_t paddr)
{
- struct folio *folio = damon_get_folio(PHYS_PFN(paddr));
+ struct folio *folio = damon_get_monitor_folio(PHYS_PFN(paddr));
bool accessed;
if (!folio)
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v3 0/3] mm/damon: support access monitoring of hugetlb-backed memory
2026-09-08 13:51 [PATCH v3 0/3] mm/damon: support access monitoring of hugetlb-backed memory SJ Park
` (2 preceding siblings ...)
2026-09-08 13:51 ` [PATCH v3 3/3] mm/damon/paddr: support hugetlb folios in access monitoring SJ Park
@ 2026-09-08 14:48 ` SJ Park
3 siblings, 0 replies; 5+ messages in thread
From: SJ Park @ 2026-09-08 14:48 UTC (permalink / raw)
To: SJ Park; +Cc: Andrew Morton, damon, linux-kernel, linux-mm
This series relies on atomic hugetlb pte setup patch [1]. Without it, applying
this series on mm-new will fial with a conflict. Because of the fact, Sashiko
also failed to review this series. Sashiko reviewed the previous version of
this series and found no blocker.
[1] https://lore.kernel.org/20260907170358.100168-1-sj@kernel.org
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 5+ messages in thread