DAMON development mailing list
 help / color / mirror / Atom feed
* [RFC PATCH mm-hotfixes-unstable] mm/damon/core: do not update stat for core filter rejecting region
@ 2026-11-27 20:39 SJ Park
  2026-11-27 20:48 ` sashiko-bot
  0 siblings, 1 reply; 3+ messages in thread
From: SJ Park @ 2026-11-27 20:39 UTC (permalink / raw)
  Cc: SJ Park, stable, Andrew Morton, damon, linux-mm

damos_apply_scheme() update stats for regions that were unable to apply
the scheme due to the quota.  Those are counted as tried and failed.  It
doesn't update stats for regions that were rejected by DAMOS core
filters.  Those are counted as not tried at all.

However, the DAMOS quota-driven failure is handled before DAMOS core
filters.  Regions that would be rejected by the core filter can, hence,
be accounted as tried and failed.  As a result, users could show
confusing stat changes.

Fix by handling core filters before quotas.

The user impact is not critical.  No crash or leak happens.  Only the
DAMOS stat could occasionally move in an unexpected way.

Fixes: ab9bda001b68 ("mm/damon/core: introduce address range type damos filter")
Cc: <stable@vger.kernel.org> # 6.6.x
closes: https://sashiko.dev/#/bug/linux-9c51890e-a25c-4534-afab-ef33f22a9557
Signed-off-by: SJ Park <sj@kernel.org>
---
 mm/damon/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index 0e6b361f97ea..e0ea93de100d 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -2785,6 +2785,8 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
 	}
 
 	if (c->ops.apply_scheme) {
+		if (damos_core_filter_out(c, t, r, s))
+			return;
 		if (damos_quota_is_set(quota) &&
 				quota->charged_sz + sz > quota->esz) {
 			sz = ALIGN_DOWN(quota->esz - quota->charged_sz,
@@ -2794,8 +2796,6 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
 			if (damon_split_region_at(t, r, sz))
 				goto update_stat;
 		}
-		if (damos_core_filter_out(c, t, r, s))
-			return;
 		sz = damon_sz_region(r);
 		ktime_get_coarse_ts64(&begin);
 		trace_damos_before_apply(cidx, sidx, tidx, r, nr_accesses,

base-commit: daba53bdc1a54c453c2f4ced54a1cd52416c3f87
-- 
2.47.3

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH mm-hotfixes-unstable] mm/damon/core: do not update stat for core filter rejecting region
  2026-11-27 20:39 [RFC PATCH mm-hotfixes-unstable] mm/damon/core: do not update stat for core filter rejecting region SJ Park
@ 2026-11-27 20:48 ` sashiko-bot
  2026-11-27 20:59   ` SJ Park
  0 siblings, 1 reply; 3+ messages in thread
From: sashiko-bot @ 2026-11-27 20:48 UTC (permalink / raw)
  To: SJ Park; +Cc: Andrew Morton, damon, linux-mm

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] mm/damon/core: stale region size in damos_apply_scheme()
  corrupts regions
--

commit 2aba0f31066065a1efc163e77a7548d189458afa
Author: SJ Park <sj@kernel.org>

mm/damon/core: do not update stat for core filter rejecting region

This commit moves the damos_core_filter_out() check in
damos_apply_scheme() ahead of the quota enforcement check so that
regions rejected by core filters are not accounted in DAMOS statistics
when the quota is full.

> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index 0e6b361f97ea6..e0ea93de100d8 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -2785,6 +2785,8 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
>  	}
>  
>  	if (c->ops.apply_scheme) {
> +		if (damos_core_filter_out(c, t, r, s))
> +			return;
>  		if (damos_quota_is_set(quota) &&
>  				quota->charged_sz + sz > quota->esz) {
>  			sz = ALIGN_DOWN(quota->esz - quota->charged_sz,
> @@ -2794,8 +2796,6 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
>  			if (damon_split_region_at(t, r, sz))
>  				goto update_stat;
>  		}
> -		if (damos_core_filter_out(c, t, r, s))
> -			return;
>  		sz = damon_sz_region(r);

[Severity: High]
Should sz be refreshed with damon_sz_region(r) right after
damos_core_filter_out() rather than after the quota check?

damos_core_filter_out() -> damos_filter_match() can split r in place and
shrink r->ar.end for a DAMOS_FILTER_TYPE_ADDR filter.  Because sz still
holds the pre-filter region size during the quota check, when the
remaining aligned quota falls between the post-filter and pre-filter
sizes, damon_split_region_at(t, r, sz) is called with sz >=
damon_sz_region(r).  That expands r->ar.end back across the filter
boundary and inserts a zero-length or inverted region (start >= end)
into t->regions_list.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127203938.94339-1-sj@kernel.org?part=1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH mm-hotfixes-unstable] mm/damon/core: do not update stat for core filter rejecting region
  2026-11-27 20:48 ` sashiko-bot
@ 2026-11-27 20:59   ` SJ Park
  0 siblings, 0 replies; 3+ messages in thread
From: SJ Park @ 2026-11-27 20:59 UTC (permalink / raw)
  To: sashiko-bot; +Cc: SJ Park, Andrew Morton, damon, linux-mm

On Fri, 27 Nov 2026 20:48:16 +0000 sashiko-bot@kernel.org wrote:

> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [High] mm/damon/core: stale region size in damos_apply_scheme()
>   corrupts regions
> --
> 
> commit 2aba0f31066065a1efc163e77a7548d189458afa
> Author: SJ Park <sj@kernel.org>
> 
> mm/damon/core: do not update stat for core filter rejecting region
> 
> This commit moves the damos_core_filter_out() check in
> damos_apply_scheme() ahead of the quota enforcement check so that
> regions rejected by core filters are not accounted in DAMOS statistics
> when the quota is full.
> 
> > diff --git a/mm/damon/core.c b/mm/damon/core.c
> > index 0e6b361f97ea6..e0ea93de100d8 100644
> > --- a/mm/damon/core.c
> > +++ b/mm/damon/core.c
> > @@ -2785,6 +2785,8 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
> >  	}
> >  
> >  	if (c->ops.apply_scheme) {
> > +		if (damos_core_filter_out(c, t, r, s))
> > +			return;
> >  		if (damos_quota_is_set(quota) &&
> >  				quota->charged_sz + sz > quota->esz) {
> >  			sz = ALIGN_DOWN(quota->esz - quota->charged_sz,
> > @@ -2794,8 +2796,6 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
> >  			if (damon_split_region_at(t, r, sz))
> >  				goto update_stat;
> >  		}
> > -		if (damos_core_filter_out(c, t, r, s))
> > -			return;
> >  		sz = damon_sz_region(r);
> 
> [Severity: High]
> Should sz be refreshed with damon_sz_region(r) right after
> damos_core_filter_out() rather than after the quota check?
> 
> damos_core_filter_out() -> damos_filter_match() can split r in place and
> shrink r->ar.end for a DAMOS_FILTER_TYPE_ADDR filter.  Because sz still
> holds the pre-filter region size during the quota check, when the
> remaining aligned quota falls between the post-filter and pre-filter
> sizes, damon_split_region_at(t, r, sz) is called with sz >=
> damon_sz_region(r).  That expands r->ar.end back across the filter
> boundary and inserts a zero-length or inverted region (start >= end)
> into t->regions_list.

Nice catch, I will fix in the next spin.

> 
> -- 
> Sashiko AI review · https://sashiko.dev/#/patchset/20261127203938.94339-1-sj@kernel.org?part=1
> 


Thanks,
SJ

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-27 20:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 20:39 [RFC PATCH mm-hotfixes-unstable] mm/damon/core: do not update stat for core filter rejecting region SJ Park
2026-11-27 20:48 ` sashiko-bot
2026-11-27 20:59   ` SJ Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox