[RFC PATCH v1.1 9/9] mm/damon/core: handle extreme memory state in get_in_active_mem_bp()
From: SJ Park
Date: Sun Aug 02 2026 - 12:29:40 EST
damos_get_in_active_mem_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 67ad1f07c29a4..c79b854e1a971 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -3014,7 +3014,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