From: sashiko-bot@kernel.org
To: "SJ Park" <sj@kernel.org>
Cc: damon@lists.linux.dev
Subject: Re: [RFC PATCH v1.1 8/9] mm/damon/core: handle extreme memory state in get_node_memcg_used_bp()
Date: Sun, 02 Aug 2026 16:38:33 +0000 [thread overview]
Message-ID: <20260802163834.2C72B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260802162631.90304-9-sj@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but damos_get_node_mem_bp() contains a severe logic bug and underflow when free memory exceeds total memory (i.totalram < i.freeram).
--
--- Patch [8]: [RFC PATCH v1.1 8/9] mm/damon/core: handle extreme memory state in get_node_memcg_used_bp() ---
commit 0fb31bc202c766c30f5d776d57b867135fba4aa6
Author: SJ Park <sj@kernel.org>
mm/damon/core: handle extreme memory state in get_node_memcg_used_bp()
This commit addresses division by zero and underflow issues in
damos_get_node_memcg_used_bp() by handling cases where total memory is zero or
used memory exceeds total memory. It returns 100% and 0% for these respective
edge cases to prevent anomalous behavior.
Link: https://lore.kernel.org/20260329154813.47382-1-sj@kernel.org
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index e3f3ee75a3d33..67ad1f07c29a4 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -2862,10 +2862,16 @@ static unsigned long damos_get_node_memcg_used_bp(
> mem_cgroup_put(memcg);
>
> si_meminfo_node(&i, goal->nid);
> - if (goal->metric == DAMOS_QUOTA_NODE_MEMCG_USED_BP)
> + if (!i.totalram)
> + return 10000;
> + if (goal->metric == DAMOS_QUOTA_NODE_MEMCG_USED_BP) {
> numerator = used_pages;
> - else /* DAMOS_QUOTA_NODE_MEMCG_FREE_BP */
> + } else {
> + /* DAMOS_QUOTA_NODE_MEMCG_FREE_BP */
> + if (i.totalram < used_pages)
> + return 0;
[Severity: High]
This isn't a bug introduced by this patch, but does the adjacent
damos_get_node_mem_bp() function contain a logic bug when free memory exceeds
total memory?
If i.totalram < i.freeram, it appears that for DAMOS_QUOTA_NODE_MEM_USED_BP,
i.totalram - i.freeram will unconditionally underflow, falsely throttling or
activating schemes. For DAMOS_QUOTA_NODE_MEM_FREE_BP, returning 0 means it
reports 0% free memory when the node is actually >100% free, which could cause
schemes waiting for low free memory to trigger aggressively.
mm/damon/core.c:damos_get_node_mem_bp() {
...
if (goal->metric == DAMOS_QUOTA_NODE_MEM_USED_BP) {
numerator = i.totalram - i.freeram;
} else {
/* DAMOS_QUOTA_NODE_MEM_FREE_BP */
if (i.totalram < i.freeram)
return 0;
numerator = i.freeram;
}
...
}
Should this pre-existing issue in damos_get_node_mem_bp() be addressed as well,
perhaps by returning 0 for USED_BP and 10000 for FREE_BP when
i.totalram < i.freeram?
> numerator = i.totalram - used_pages;
> + }
> return mult_frac(numerator, 10000, i.totalram);
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260802162631.90304-1-sj@kernel.org?part=8
next prev parent reply other threads:[~2026-08-02 16:38 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-02 16:26 [RFC PATCH v1.1 0/9] mm/damon: fix DAMOS bugs in core, paddr and vaddr SJ Park
2026-08-02 16:26 ` [RFC PATCH v1.1 1/9] mm/damon/core: skip applying scheme if region split for quota fails SJ Park
2026-08-02 16:26 ` [RFC PATCH v1.1 2/9] mm/damon/core: initialize damos_quota_goal->last_psi_total SJ Park
2026-08-02 16:43 ` sashiko-bot
2026-08-02 17:41 ` SJ Park
2026-08-02 16:26 ` [RFC PATCH v1.1 3/9] mm/damon/paddr: respect folio end for DAMOS_STAT SJ Park
2026-08-02 16:34 ` sashiko-bot
2026-08-02 17:43 ` SJ Park
2026-08-02 16:26 ` [RFC PATCH v1.1 4/9] mm/damon/paddr: respect folio end for DAMOS actions except STAT SJ Park
2026-08-02 16:26 ` [RFC PATCH v1.1 5/9] mm/damon/vaddr: respect folio end for DAMOS_STAT SJ Park
2026-08-02 16:36 ` sashiko-bot
2026-08-02 17:45 ` SJ Park
2026-08-02 16:26 ` [RFC PATCH v1.1 6/9] mm/damon/vaddr: respect folio end for DAMOS_MIGRATE_{HOT,COLD} SJ Park
2026-08-02 16:26 ` [RFC PATCH v1.1 7/9] mm/damon/core: handle extreme memory state in damon_get_node_mem_bp() SJ Park
2026-08-02 16:35 ` sashiko-bot
2026-08-02 17:49 ` SJ Park
2026-08-02 17:59 ` SJ Park
2026-08-02 16:26 ` [RFC PATCH v1.1 8/9] mm/damon/core: handle extreme memory state in get_node_memcg_used_bp() SJ Park
2026-08-02 16:38 ` sashiko-bot [this message]
2026-08-02 17:51 ` SJ Park
2026-08-02 16:26 ` [RFC PATCH v1.1 9/9] mm/damon/core: handle extreme memory state in get_in_active_mem_bp() SJ Park
2026-08-02 16:51 ` sashiko-bot
2026-08-02 17:51 ` 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=20260802163834.2C72B1F000E9@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