[RFC PATCH v1.1 7/9] mm/damon/core: handle extreme memory state in damon_get_node_mem_bp()
From: SJ Park
Date: Sun Aug 02 2026 - 12:27:49 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 | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 3bdbf4fbf7147..e3f3ee75a3d33 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -2816,10 +2816,16 @@ static __kernel_ulong_t damos_get_node_mem_bp(
}
si_meminfo_node(&i, goal->nid);
- if (goal->metric == DAMOS_QUOTA_NODE_MEM_USED_BP)
+ if (!i.totalram)
+ return 10000;
+ if (goal->metric == DAMOS_QUOTA_NODE_MEM_USED_BP) {
numerator = i.totalram - i.freeram;
- else /* DAMOS_QUOTA_NODE_MEM_FREE_BP */
+ } else {
+ /* DAMOS_QUOTA_NODE_MEM_FREE_BP */
+ if (i.totalram < i.freeram)
+ return 0;
numerator = i.freeram;
+ }
return mult_frac(numerator, 10000, i.totalram);
}
--
2.47.3