Re: (sashiko review) [RFC PATCH v5.2 03/11] mm/damon/core: introduce failed region quota charge ratio

SeongJae Park
2026-04-12T18:08:05Z

TL; DR: Sashiko found no blocker for this patch. It is just asking a same
question that I decided to ignore.

Forwarding full sashiko review in a reply format with my inline comments below,
for sharing details of my view and doing followup discussions via mails if
needed.

> # review url: https://sashiko.dev/#/patchset/20260412161957.82835-4-sj@kernel.org
> # start of sashiko.dev inline review
> commit 45b2671ba02d19f0991caa536696cde623c0c081
> Author: SeongJae Park <sj@kernel.org>
>
> mm/damon/core: introduce failed region quota charge ratio
>
> This commit introduces a new DAMON core API for setting the charge ratio
> for action-failed memory. It allows specifying the ratio using a numerator
> and denominator to make charging fairer for successful vs failed actions.
>
> > diff --git a/mm/damon/core.c b/mm/damon/core.c
> > --- a/mm/damon/core.c
> > +++ b/mm/damon/core.c
> > @@ -2041,6 +2043,23 @@ static void damos_walk_cancel(struct damon_ctx *ctx)
> > mutex_unlock(&ctx->walk_control_lock);
> > }
> >
> > +static void damos_charge_quota(struct damos_quota *quota,
> > + unsigned long sz_region, unsigned long sz_applied)
> > +{
> > + /*
> > + * sz_applied could be bigger than sz_region, depending on ops
> > + * implementation of the action, e.g., damos_pa_pageout(). Charge only
> > + * the region size in the case.
> > + */
> > + if (!quota->fail_charge_denom || sz_applied > sz_region)
> > + quota->charged_sz += sz_region;
> > + else
> > + quota->charged_sz += sz_applied + mult_frac(
> > + (sz_region - sz_applied),
> > + quota->fail_charge_num,
> > + quota->fail_charge_denom);
>
> Can this calculation overflow during the mult_frac() expansion?
>
> The mult_frac(x, numer, denom) macro evaluates to:
> (x / denom * numer) + ((x % denom * numer) / denom)
>
> Since both sz_region and sz_applied are unsigned long, on 32-bit systems this
> is a 32-bit type. If fail_charge_num is large, couldn't the remainder
> multiplication (or even the quotient multiplication) overflow unsigned long
> and truncate the size added to quota->charged_sz?

A question that same to what raised previously. I decided to keep this as is
in favor of code simplicity, unless other humans make some voices.

>
> > +}
> > +
>
>
> # end of sashiko.dev inline review
> # review url: https://sashiko.dev/#/patchset/20260412161957.82835-4-sj@kernel.org

Thanks,
SJ

# hkml [1] generated a draft of this mail. You can regenerate
# this using below command:
#
# hkml patch sashiko_dev --for_forwarding \
# 20260412161957.82835-4-sj@kernel.org
#
# [1] https://github.com/sjp38/hackermail