From 316b2e6e4baa4cdf6c678730a16999b29c21a52c Mon Sep 17 00:00:00 2001 From: "Matthew Wilcox (Oracle)" Date: Tue, 27 Feb 2024 17:42:40 +0000 Subject: [PATCH] BACKPORT: mm: remove use of folio list from folios_put() Instead of putting the interesting folios on a list, delete the uninteresting one from the folio_batch. Link: https://lkml.kernel.org/r/20240227174254.710559-7-willy@infradead.org Change-Id: I1c416d2a6b8a78a9b194c4cf45577b64b8cb99c6 Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Ryan Roberts Cc: David Hildenbrand Cc: Mel Gorman Signed-off-by: Andrew Morton (cherry picked from commit 7c33b8c4229af19797c78de48827ca70228c1f47) [ Fix trivial conflicts in folio_put_ref() - Kalesh Singh] Bug: 419599659 Signed-off-by: Kalesh Singh --- mm/swap.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/mm/swap.c b/mm/swap.c index 216b4e015d2a..dc7a3d60b38a 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -973,12 +973,11 @@ EXPORT_SYMBOL_GPL(lru_cache_disable); */ void folios_put_refs(struct folio_batch *folios, unsigned int *refs) { - int i; - LIST_HEAD(pages_to_free); + int i, j; struct lruvec *lruvec = NULL; unsigned long flags = 0; - for (i = 0; i < folios->nr; i++) { + for (i = 0, j = 0; i < folios->nr; i++) { struct folio *folio = folios->folios[i]; unsigned int nr_refs = refs ? refs[i] : 1; @@ -1017,14 +1016,20 @@ void folios_put_refs(struct folio_batch *folios, unsigned int *refs) __folio_clear_lru_flags(folio); } - list_add(&folio->lru, &pages_to_free); + if (j != i) + folios->folios[j] = folio; + j++; } if (lruvec) unlock_page_lruvec_irqrestore(lruvec, flags); + if (!j) { + folio_batch_reinit(folios); + return; + } - mem_cgroup_uncharge_list(&pages_to_free); - free_unref_page_list(&pages_to_free); - folio_batch_reinit(folios); + folios->nr = j; + mem_cgroup_uncharge_folios(folios); + free_unref_folios(folios); } EXPORT_SYMBOL(folios_put_refs);