]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mm/damon/core: do damos walking in entire regions granularity
authorSeongJae Park <sj@kernel.org>
Mon, 10 Feb 2025 18:27:36 +0000 (10:27 -0800)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 17 Mar 2025 05:06:10 +0000 (22:06 -0700)
damos_walk_control can be installed while DAMOS is walking the regions.
This means the walk callback function invocations can be started from a
region at the middle of the regions list.  This makes it hard to be used
reliably.  Particularly, DAMOS tried regions update for collecting
monitoring results gets problematic results.  Increase the
walk_control_lock critical section to do walking in entire regions
granularity.

Link: https://lkml.kernel.org/r/20250210182737.134994-4-sj@kernel.org
Fixes: bf0eaba0ff9c ("mm/damon/core: implement damos_walk()")
Signed-off-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/damon/core.c

index e129fb7859701a36ab400d78ab8b6a21ce96d109..f663c8e99dfa28862fa670b2fa46fe67bcc81fa8 100644 (file)
@@ -1461,11 +1461,10 @@ static void damos_walk_call_walk(struct damon_ctx *ctx, struct damon_target *t,
        if (s->walk_completed)
                return;
 
-       mutex_lock(&ctx->walk_control_lock);
        control = ctx->walk_control;
-       mutex_unlock(&ctx->walk_control_lock);
        if (!control)
                return;
+
        control->walk_fn(control->data, ctx, t, r, s, sz_filter_passed);
 }
 
@@ -1485,9 +1484,7 @@ static void damos_walk_complete(struct damon_ctx *ctx, struct damos *s)
        struct damos *siter;
        struct damos_walk_control *control;
 
-       mutex_lock(&ctx->walk_control_lock);
        control = ctx->walk_control;
-       mutex_unlock(&ctx->walk_control_lock);
        if (!control)
                return;
 
@@ -1501,9 +1498,7 @@ static void damos_walk_complete(struct damon_ctx *ctx, struct damos *s)
                siter->walk_completed = false;
 
        complete(&control->completion);
-       mutex_lock(&ctx->walk_control_lock);
        ctx->walk_control = NULL;
-       mutex_unlock(&ctx->walk_control_lock);
 }
 
 /*
@@ -1850,6 +1845,7 @@ static void kdamond_apply_schemes(struct damon_ctx *c)
        if (!has_schemes_to_apply)
                return;
 
+       mutex_lock(&c->walk_control_lock);
        damon_for_each_target(t, c) {
                damon_for_each_region_safe(r, next_r, t)
                        damon_do_apply_schemes(c, t, r);
@@ -1864,6 +1860,7 @@ static void kdamond_apply_schemes(struct damon_ctx *c)
                         c->attrs.aggr_interval) / sample_interval;
                s->last_applied = NULL;
        }
+       mutex_unlock(&c->walk_control_lock);
 }
 
 /*