[PATCH 6/8] mm/damon/core: handle extreme memory state in damon_get_node_mem_bp()
From: SJ Park
Date: Tue Sep 01 2026 - 10:27:15 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(). It could also show free memory larger than the
total memory. This could cause underflow and make DAMOS temporarily
make unexpected behavior. Thanks to safety guards in the auto-tuning
feedback loop, that should not be a real problem, though. Fix the
problems by respectively returning 100% and 0% for used and free memory
queries in the corner cases.
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 | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index a6fdb3068262d..ad3657d356fbc 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -2807,6 +2807,13 @@ static __kernel_ulong_t damos_get_node_mem_bp(
}
si_meminfo_node(&i, goal->nid);
+ if (!i.totalram || i.totalram < i.freeram) {
+ if (goal->metric == DAMOS_QUOTA_NODE_MEM_USED_BP)
+ return 10000;
+ else /* DAMOS_QUOTA_NODE_MEM_FREE_BP */
+ return 0;
+ }
+
if (goal->metric == DAMOS_QUOTA_NODE_MEM_USED_BP)
numerator = i.totalram - i.freeram;
else /* DAMOS_QUOTA_NODE_MEM_FREE_BP */
--
2.47.3