From: SeongJae Park <sj@kernel.org>
To: SeongJae Park <sj@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Liew Rui Yan <aethernet65535@gmail.com>,
damon@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-mm@kvack.org
Subject: Re: (sashiko review) [PATCH 1/3] mm/damon/ops-common: optimize damon_hot_score() using ilog2()
Date: Thu, 2 Apr 2026 17:16:57 -0700 [thread overview]
Message-ID: <20260403001658.46229-1-sj@kernel.org> (raw)
In-Reply-To: <20260402155733.77050-2-sj@kernel.org>
TL; DR: sashiko didn't find a blocker for this patch.
Forwarding Sashiko review in a review format with my inline comment, for
sharing more details of my view and doing more discussions via mails if needed.
> # review url: https://sashiko.dev/#/patchset/20260402155733.77050-2-sj@kernel.org
> # start of sashiko.dev inline review
> commit 3d1d9600685998aeba66926091d5a11897567bd0
> Author: Liew Rui Yan <aethernet65535@gmail.com>
>
> mm/damon/ops-common: optimize damon_hot_score() using ilog2()
>
> This commit replaces a manual for-loop with an ilog2() based calculation
> to optimize the derivation of age_in_log in damon_hot_score(), improving
> latency during performance tests.
>
> > diff --git a/mm/damon/ops-common.c b/mm/damon/ops-common.c
> > --- a/mm/damon/ops-common.c
> > +++ b/mm/damon/ops-common.c
> [ ... ]
> > @@ -117,9 +117,12 @@ int damon_hot_score(struct damon_ctx *c, struct damon_region *r,
> > damon_max_nr_accesses(&c->attrs);
> >
> > age_in_sec = (unsigned long)r->age * c->attrs.aggr_interval / 1000000;
> > - for (age_in_log = 0; age_in_log < DAMON_MAX_AGE_IN_LOG && age_in_sec;
> > - age_in_log++, age_in_sec >>= 1)
> > - ;
> > + if (age_in_sec)
> > + age_in_log = min_t(int, ilog2(age_in_sec) + 1,
> > + DAMON_MAX_AGE_IN_LOG);
> > + else
> > + age_in_log = 0;
>
> This isn't a bug, but could this logic be simplified and the branch avoided
> by using fls() instead of ilog2()?
>
> For non-constant variable arguments, ilog2(x) internally resolves to
> fls(x) - 1. By evaluating ilog2(age_in_sec) + 1, this code essentially
> calculates fls(age_in_sec) - 1 + 1.
>
> Since fls() natively returns 0 when the input is 0, using fls(age_in_sec)
> directly would remove the need for the conditional branch entirely and
> reduce the block to a single expression.
We decided to use ilog2() since it makes the code easier to read in my taste.
So, this is not a blocker for this patch.
>
>
> # end of sashiko.dev inline review
> # review url: https://sashiko.dev/#/patchset/20260402155733.77050-2-sj@kernel.org
Thanks,
SJ
[...]
next prev parent reply other threads:[~2026-04-03 0:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-02 15:57 [PATCH 0/3] mm/damon: non-hotfix reviewed patches in damon/next tree SeongJae Park
2026-04-02 15:57 ` [PATCH 1/3] mm/damon/ops-common: optimize damon_hot_score() using ilog2() SeongJae Park
2026-04-03 0:16 ` SeongJae Park [this message]
2026-04-02 15:57 ` [PATCH 2/3] Docs/admin-guide/mm/damon: fix 'parametrs' typo SeongJae Park
2026-04-02 15:57 ` [PATCH 3/3] mm/damon: add synchronous commit for commit_inputs SeongJae Park
2026-04-03 0:23 ` SeongJae Park
2026-04-03 0:27 ` (sashiko status) [PATCH 0/3] mm/damon: non-hotfix reviewed patches in damon/next tree SeongJae Park
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260403001658.46229-1-sj@kernel.org \
--to=sj@kernel.org \
--cc=aethernet65535@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=damon@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox