[RFC PATCH 7/9] mm/damon/core: handle extreme memory state in damon_get_node_mem_bp()

From: SJ Park

Date: Sat Aug 01 2026 - 13:42:20 EST


In an extreme and unlikely situation, si_meminfo_node() might let the
caller show zero total ram. That could cause a divide by zero in
damon_get_node_mem_bp(). Fix it by setting the totalram one byte in the
case.

The issue was discovered [1] by Sashiko.

[1] https://lore.kernel.org/20260328133216.9697-1-sj@xxxxxxxxxx

Fixes: 0e1c773b501f ("mm/damon/core: introduce damos quota goal metrics for memory node utilization")
Cc: <stable@xxxxxxxxxxxxxxx> # 6.16.x
Signed-off-by: SJ Park <sj@xxxxxxxxxx>
---
mm/damon/core.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index 3bdbf4fbf7147..269865eb8fbfa 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -2816,6 +2816,8 @@ static __kernel_ulong_t damos_get_node_mem_bp(
}

si_meminfo_node(&i, goal->nid);
+ if (!i.totalram)
+ i.totalram = 1;
if (goal->metric == DAMOS_QUOTA_NODE_MEM_USED_BP)
numerator = i.totalram - i.freeram;
else /* DAMOS_QUOTA_NODE_MEM_FREE_BP */
--
2.47.3