linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/vmscan: don't try to reclaim freed folios
@ 2022-05-27  8:04 Miaohe Lin
  2022-05-27 15:02 ` Matthew Wilcox
  0 siblings, 1 reply; 6+ messages in thread
From: Miaohe Lin @ 2022-05-27  8:04 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, linux-kernel, linmiaohe

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 IO.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 mm/vmscan.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index f7d9a683e3a7..646dd1efad32 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -1556,12 +1556,18 @@ static unsigned int shrink_page_list(struct list_head *page_list,
 		folio = lru_to_folio(page_list);
 		list_del(&folio->lru);
 
+		nr_pages = folio_nr_pages(folio);
+		if (folio_ref_count(folio) == 1) {
+			/* folio was freed from under us. So we are done. */
+			WARN_ON(!folio_put_testzero(folio));
+			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.23.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-06-08 14:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-27  8:04 [PATCH] mm/vmscan: don't try to reclaim freed folios Miaohe Lin
2022-05-27 15:02 ` Matthew Wilcox
2022-05-28  2:52   ` Miaohe Lin
2022-05-28  3:13     ` Matthew Wilcox
2022-05-28  6:24       ` Miaohe Lin
2022-06-08 14:09   ` Miaohe Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).