From: sashiko-bot@kernel.org
To: "SJ Park" <sj@kernel.org>
Cc: damon@lists.linux.dev
Subject: Re: [PATCH 8/8] mm/damon/core: handle extreme memory state in get_in_active_mem_bp()
Date: Tue, 01 Sep 2026 13:36:50 +0000 [thread overview]
Message-ID: <20260901133650.EF4F71F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260901131850.98037-9-sj@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] 32-bit integer overflow in DAMOS metric calculations.
--
commit 4a4658bd5d39473e6ccb07618a88e601987f2acf
Author: SJ Park <sj@kernel.org>
mm/damon/core: handle extreme memory state in get_in_active_mem_bp()
The function damos_get_in_active_mem_bp() uses the sum of active and inactive
memory as a denominator. In extreme environments where both are zero, this
results in a divide by zero error. This patch avoids the issue by changing
the denominator to one if it is zero.
Link: https://lore.kernel.org/20260721034756.147011-1-sj@kernel.org
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index 3060edf5e4fa6..0df785e72438f 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -3006,7 +3006,7 @@ static unsigned int damos_get_in_active_mem_bp(bool active_ratio)
> global_node_page_state(NR_LRU_BASE + LRU_ACTIVE_FILE);
> inactive = global_node_page_state(NR_LRU_BASE + LRU_INACTIVE_ANON) +
> global_node_page_state(NR_LRU_BASE + LRU_INACTIVE_FILE);
> - total = active + inactive;
> + total = max(active + inactive, 1);
> if (active_ratio)
> return mult_frac(active, 10000, total);
> return mult_frac(inactive, 10000, total);
[Severity: High]
This isn't a bug introduced by this patch, but it's a pre-existing high
severity issue in the exact function modified.
Could this mult_frac() calculation overflow on 32-bit architectures?
When active or inactive memory exceeds approximately 429,496 pages (about
1.7GB) on a 32-bit system, the intermediate product in mult_frac():
(r * n / d) where r is (active % total) and n is 10000
will overflow the 32-bit unsigned long before division. This wraps around
and causes Damon to apply completely wrong quotas, degrading memory goal
reliability.
Does this same 32-bit overflow issue also affect other metric calculations
in mm/damon/core.c, such as damos_get_node_mem_bp() and
damos_get_node_memcg_used_bp() which similarly compute:
mult_frac(numerator, 10000, i.totalram) ?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260901131850.98037-1-sj@kernel.org?part=8
next prev parent reply other threads:[~2026-09-01 13:36 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-01 13:18 [PATCH 0/8] mm/damon: fix DAMOS bugs in core, paddr and vaddr SJ Park
2026-09-01 13:18 ` [PATCH 1/8] mm/damon/core: skip applying scheme if region split for quota fails SJ Park
2026-09-01 13:28 ` sashiko-bot
2026-09-01 13:18 ` [PATCH 2/8] mm/damon/paddr: respect folio end for DAMOS_STAT SJ Park
2026-09-01 13:27 ` sashiko-bot
2026-09-01 13:18 ` [PATCH 3/8] mm/damon/paddr: respect folio end for DAMOS actions except STAT SJ Park
2026-09-01 13:27 ` sashiko-bot
2026-09-01 13:18 ` [PATCH 4/8] mm/damon/vaddr: respect folio end for DAMOS_STAT SJ Park
2026-09-01 13:29 ` sashiko-bot
2026-09-01 13:18 ` [PATCH 5/8] mm/damon/vaddr: respect folio end for DAMOS_MIGRATE_{HOT,COLD} SJ Park
2026-09-01 13:26 ` sashiko-bot
2026-09-01 13:18 ` [PATCH 6/8] mm/damon/core: handle extreme memory state in damon_get_node_mem_bp() SJ Park
2026-09-01 13:35 ` sashiko-bot
2026-09-01 13:18 ` [PATCH 7/8] mm/damon/core: handle extreme memory state in get_node_memcg_used_bp() SJ Park
2026-09-01 13:41 ` sashiko-bot
2026-09-01 14:29 ` SJ Park
2026-09-01 13:18 ` [PATCH 8/8] mm/damon/core: handle extreme memory state in get_in_active_mem_bp() SJ Park
2026-09-01 13:36 ` sashiko-bot [this message]
2026-09-01 14:30 ` SJ Park
2026-09-01 14:30 ` [PATCH 0/8] mm/damon: fix DAMOS bugs in core, paddr and vaddr SJ 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=20260901133650.EF4F71F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=damon@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
--cc=sj@kernel.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