@@ -14,6 +14,7 @@
#include <linux/swapops.h>
#include <linux/init.h>
#include <linux/pagemap.h>
+#include <linux/pagevec.h>
#include <linux/backing-dev.h>
#include <linux/blkdev.h>
#include <linux/migrate.h>
@@ -309,10 +310,18 @@ void free_page_and_swap_cache(struct page *page)
*/
void free_pages_and_swap_cache(struct encoded_page **pages, int nr)
{
+ struct folio_batch folios;
+
lru_add_drain();
- for (int i = 0; i < nr; i++)
- free_swap_cache(encoded_page_ptr(pages[i]));
- release_pages(pages, nr);
+ folio_batch_init(&folios);
+ for (int i = 0; i < nr; i++) {
+ struct folio *folio = page_folio(encoded_page_ptr(pages[i]));
+ free_swap_cache(&folio->page);
+ if (folio_batch_add(&folios, folio) == 0)
+ folios_put(&folios);
+ }
+ if (folios.nr)
+ folios_put(&folios);
}
static inline bool swap_use_vma_readahead(void)
Process the pages in batch-sized quantities instead of all-at-once. Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> --- mm/swap_state.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)