On Sun, 23 Nov 2025 10:43:26 -0800
SeongJae Park <[email protected]> wrote:

> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -2256,6 +2256,19 @@ static void damos_adjust_quota(struct damon_ctx *c, 
> struct damos *s)
>       quota->min_score = score;
>  }
>  
> +static void damos_trace_stat(struct damon_ctx *c, struct damos *s)
> +{
> +     unsigned int cidx = 0, sidx = 0;
> +     struct damos *siter;
> +
> +     damon_for_each_scheme(siter, c) {
> +             if (siter == s)
> +                     break;
> +             sidx++;
> +     }
> +     trace_damos_stat_after_apply_interval(cidx, sidx, &s->stat);
> +}
> +
>  static void kdamond_apply_schemes(struct damon_ctx *c)
>  {
>       struct damon_target *t;
> @@ -2294,6 +2307,8 @@ static void kdamond_apply_schemes(struct damon_ctx *c)
>                       (s->apply_interval_us ? s->apply_interval_us :
>                        c->attrs.aggr_interval) / sample_interval;
>               s->last_applied = NULL;
> +             if (trace_damos_stat_after_apply_interval_enabled())
> +                     damos_trace_stat(c, s);
>       }
>       mutex_unlock(&c->walk_control_lock);
>  }


I wonder if the above would look better (and still produce good assembly)
if it was:

static inline void damos_trace_stat(struct damon_ctx *c, struct damos *s)
{
        unsigned int cidx = 0, sidx = 0;
        struct damos *siter;

        if (!trace_damos_stat_after_apply_interval_enabled())
                return;

        damon_for_each_scheme(siter, c) {
                if (siter == s)
                        break;
                sidx++;
        }
        trace_damos_stat_after_apply_interval(cidx, sidx, &s->stat);
}

static void kdamond_apply_schemes(struct damon_ctx *c)
{
        struct damon_target *t;
> @@ -2294,6 +2307,8 @@ static void kdamond_apply_schemes(struct damon_ctx *c)
                        (s->apply_interval_us ? s->apply_interval_us :
                         c->attrs.aggr_interval) / sample_interval;
                s->last_applied = NULL;
                damos_trace_stat(c, s);
        }
        mutex_unlock(&c->walk_control_lock);
}


I have no real preference. I just think keeping the "if ()" statement out
of the main code as a more aesthetic look. But the above should be
equivalent in actual functionality.

-- Steve

Reply via email to