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

From: SJ Park

Date: Sat Aug 01 2026 - 13:45:09 EST


damon_get_intervals_adaptation_bp() uses the sum of the active and
inactive memory amount as a denominator. In an extreme and unlikely
environment, active and inactive memory might be zero. In this case,
hence, it results in a divide by zero problem. Avoid it by changing the
denominator to one if it is zero, before it is being used.

The issue was discovered [1] by Sashiko.

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

Fixes: 4835e2871321 ("mm/damon/core: introduce [in]active memory ratio damos quota goal metric")
Cc: <stable@xxxxxxxxxxxxxxx> # 7.0.x
Signed-off-by: SJ Park <sj@xxxxxxxxxx>
---
mm/damon/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index 76764a2056f7c..4944cf2c5afae 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -3010,7 +3010,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);
--
2.47.3