mm/damon/vaddr: support {prep,apply}_probes
Subsystems (2)
SJ Park
maintainercover mm/damon/vaddr: support {prep,apply}_probes
DAMON supports data attributes monitoring. However, only the physical address space operation set (paddr) is supporting it. Add the support to the virtual address space operation set (vaddr).
Patch 1 adds prep_probes support to vaddr. Patch 2 moves probe filter handling code in paddr.c that can be reused by vaddr to ops-common.c. Patch 3 adds minimum apply_probes support to vaddr. Patch 4 extends the support for hugetlb. Patch 5 extends the support for pgidle_unset filter.
Test
====
I confirmed it can capture ~48 mb working set of masim in vaddr mode, like below.
First, start masim [1] to access ~48 mb memory at a time, in the background.
$ ./masim/masim.py run \
--config_file ./masim/configs/stairs-50mb.cfg \
--repeat 10 --quiet &Note that the config says the working set is 50mb. It is 50 million bytes, so ~48 MiB.
Start traditional access monitoring of masim's virtual address space using damo [2].
$ sudo ./damo/damo start $(pidof masim)
Confirm it can capture the ~48 MiB working set as the 4-th region on the snapshot.
$ sudo ./damo/damo report access
heatmap:
11111111334[...]3000000000000000000000000000000000000000489999997777777743333333555556[...]8
# min/max temperatures: -1,150,000,000, 80,009,499, column size: 6.963
MiB
intervals: sample 5 ms aggr 100 ms (max access hz 200)
0 addr 85.355 TiB size 55.703 MiB access 0 hz age 9.500 s
1 addr 85.355 TiB size 18.984 MiB access 0 hz age 6.700 s
2 addr 127.183 TiB size 278.516 MiB access 0 hz age 11.500 s
3 addr 127.183 TiB size 7.570 MiB access 0 hz age 900 ms
4 addr 127.183 TiB size 48.133 MiB access 190 hz age 800 ms
5 addr 127.183 TiB size 54.977 MiB access 0 hz age 1.700 s
6 addr 127.183 TiB size 55.113 MiB access 0 hz age 6.700 s
7 addr 127.183 TiB size 37.902 MiB access 0 hz age 3.900 s
8 addr 127.990 TiB size 120.000 KiB access 0 hz age 11.400 s
9 addr 127.990 TiB size 8.000 KiB access 70 hz age 0 ns
10 addr 127.990 TiB size 4.000 KiB access 0 hz age 11.200 s
memory bw estimate: 8.931 GiB per second
total size: 557.027 MiB
record DAMON intervals: sample 5 ms, aggr 100 msStop access monitoring and start probe-only mode access monitoring.
$ sudo ./damo/damo stop
$ sudo ./damo/damo start $(pidof masim) --probe_prep set_pgidle \
--probe_filter allow pgidle_unset --probe_weight 1Confirm it can also capture the ~48 MiB working set as the 11-th region on the snapshot.
$ sudo ./damo/damo report attrs
heatmap:
00000000113[...]40000000000000000000000000000000000000000000000001111114999999533333336[...]6
# min/max temperatures: -840,000,000, 330,002,000, column size: 6.961
MiB
probe prep: set_pgidle, filter: allow pgidle_unset (weight: 1)
intervals: sample 5 ms aggr 100 ms (max probe hits 20)
# size address age probe_hits
0 8.000 KiB 127.990 TiB 8.700 s 0
1 120.000 KiB 127.990 TiB 8.600 s 0
2 55.543 MiB 127.183 TiB 8.400 s 0
3 110.008 MiB 127.183 TiB 8.300 s 0
4 55.352 MiB 127.183 TiB 8.100 s 0
5 55.605 MiB 127.183 TiB 8 s 0
6 55.691 MiB 85.355 TiB 7.900 s 0
7 54.430 MiB 127.183 TiB 7.900 s 0
8 50.391 MiB 127.183 TiB 6.900 s 0
9 18.879 MiB 85.355 TiB 6 s 0
10 52.844 MiB 127.183 TiB 3.500 s 0
11 48.039 MiB 127.183 TiB 3.300 s 20
12 4.000 KiB 127.990 TiB 8.500 s 20
memory bw estimate: 0 B per second
total size: 556.910 MiB
record DAMON intervals: sample 5 ms, aggr 100 ms[1] https://github.com/sjp38/masim
[2] https://github.com/damonitor/damo
Changes from RFC
- RFC: https://lore.kernel.org/[email protected]
- Drop RFC tag.
- Rebase to latest mm-new.
SJ Park (5):
mm/damon/vaddr: support prep_probes mm/damon/paddr: move probe filter handling to ops-common mm/damon/vaddr: support apply_probe mm/damon/vaddr: extend apply_probes() for hugetlb mm/damon/vaddr: support pgidle_unset probe filter type
mm/damon/ops-common.c | 32 ++++++ mm/damon/ops-common.h | 2 + mm/damon/paddr.c | 23 +---- mm/damon/vaddr.c | 232 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 267 insertions(+), 22 deletions(-)
base-commit: 87f579da3b3b652d1bf5ca71ccfd7e267807e8ac
Signature · 1 line
2.47.3
SJ Park
maintainerPATCH 1/5 mm/damon/vaddr: support prep_probes
DAMON virtual address space operation set (vaddr) is not supporting prep_probes. Add the support.
--- mm/damon/vaddr.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
mm/damon/vaddr.c +40 -0
@@ -483,6 +483,45 @@ static unsigned int damon_va_check_accesses(struct damon_ctx *ctx)return max_nr_accesses; } +static void damon_va_prep_probe_region (struct damon_ctx *ctx, +struct mm_struct *mm,struct damon_region *r, +struct damon_probe *probe) +{ +struct damon_prep *p; + +damon_for_each_prep (p, probe) { +switch (p->action) { +case DAMON_PREP_SET_PGIDLE : +damon_va_mkold (mm, r->sampling_addr); +break ; +default : +break ; + } + } +} + +static void damon_va_prep_probes (struct damon_ctx *ctx,bool set_samples) +{ +struct damon_target *t; +struct mm_struct *mm; +struct damon_region *r; +struct damon_probe *p; + +damon_for_each_target (t, ctx) { + mm =damon_get_mm (t); +if (!mm) +continue ; +damon_for_each_region (r, t) { +if (set_samples) + r->sampling_addr =damon_rand (ctx, r->ar.start, + r->ar.end); +damon_for_each_probe (p, ctx) +damon_va_prep_probe_region (ctx, mm, r, p); + } +mmput (mm); + } +} +static bool damos_va_filter_young_match (struct damos_filter *filter,struct folio *folio,struct vm_area_struct *vma,unsigned long addr,pte_t *ptep,pmd_t *pmdp)
@@ -911,6 +950,7 @@ static int __init damon_va_initcall(void) .update = damon_va_update, .prepare_access_checks = damon_va_prepare_access_checks, .check_accesses = damon_va_check_accesses, + .prep_probes = damon_va_prep_probes, .target_valid = damon_va_target_valid, .cleanup_target = damon_va_cleanup_target, .apply_scheme = damon_va_apply_scheme,
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 1/5] mm/damon/vaddr: support prep_probes
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 4 lines
DAMON virtual address space operation set (vaddr) is not supporting
prep_probes. Add the support.Signed-off-by SJ Park <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
SJ Park
maintainerPATCH 2/5 mm/damon/paddr: move probe filter handling to ops-common
In reply to SJ ParkProbe filter matching logic for anon and memcg type filters in DAMON's physical address space operation set (paddr) can be reused by virtual address space operation set (vaddr) in future. Prepare the future by moving the code to ops-common.c
--- mm/damon/ops-common.c | 32 ++++++++++++++++++++++++++++++++ mm/damon/ops-common.h | 2 ++ mm/damon/paddr.c | 23 +---------------------- 3 files changed, 35 insertions(+), 22 deletions(-)
mm/damon/ops-common.c +32 -0
@@ -524,3 +524,35 @@ bool damos_ops_has_filter(struct damos *s)return true;return false; } + +bool damon_ops_filter_match (struct damon_filter *filter,struct folio *folio) +{ +bool matched = false; +struct mem_cgroup *memcg; + +switch (filter->type) { +case DAMON_FILTER_TYPE_ANON : +if (!folio) { + matched = false; +break ; + } + matched =folio_test_anon (folio); +break ; +case DAMON_FILTER_TYPE_MEMCG : +if (!folio) { + matched = false; +break ; + } +rcu_read_lock (); + memcg =folio_memcg_check (folio); +if (!memcg) + matched = false; +else + matched = filter->memcg_id ==mem_cgroup_id (memcg); +rcu_read_unlock (); +break ; +default : +break ; + } +return matched == filter->matching; +}
mm/damon/ops-common.h +2 -0
@@ -31,3 +31,5 @@ bool damos_folio_filter_match(struct damos_filter *filter, struct folio *folio);unsigned long damon_migrate_pages (struct list_head *folio_list,int target_nid);bool damos_ops_has_filter (struct damos *s); + +bool damon_ops_filter_match (struct damon_filter *filter,struct folio *folio);
mm/damon/paddr.c +1 -22
@@ -143,29 +143,8 @@ static bool damon_pa_filter_match(struct damon_filter *filter, struct folio *folio) {bool matched = false; -struct mem_cgroup *memcg;switch (filter->type) { -case DAMON_FILTER_TYPE_ANON : -if (!folio) { - matched = false; -break ; - } - matched =folio_test_anon (folio); -break ; -case DAMON_FILTER_TYPE_MEMCG : -if (!folio) { - matched = false; -break ; - } -rcu_read_lock (); - memcg =folio_memcg_check (folio); -if (!memcg) - matched = false; -else - matched = filter->memcg_id ==mem_cgroup_id (memcg); -rcu_read_unlock (); -break ;case DAMON_FILTER_TYPE_PGIDLE_UNSET :if (!folio) matched = false;
@@ -173,7 +152,7 @@ static bool damon_pa_filter_match(struct damon_filter *filter, matched =damon_folio_young (folio);break ;default : -break ; +return damon_ops_filter_match (filter, folio); }return matched == filter->matching; }
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 2/5] mm/damon/paddr: move probe filter handling to ops-common
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines
Probe filter matching logic for anon and memcg type filters in DAMON's physical address space operation set (paddr) can be reused by virtual address space operation set (vaddr) in future. Prepare the future by moving the code to
ops-common.cSigned-off-by SJ Park <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
SJ Park
maintainerPATCH 3/5 mm/damon/vaddr: support apply_probe
In reply to SJ ParkDAMON virtual address space operation set (vaddr) is not supporting apply_probe. Add a minimum support. Do not support hugetlb pages and PGIDLE_UNSET filter type for simplicity.
--- mm/damon/vaddr.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+)
mm/damon/vaddr.c +123 -0
@@ -522,6 +522,128 @@ static void damon_va_prep_probes(struct damon_ctx *ctx, bool set_samples) } } +static bool damon_va_filter_pass (struct folio *folio,struct damon_probe *p) +{ +struct damon_filter *f; +bool pass = true; + +damon_for_each_filter (f, p) { +if (damon_ops_filter_match (f, folio)) { + pass = f->allow; +break ; + } + pass = !f->allow; + } +return pass; +} + +struct damon_va_probe_walk_private { +struct damon_ctx *ctx; +struct damon_region *r; +}; + +static void damon_va_probe_folio (struct damon_ctx *ctx, +struct damon_region *r,struct folio *folio) +{ +struct damon_probe *probe; +int i =0 ; + +damon_for_each_probe (probe, ctx) { +if (damon_va_filter_pass (folio, probe)) + r->probe_hits[i]++; + i++; + } +} + +static int damon_va_probe_pmd_entry (pmd_t *pmd,unsigned long addr, +unsigned long next,struct mm_walk *walk) +{ +pte_t *pte; +pte_t ptent; +spinlock_t *ptl; +struct folio *folio; +struct damon_va_probe_walk_private *priv = walk->private; + +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + ptl =pmd_trans_huge_lock (pmd, walk->vma); +if (ptl) { +pmd_t pmde =pmdp_get (pmd); + +if (!pmd_present (pmde)) + goto huge_out; + folio =vm_normal_folio_pmd (walk->vma, addr, pmde); +if (!folio) + goto huge_out; +damon_va_probe_folio (priv->ctx, priv->r, folio); + +huge_out: +spin_unlock (ptl); +return 0 ; + } +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ + + pte =pte_offset_map_lock (walk->mm, pmd, addr, &ptl); +if (!pte) +return 0 ; + ptent =ptep_get (pte); +if (!pte_present (ptent)) + goto out; + folio =vm_normal_folio (walk->vma, addr, ptent); +if (!folio) + goto out; +damon_va_probe_folio (priv->ctx, priv->r, folio); + +out: +pte_unmap_unlock (pte, ptl); +return 0 ; +} + +static void __damon_va_apply_probes (struct damon_ctx *ctx, +struct mm_struct *mm,struct damon_region *r) +{ +struct damon_va_probe_walk_private arg = { + .ctx = ctx, + .r = r, + }; +struct mm_walk_ops damon_probe_walk_ops = { + .pmd_entry = damon_va_probe_pmd_entry, + .hugetlb_entry =NULL , + }; +unsigned long addr = r->sampling_addr; + +if (!mm) +return ; + +damon_va_walk_page_range (mm, addr, addr +1 , &damon_probe_walk_ops, + &arg); +} + +static unsigned int damon_va_apply_probes (struct damon_ctx *ctx, +bool set_samples,bool return_max_wsum) +{ +struct damon_target *t; +struct mm_struct *mm; +struct damon_region *r; +unsigned int max_wsum =0 ; + +damon_for_each_target (t, ctx) { + mm =damon_get_mm (t); +damon_for_each_region (r, t) { +if (set_samples) + r->sampling_addr =damon_rand (ctx, r->ar.start, + r->ar.end); +__damon_va_apply_probes (ctx, mm, r); +if (return_max_wsum) + max_wsum =max (damon_probe_hits_wsum (r, false, + ctx), max_wsum); + } +if (mm) +mmput (mm); + } + +return max_wsum; +} +static bool damos_va_filter_young_match (struct damos_filter *filter,struct folio *folio,struct vm_area_struct *vma,unsigned long addr,pte_t *ptep,pmd_t *pmdp)
@@ -951,6 +1073,7 @@ static int __init damon_va_initcall(void) .prepare_access_checks = damon_va_prepare_access_checks, .check_accesses = damon_va_check_accesses, .prep_probes = damon_va_prep_probes, + .apply_probes = damon_va_apply_probes, .target_valid = damon_va_target_valid, .cleanup_target = damon_va_cleanup_target, .apply_scheme = damon_va_apply_scheme,
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 3/5] mm/damon/vaddr: support apply_probe
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines
DAMON virtual address space operation set (vaddr) is not supporting
apply_probe. Add a minimum support. Do not support hugetlb pages andPGIDLE_UNSETfilter type for simplicity.Signed-off-by SJ Park <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
SJ Park
maintainerPATCH 4/5 mm/damon/vaddr: extend apply_probes() for hugetlb
In reply to SJ ParkDAMON virtual address space operation set(vaddr) does not support hugetlb pages in apply_probes. Extend it for hugetlb pages.
--- mm/damon/vaddr.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)
mm/damon/vaddr.c +29 -1
@@ -598,6 +598,34 @@ static int damon_va_probe_pmd_entry(pmd_t *pmd, unsigned long addr,return 0 ; } +#ifdef CONFIG_HUGETLB_PAGE +static int damon_va_probe_hugetlb_entry (pte_t *pte,unsigned long hmask, +unsigned long addr,unsigned long end,struct mm_walk *walk) +{ +struct damon_va_probe_walk_private *priv = walk->private; +struct hstate *h =hstate_vma (walk->vma); +struct folio *folio; +spinlock_t *ptl; +pte_t entry; + + ptl =huge_pte_lock (h, walk->mm, pte); + entry =huge_ptep_get (walk->mm, addr, pte); +if (!pte_present (entry)) + goto out; + + folio =pfn_folio (pte_pfn (entry)); +folio_get (folio); +damon_va_probe_folio (priv->ctx, priv->r, folio); +folio_put (folio); + +out: +spin_unlock (ptl); +return 0 ; +} +#else +#define damon_va_probe_hugetlb_entry NULL +#endif /* CONFIG_HUGETLB_PAGE */ +static void __damon_va_apply_probes (struct damon_ctx *ctx,struct mm_struct *mm,struct damon_region *r) {
@@ -607,7 +635,7 @@ static void __damon_va_apply_probes(struct damon_ctx *ctx, };struct mm_walk_ops damon_probe_walk_ops = { .pmd_entry = damon_va_probe_pmd_entry, - .hugetlb_entry =NULL , + .hugetlb_entry = damon_va_probe_hugetlb_entry, };unsigned long addr = r->sampling_addr;
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 4/5] mm/damon/vaddr: extend apply_probes() for hugetlb
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 4 lines
DAMON virtual address space operation set(vaddr) does not support hugetlb pages in
apply_probes. Extend it for hugetlb pages.Signed-off-by SJ Park <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
SJ Park
maintainerPATCH 5/5 mm/damon/vaddr: support pgidle_unset probe filter type
In reply to SJ ParkDAMON virtual address space operation set (vaddr) does not support pgidle_unset probe filter type. Add the support.
--- mm/damon/vaddr.c | 55 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 7 deletions(-)
mm/damon/vaddr.c +48 -7
@@ -522,13 +522,49 @@ static void damon_va_prep_probes(struct damon_ctx *ctx, bool set_samples) } } -static bool damon_va_filter_pass (struct folio *folio,struct damon_probe *p) +static bool damon_va_young_addr (struct folio *folio,pte_t *pte,pmd_t *pmd, +struct mm_struct *mm,unsigned long addr) +{ +bool young = false; + +if (pte) + young =pte_young (*pte); +else if (pmd) + young =pmd_young (*pmd); + young = young || !folio_test_idle (folio) || +mmu_notifier_test_young (mm, addr); +return young; +} + +static bool damon_va_filter_match (struct damon_filter *filter, +struct folio *folio,pte_t *pte,pmd_t *pmd, +struct mm_struct *mm,unsigned long addr) +{ +bool matched = false; + +switch (filter->type) { +case DAMON_FILTER_TYPE_PGIDLE_UNSET : +if (!folio) + matched = false; +else + matched =damon_va_young_addr (folio, pte, pmd, mm, + addr); +break ; +default : +return damon_ops_filter_match (filter, folio); + } +return matched == filter->matching; +} + +static bool damon_va_filter_pass (struct folio *folio,struct damon_probe *p, +pte_t *pte,pmd_t *pmd,struct mm_struct *mm, +unsigned long addr) {struct damon_filter *f;bool pass = true;damon_for_each_filter (f, p) { -if (damon_ops_filter_match (f, folio)) { +if (damon_va_filter_match (f, folio, pte, pmd, mm, addr)) { pass = f->allow;break ; }
@@ -543,13 +579,15 @@ struct damon_va_probe_walk_private { };static void damon_va_probe_folio (struct damon_ctx *ctx, -struct damon_region *r,struct folio *folio) +struct damon_region *r,struct folio *folio, +pte_t *pte,pmd_t *pmd,struct mm_struct *mm) {struct damon_probe *probe;int i =0 ;damon_for_each_probe (probe, ctx) { -if (damon_va_filter_pass (folio, probe)) +if (damon_va_filter_pass (folio, probe, pte, pmd, mm, + r->sampling_addr)) r->probe_hits[i]++; i++; }
@@ -574,7 +612,8 @@ static int damon_va_probe_pmd_entry(pmd_t *pmd, unsigned long addr, folio =vm_normal_folio_pmd (walk->vma, addr, pmde);if (!folio) goto huge_out; -damon_va_probe_folio (priv->ctx, priv->r, folio); +damon_va_probe_folio (priv->ctx, priv->r, folio,NULL , &pmde, + walk->vma->vm_mm); huge_out:spin_unlock (ptl);
@@ -591,7 +630,8 @@ static int damon_va_probe_pmd_entry(pmd_t *pmd, unsigned long addr, folio =vm_normal_folio (walk->vma, addr, ptent);if (!folio) goto out; -damon_va_probe_folio (priv->ctx, priv->r, folio); +damon_va_probe_folio (priv->ctx, priv->r, folio, &ptent,NULL , + walk->vma->vm_mm); out:pte_unmap_unlock (pte, ptl);
@@ -615,7 +655,8 @@ static int damon_va_probe_hugetlb_entry(pte_t *pte, unsigned long hmask, folio =pfn_folio (pte_pfn (entry));folio_get (folio); -damon_va_probe_folio (priv->ctx, priv->r, folio); +damon_va_probe_folio (priv->ctx, priv->r, folio, &entry,NULL , + walk->vma->vm_mm);folio_put (folio); out:
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 5/5] mm/damon/vaddr: support pgidle_unset probe filter type
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 4 lines
DAMON virtual address space operation set (vaddr) does not support
pgidle_unsetprobe filter type. Add the support.Signed-off-by SJ Park <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
SJ Park
maintainerQuoted 3 lines · On Sun, 6 Sep 2026 11:44:10 -0700 SJ Park <[email protected]> wrote:
DAMON supports data attributes monitoring. However, only the physical address space operation set (paddr) is supporting it. Add the support to the virtual address space operation set (vaddr).
Sashiko found no blocker for this series. Sashiko send its findings to damon@ mailing list [1], and I reply those if anything needs to be clarified. Please refer to those for details.
[1] https://lore.kernel.org/damon/
Thanks,
SJ
[...]