From 6f64c06f43098ea0aa0a67d0ad15124b5d2ba0fe Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Mon, 1 Jun 2026 13:34:28 +0200 Subject: [PATCH] mm: merge writeout into pageout writeout is only called from pageout, and a straight flow at the end, so merge the two functions. Link: https://lore.kernel.org/20260601113449.3464734-3-hch@lst.de Signed-off-by: Christoph Hellwig Reviewed-by: Baoquan He Reviewed-by: Nhat Pham Acked-by: David Hildenbrand (Arm) Cc: Chris Li Cc: Kairui Song Cc: Kemeng Shi Signed-off-by: Andrew Morton --- mm/vmscan.c | 63 ++++++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 3f3ff25e561a..299b5d9e8836 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -612,11 +612,38 @@ typedef enum { PAGE_CLEAN, } pageout_t; -static pageout_t writeout(struct folio *folio, struct address_space *mapping, - struct swap_iocb **plug, struct list_head *folio_list) +/* + * pageout is called by shrink_folio_list() for each dirty folio. + */ +static pageout_t pageout(struct folio *folio, struct address_space *mapping, + struct swap_iocb **plug, struct list_head *folio_list) { int res; + /* + * We no longer attempt to writeback filesystem folios here, other + * than tmpfs/shmem. That's taken care of in page-writeback. + * If we find a dirty filesystem folio at the end of the LRU list, + * typically that means the filesystem is saturating the storage + * with contiguous writes and telling it to write a folio here + * would only make the situation worse by injecting an element + * of random access. + * + * If the folio is swapcache, write it back even if that would + * block, for some throttling. This happens by accident, because + * swap_backing_dev_info is bust: it doesn't reflect the + * congestion state of the swapdevs. Easy to fix, if needed. + * + * A freeable shmem or swapcache folio is referenced only by the + * caller that isolated the folio and the page cache. + */ + if (folio_ref_count(folio) != 1 + folio_nr_pages(folio) || !mapping) + return PAGE_KEEP; + if (!shmem_mapping(mapping) && !folio_test_anon(folio)) + return PAGE_ACTIVATE; + if (!folio_clear_dirty_for_io(folio)) + return PAGE_CLEAN; + folio_set_reclaim(folio); /* @@ -645,38 +672,6 @@ static pageout_t writeout(struct folio *folio, struct address_space *mapping, return PAGE_SUCCESS; } -/* - * pageout is called by shrink_folio_list() for each dirty folio. - */ -static pageout_t pageout(struct folio *folio, struct address_space *mapping, - struct swap_iocb **plug, struct list_head *folio_list) -{ - /* - * We no longer attempt to writeback filesystem folios here, other - * than tmpfs/shmem. That's taken care of in page-writeback. - * If we find a dirty filesystem folio at the end of the LRU list, - * typically that means the filesystem is saturating the storage - * with contiguous writes and telling it to write a folio here - * would only make the situation worse by injecting an element - * of random access. - * - * If the folio is swapcache, write it back even if that would - * block, for some throttling. This happens by accident, because - * swap_backing_dev_info is bust: it doesn't reflect the - * congestion state of the swapdevs. Easy to fix, if needed. - * - * A freeable shmem or swapcache folio is referenced only by the - * caller that isolated the folio and the page cache. - */ - if (folio_ref_count(folio) != 1 + folio_nr_pages(folio) || !mapping) - return PAGE_KEEP; - if (!shmem_mapping(mapping) && !folio_test_anon(folio)) - return PAGE_ACTIVATE; - if (!folio_clear_dirty_for_io(folio)) - return PAGE_CLEAN; - return writeout(folio, mapping, plug, folio_list); -} - /* * Same as remove_mapping, but if the folio is removed from the mapping, it * gets returned with a refcount of 0.