Re: [RFC PATCH v1.1 3/9] mm/damon/paddr: respect folio end for DAMOS_STAT

SJ Park <[email protected]> Sun, 2 Aug 2026 10:43:38 -0700
Newsgroups dev.linux.lists.damon
Message-ID <[email protected]>
On Sun, 02 Aug 2026 16:34:57 +0000 [email protected] wrote:

> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> 
> Pre-existing issues:
> - [High] This problem wasn't introduced by this patch, but the patch provides an incomplete fix for an address advancement logic bug. While it corrects the `addr += folio_size(folio)` issue in `damon_pa_stat()` to correctly align the next address to the end of the large folio, it fails to apply the exact same fix to `damon_pa_pageout()`, `damon_pa_de_activate()`, and `damon_pa_migrate()`.
> --
> 
> --- Patch [3]: [RFC PATCH v1.1 3/9] mm/damon/paddr: respect folio end for DAMOS_STAT ---
> commit 99e0c032eda9c903df8d327aa77b989129d9b193
> Author: SJ Park <[email protected]>
> 
> mm/damon/paddr: respect folio end for DAMOS_STAT
> 
> This commit fixes the address advancement in damon_pa_stat(). When a region
> starts in the middle of a large folio, it now properly aligns to the start of
> the next folio instead of simply adding the folio size and overshooting.
> 
> > diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
> > --- a/mm/damon/paddr.c
> > +++ b/mm/damon/paddr.c
> > @@ -379,7 +379,7 @@ static unsigned long damon_pa_stat(struct damon_region *r,
> >  
> >  		if (!damos_pa_filter_out(s, folio))
> >  			*sz_filter_passed += folio_size(folio) / addr_unit;
> > -		addr += folio_size(folio);
> > +		addr = PFN_PHYS(folio_pfn(folio)) + folio_size(folio);
> 
> [Severity: High]
> This isn't a bug introduced by this patch, but does the same address
> advancement logic regression still exist in other DAMON actions?
> 
> While you fixed the overshoot behavior here in damon_pa_stat(), it looks like
> damon_pa_pageout(), damon_pa_de_activate(), and damon_pa_migrate() in
> mm/damon/paddr.c might still be using the flawed logic.
> 
> For example, in damon_pa_pageout():
> 
>     put_folio:
> 		addr += folio_size(folio);
> 		folio_put(folio);
> 
> Could this cause DAMON actions to silently skip sections of valid memory
> if a region starts in the middle of a large folio?

A later patch of this series fix that.

> 
> >  		folio_put(folio);
> >  	}
> >  	s->last_applied = folio;
> 
> -- 
> Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=3
> 


Thanks,
SJ