[PATCH v2 1/6] mm/page_io: convert write completion handlers to folios

From: Tal Zussman

Date: Sat Aug 29 2026 - 15:09:41 EST


Convert swap_write_end() and swap_fs_write_complete() to operate on
folios directly instead of going through the folio-compat page APIs.
This removes calls to end_page_writeback() and set_page_dirty(), and the
last caller of ClearPageReclaim(), saving two calls to compound_head()
per folio on the write error path.

Acked-by: Johannes Weiner <hannes@xxxxxxxxxxx>
Reviewed-by: Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx>
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx>
Signed-off-by: Tal Zussman <tz2294@xxxxxxxxxxxx>
---
mm/page_io.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/mm/page_io.c b/mm/page_io.c
index 88962571cb93..fbcf58ff292d 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -497,13 +497,13 @@ static void swap_write_end(struct swap_iocb *sio, bool failed)
int p;

for (p = 0; p < sio->nr_bvecs; p++) {
- struct page *page = sio->bvecs[p].bv_page;
+ struct folio *folio = bvec_folio(&sio->bvecs[p]);

if (failed) {
- set_page_dirty(page);
- ClearPageReclaim(page);
+ folio_mark_dirty(folio);
+ folio_clear_reclaim(folio);
}
- end_page_writeback(page);
+ folio_end_writeback(folio);
}
mempool_free(sio, sio_pool);
}
@@ -514,16 +514,16 @@ static void swap_fs_write_complete(struct kiocb *iocb, long ret)
bool failed = ret != sio->len;

if (failed) {
- struct page *page = sio->bvecs[0].bv_page;
+ struct folio *folio = bvec_folio(&sio->bvecs[0]);

/*
* In the case of swap-over-nfs, this can be a temporary failure
* if the system has limited memory for allocating transmit
- * buffers. Mark the page dirty and avoid
+ * buffers. Mark the folio dirty and avoid
* folio_rotate_reclaimable but rate-limit the messages.
*/
pr_err_ratelimited("Write error %ld on dio swapfile (%llu)\n",
- ret, swap_dev_pos(page_swap_entry(page)));
+ ret, swap_dev_pos(folio->swap));
}

swap_write_end(sio, failed);

--
2.39.5