[PATCH RFC v2 10/15] mm/damon: convert to LRU refs based operations

From: Kairui Song via B4 Relay

Date: Fri Sep 11 2026 - 07:54:57 EST


From: Kairui Song <kasong@xxxxxxxxxxx>

damon_pa_pageout() cleared PG_referenced directly, which under MGLRU
may corrupts the folio's refs count in later commits. That flag is now
bit 0 of the count (LRU_REFS_FLAGS).

Reset the count instead under MGLRU.

Signed-off-by: Kairui Song <kasong@xxxxxxxxxxx>
---
mm/damon/paddr.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index 79195026b903..38d3ff7019e3 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -280,7 +280,14 @@ static unsigned long damon_pa_pageout(struct damon_region *r,
else
*sz_filter_passed += folio_size(folio) / addr_unit;

- folio_clear_referenced(folio);
+ /*
+ * DAMON only gets here for regions it measured as cold,
+ * so the hotness can be, and better be dropped.
+ */
+ if (lru_gen_enabled())
+ folio_set_lru_refs(folio, 0);
+ else
+ folio_clear_referenced(folio);
folio_test_clear_young(folio);
if (!folio_isolate_lru(folio))
goto put_folio;

--
2.55.0