From be25e67e3aeb11e164c92c39563f8a0b32472a21 Mon Sep 17 00:00:00 2001 From: Miaohe Lin Date: Wed, 8 Jun 2022 22:14:32 +0800 Subject: [PATCH] mm/vmscan: don't try to reclaim freed folios If folios were freed from under us, there's no need to reclaim them. Skip these folios to save lots of cpu cycles and avoid possible unnecessary disk I/O. Link: https://lkml.kernel.org/r/20220608141432.23258-1-linmiaohe@huawei.com Signed-off-by: Miaohe Lin Cc: Matthew Wilcox Signed-off-by: Andrew Morton --- mm/vmscan.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 97ac6c6c026d..cd2201ba6d7c 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1610,13 +1610,19 @@ retry: folio = lru_to_folio(page_list); list_del(&folio->lru); + nr_pages = folio_nr_pages(folio); + + if (folio_ref_count(folio) == 1 && + folio_ref_freeze(folio, 1)) { + /* folio was freed from under us. So we are done. */ + goto free_it; + } + if (!folio_trylock(folio)) goto keep; VM_BUG_ON_FOLIO(folio_test_active(folio), folio); - nr_pages = folio_nr_pages(folio); - /* Account the number of base pages */ sc->nr_scanned += nr_pages; -- 2.50.1