From: SeongJae Park <sj@kernel.org>
To: Gutierrez Asier <gutierrez.asier@huawei-partners.com>
Cc: SeongJae Park <sj@kernel.org>,
sashiko-reviews@lists.linux.dev, damon@lists.linux.dev
Subject: Re: [RFC PATCH v3 1/4] mm/damon: Introduce DAMOS_QUOTA_HUGEPAGE auto tuning
Date: Fri, 5 Jun 2026 17:12:07 -0700 [thread overview]
Message-ID: <20260606001209.88310-1-sj@kernel.org> (raw)
In-Reply-To: <2a4665b3-ac61-4ea2-b360-5cc6c21a6606@huawei-partners.com>
On Fri, 5 Jun 2026 13:57:47 +0300 Gutierrez Asier <gutierrez.asier@huawei-partners.com> wrote:
>
>
> On 6/4/2026 6:19 PM, sashiko-bot@kernel.org wrote:
[...]
> > [Severity: High]
> > This is a pre-existing issue, but can this cause a divide by zero kernel
> > panic?
> >
> > If there are no active or inactive pages, or if per-CPU vmstat counter drift
> > evaluates total to 0, mult_frac() will divide by zero.
> Not a bug. The system can never have 0 consumed memory.
Makes sense.
> >> +static unsigned int damos_hugepage_mem_bp(void)
> >> +{
> >> + unsigned long thp, total;
> >> +
> >> + thp = global_node_page_state(NR_ANON_THPS) +
> >> + global_node_page_state(NR_SHMEM_THPS) +
> >> + global_node_page_state(NR_FILE_THPS);
> >> + total = totalram_pages() - global_zone_page_state(NR_FREE_PAGES);
> >> + return mult_frac(thp, 10000, total);
> >
> > [Severity: High]
> > Can mult_frac() divide by zero here?
> >
> > If the system is highly idle or due to per-CPU vmstat counter drift, total
> > could evaluate to exactly 0.
> No, total can never be 0.
> > [Severity: Medium]
> > Is there a risk of a 32-bit overflow in this calculation?
> >
> > On 32-bit architectures, mult_frac() preserves types, and computing
> > thp * 10000 could exceed the maximum unsigned long value if there are
> > more than ~1.7 GB of THPs, producing an arbitrarily small quota target.
> >
> Good catch! I will cast 10000 to unsigned long to preserve the types.
But still it is 'unsigned long' that has only 32 bits on 32-bit architectures?
So it shouldn't make any change here. Or, am I missing something?
Thanks,
SJ
[...]
next prev parent reply other threads:[~2026-06-06 0:12 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-04 15:03 [RFC PATCH v3 0/4] mm/damon: Introduce a huge page collapsing mechanism using auto tuning gutierrez.asier
2026-06-04 15:03 ` [RFC PATCH v3 1/4] mm/damon: Introduce DAMOS_QUOTA_HUGEPAGE " gutierrez.asier
2026-06-04 15:19 ` sashiko-bot
2026-06-05 10:57 ` Gutierrez Asier
2026-06-06 0:12 ` SeongJae Park [this message]
2026-06-05 0:44 ` SeongJae Park
2026-06-05 11:00 ` Gutierrez Asier
2026-06-06 0:14 ` SeongJae Park
2026-06-04 15:03 ` [RFC PATCH v3 2/4] mm/damon: Generalize ctx_target creation for damon_ops_id and add vaddr support gutierrez.asier
2026-06-05 0:50 ` SeongJae Park
2026-06-05 11:13 ` Gutierrez Asier
2026-06-06 0:15 ` SeongJae Park
2026-06-04 15:03 ` [RFC PATCH v3 3/4] mm/damon: introduce DAMON_HUGEPAGE for hot region hugepage collapsing gutierrez.asier
2026-06-04 15:41 ` sashiko-bot
2026-06-05 14:16 ` Gutierrez Asier
2026-06-05 1:06 ` SeongJae Park
2026-06-05 13:47 ` Gutierrez Asier
2026-06-04 15:03 ` [RFC PATCH v3 4/4] Documentation/admin-guide/mm/damon: add DAMON-based Hugepage Management gutierrez.asier
2026-06-04 15:48 ` sashiko-bot
2026-06-05 1:09 ` SeongJae Park
2026-06-05 10:28 ` Gutierrez Asier
2026-06-05 1:34 ` [RFC PATCH v3 0/4] mm/damon: Introduce a huge page collapsing mechanism using auto tuning SeongJae Park
2026-06-05 10:25 ` Gutierrez Asier
2026-06-06 0:24 ` 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=20260606001209.88310-1-sj@kernel.org \
--to=sj@kernel.org \
--cc=damon@lists.linux.dev \
--cc=gutierrez.asier@huawei-partners.com \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.