Re: [PATCH 2/3] mm/mglru: test PG_lru before taking a folio reference
From: Baolin Wang
Date: Tue Dec 01 2026 - 02:18:24 EST
On 11/29/26 10:37 PM, Barry Song (Xiaomi) wrote:
From: Chris Mason <mason@xxxxxxxxxx>
With MGLRU, reclaim that races with compaction for a folio can deadlock
on the lruvec->lru_lock that it already holds.
isolate_folio() runs under the lru_lock. It takes a reference, and drops
it again if another isolator has already cleared PG_lru. That
folio_put() must not be the last one, since the free path takes the
lru_lock if PG_lru is set. But compaction can release the lru_lock while
the folio is still on the list with PG_lru clear. If the folio is
truncated or unmapped meanwhile, the two isolators hold the only
references:
isolate_migratepages_block() evict_folios()
============================ ==============
folio_get_nontail_page()
folio_test_clear_lru()
goto isolate_abort
lruvec_unlock_irqrestore()
lruvec_lock_irq()
isolate_folio()
folio_try_get()
folio_test_clear_lru() fails
folio_set_lru()
folio_put()
folio_put()
__page_cache_release()
folio_lruvec_lock_irqsave()
The fix used here is to leave a folio alone if PG_lru is already clear,
before a reference is taken, as isolate_lru_folios() does. An isolator
that clears PG_lru after that test has to take the lru_lock before it
drops its own reference.
Fixes: ac35a4902374 ("mm: multi-gen LRU: minimal implementation")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Chris Mason <mason@xxxxxxxxxx>
Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
[Kairui: Improved the comment]
Signed-off-by: Kairui Song <kasong@xxxxxxxxxxx>
Signed-off-by: Barry Song (Xiaomi) <baohua@xxxxxxxxxx>
---
LGTM.
Reviewed-by: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>