Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/damon/core: do not overwrite wmarks.activated in damos_commit()
@ 2026-11-22  0:29 Yifan Feng
  2026-11-22  1:22 ` SJ Park
  2026-11-23  0:01 ` SJ Park
  0 siblings, 2 replies; 5+ messages in thread
From: Yifan Feng @ 2026-11-22  0:29 UTC (permalink / raw)
  To: SJ Park, Andrew Morton; +Cc: damon, linux-mm, linux-kernel, Yifan Feng, stable

damos_commit() copies the whole wmarks struct from the source scheme,
including the private 'activated' field.  The source scheme is a new
one, so the field is always true there.

As a result, a commit turns on a scheme that the watermarks turned off.
If the metric is between mid and high at that time, the scheme keeps
running, though it should stay off until the metric goes below mid.
DAMON_RECLAIM and DAMON_LRU_SORT use the same path for commit_inputs.

Save 'activated' before the copy and restore it after.  Do not restore
it for DAMOS_WMARK_NONE, because nothing sets it again in that case and
the scheme would stay off.

Fixes: 9cb3d0b9dfce ("mm/damon/core: implement DAMON context commit function")
Cc: <stable@vger.kernel.org> # 6.11.x
Signed-off-by: Yifan Feng <evanfengff@gmail.com>
---
Tested in QEMU: without the fix a commit turns the scheme on, with the fix it stays off. kunit and selftests results do not change (13 pass, 2 need drgn).
Found and written with the help of an AI coding assistant.

 mm/damon/core.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index b8678a53b0a9..9ae77e4d6e57 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -1567,6 +1567,7 @@ static struct damos *damon_nth_scheme(int n, struct damon_ctx *ctx)
 
 static int damos_commit(struct damos *dst, struct damos *src)
 {
+	bool activated = dst->wmarks.activated;
 	int err;
 
 	dst->pattern = src->pattern;
@@ -1578,6 +1579,8 @@ static int damos_commit(struct damos *dst, struct damos *src)
 		return err;
 
 	dst->wmarks = src->wmarks;
+	if (dst->wmarks.metric != DAMOS_WMARK_NONE)
+		dst->wmarks.activated = activated;
 	dst->target_nid = src->target_nid;
 
 	err = damos_commit_dests(&dst->migrate_dests, &src->migrate_dests);

base-commit: 4405c18c95d2d0f99f6c581ef0ee8591a1aa6ccd
-- 
2.39.3 (Apple Git-146)



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

* Re: [PATCH] mm/damon/core: do not overwrite wmarks.activated in damos_commit()
  2026-11-22  0:29 [PATCH] mm/damon/core: do not overwrite wmarks.activated in damos_commit() Yifan Feng
@ 2026-11-22  1:22 ` SJ Park
  2026-11-22 23:46   ` Yifan Feng
  2026-11-23  0:01 ` SJ Park
  1 sibling, 1 reply; 5+ messages in thread
From: SJ Park @ 2026-11-22  1:22 UTC (permalink / raw)
  To: Yifan Feng; +Cc: SJ Park, Andrew Morton, damon, linux-mm, linux-kernel, stable

On Sat, 21 Nov 2026 16:29:30 -0800 Yifan Feng <evanfengff@gmail.com> wrote:

> damos_commit() copies the whole wmarks struct from the source scheme,
> including the private 'activated' field.  The source scheme is a new
> one, so the field is always true there.
> 
> As a result, a commit turns on a scheme that the watermarks turned off.
> If the metric is between mid and high at that time, the scheme keeps
> running, though it should stay off until the metric goes below mid.
> DAMON_RECLAIM and DAMON_LRU_SORT use the same path for commit_inputs.
> 
> Save 'activated' before the copy and restore it after.

Thank you for finding the issue and sharing this patch.

> Do not restore
> it for DAMOS_WMARK_NONE, because nothing sets it again in that case and
> the scheme would stay off.

Is this really necessary?  If not, I'd prefer restoring it always for
simplicity.


Thanks,
SJ

[...]


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

* Re: [PATCH] mm/damon/core: do not overwrite wmarks.activated in damos_commit()
  2026-11-22  1:22 ` SJ Park
@ 2026-11-22 23:46   ` Yifan Feng
  2026-11-22 23:49     ` SJ Park
  0 siblings, 1 reply; 5+ messages in thread
From: Yifan Feng @ 2026-11-22 23:46 UTC (permalink / raw)
  To: SJ Park; +Cc: Andrew Morton, damon, linux-mm, linux-kernel, stable

On Sat, 21 Nov 2026 17:22:22 -0800 SJ Park <sj@kernel.org> wrote:

[...]
> > Do not restore
> > it for DAMOS_WMARK_NONE, because nothing sets it again in that case and
> > the scheme would stay off.
>
> Is this really necessary?  If not, I'd prefer restoring it always for
> simplicity.

Thanks for the quick review.

I think it is needed.  With DAMOS_WMARK_NONE, damos_wmark_wait_us()
returns 0 before it touches 'activated'.  So if the scheme is
deactivated when the metric is changed to none, nothing activates it
again.

I tried restoring it always.  I deactivated a scheme by the watermarks
(free memory rate above high), then set the metric to none and
committed.  After that update_schemes_tried_regions never returned on
my test kernel (it does not have the damos_walk() fix yet).  With the
check, the scheme is applied again after the commit.

Thanks,
Yifan


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

* Re: [PATCH] mm/damon/core: do not overwrite wmarks.activated in damos_commit()
  2026-11-22 23:46   ` Yifan Feng
@ 2026-11-22 23:49     ` SJ Park
  0 siblings, 0 replies; 5+ messages in thread
From: SJ Park @ 2026-11-22 23:49 UTC (permalink / raw)
  To: Yifan Feng; +Cc: SJ Park, Andrew Morton, damon, linux-mm, linux-kernel, stable

On Sun, 22 Nov 2026 15:46:32 -0800 Yifan Feng <evanfengff@gmail.com> wrote:

> On Sat, 21 Nov 2026 17:22:22 -0800 SJ Park <sj@kernel.org> wrote:
> 
> [...]
> > > Do not restore
> > > it for DAMOS_WMARK_NONE, because nothing sets it again in that case and
> > > the scheme would stay off.
> >
> > Is this really necessary?  If not, I'd prefer restoring it always for
> > simplicity.
> 
> Thanks for the quick review.
> 
> I think it is needed.  With DAMOS_WMARK_NONE, damos_wmark_wait_us()
> returns 0 before it touches 'activated'.  So if the scheme is
> deactivated when the metric is changed to none, nothing activates it
> again.

Makes sense, thank you for clarifying this.

> 
> I tried restoring it always.  I deactivated a scheme by the watermarks
> (free memory rate above high), then set the metric to none and
> committed.  After that update_schemes_tried_regions never returned on
> my test kernel (it does not have the damos_walk() fix yet).  With the
> check, the scheme is applied again after the commit.
> 
> Thanks,
> Yifan
> 


Thanks,
SJ


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

* Re: [PATCH] mm/damon/core: do not overwrite wmarks.activated in damos_commit()
  2026-11-22  0:29 [PATCH] mm/damon/core: do not overwrite wmarks.activated in damos_commit() Yifan Feng
  2026-11-22  1:22 ` SJ Park
@ 2026-11-23  0:01 ` SJ Park
  1 sibling, 0 replies; 5+ messages in thread
From: SJ Park @ 2026-11-23  0:01 UTC (permalink / raw)
  To: Yifan Feng; +Cc: SJ Park, Andrew Morton, damon, linux-mm, linux-kernel, stable

On Sat, 21 Nov 2026 16:29:30 -0800 Yifan Feng <evanfengff@gmail.com> wrote:

> damos_commit() copies the whole wmarks struct from the source scheme,
> including the private 'activated' field.  The source scheme is a new
> one, so the field is always true there.
> 
> As a result, a commit turns on a scheme that the watermarks turned off.
> If the metric is between mid and high at that time, the scheme keeps
> running, though it should stay off until the metric goes below mid.
> DAMON_RECLAIM and DAMON_LRU_SORT use the same path for commit_inputs.
> 
> Save 'activated' before the copy and restore it after.  Do not restore
> it for DAMOS_WMARK_NONE, because nothing sets it again in that case and
> the scheme would stay off.
> 
> Fixes: 9cb3d0b9dfce ("mm/damon/core: implement DAMON context commit function")
> Cc: <stable@vger.kernel.org> # 6.11.x
> Signed-off-by: Yifan Feng <evanfengff@gmail.com>

Reviewed-by: SJ Park <sj@kernel.org>

This patch is applied to damon/next [1] tree.  I will repost it soon (~1 week)
as an mm.git merge request.  So, no action from your side is needed for now.

[1] https://origin.kernel.org/doc/html/latest/mm/damon/maintainer-profile.html#scm-trees


Thanks,
SJ

[...]


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

end of thread, other threads:[~2026-11-23  0:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22  0:29 [PATCH] mm/damon/core: do not overwrite wmarks.activated in damos_commit() Yifan Feng
2026-11-22  1:22 ` SJ Park
2026-11-22 23:46   ` Yifan Feng
2026-11-22 23:49     ` SJ Park
2026-11-23  0:01 ` SJ Park

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