Re: summarize all information again at bottom//reply: reply: [PATCH] mm: fix a race scenario in folio_isolate_lru

From: Matthew Wilcox
Date: Tue Mar 26 2024 - 08:22:17 EST


On Tue, Mar 26, 2024 at 05:06:55PM +0800, Zhaoyang Huang wrote:
> 1. Thread_readahead remove the folio from page cache and drop 2 refcnt
> by readahead_folio & filemap_remove_folio(get rid of the folios which
> failed to launch IO during readahead)
> refcnt == 0, PG_lru == true, PG_lock == true
> read_pages
> ...
> folio = readahead_folio
> <one refcnt dropped here>
> ********For the folio which can not launch IO, we should NOT drop
> refcnt here??? replaced by __readahead_folio???**********
> folio_get
> filemap_remove_folio(folio)
> folio_unlock
> <one refcnt dropped here>
> folio_put

Ignoring any other thread, you're basically saying that there's a
refcount imbalance here. Which means we'd hit an assert (that folio
refcount went below zero) in the normal case where another thread wasn't
simultaneously trying to do anything.