[PATCH v5 08/10] ceph: convert page cleanup loop in writepages_finish() to folios

From: Tal Zussman

Date: Wed Sep 02 2026 - 12:22:54 EST


Convert the page cleanup loop in writepages_finish() to work on folios.
Resolve the folio up front and unwrap any fscrypt bounce folio to its
page cache folio, storing the page cache page back into the array.

This removes a use of detach_page_private() and five calls to
compound_head() per page, while adding one back via page_folio().

While at it, remove the BUG_ON() in the num_pages loop, as it cannot be
triggered.

No functional change.

Signed-off-by: Tal Zussman <tz2294@xxxxxxxxxxxx>
---
fs/ceph/addr.c | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index 8e761144e8fb..f9741812e8a9 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -913,7 +913,6 @@ static void writepages_finish(struct ceph_osd_request *req)
struct ceph_inode_info *ci = ceph_inode(inode);
struct ceph_client *cl = ceph_inode_to_client(inode);
struct ceph_osd_data *osd_data;
- struct page *page;
int num_pages, total_pages = 0;
int i, j;
int rc = req->r_result;
@@ -960,35 +959,35 @@ static void writepages_finish(struct ceph_osd_request *req)
(u64)osd_data->length);
total_pages += num_pages;
for (j = 0; j < num_pages; j++) {
- page = osd_data->pages[j];
- if (fscrypt_is_bounce_page(page)) {
- page = fscrypt_pagecache_page(page);
+ struct folio *folio = page_folio(osd_data->pages[j]);
+
+ if (fscrypt_is_bounce_folio(folio)) {
+ folio = fscrypt_pagecache_folio(folio);
fscrypt_free_bounce_page(osd_data->pages[j]);
- osd_data->pages[j] = page;
+ osd_data->pages[j] = &folio->page;
}
- BUG_ON(!page);
- WARN_ON(!PageUptodate(page));
+ WARN_ON(!folio_test_uptodate(folio));

if (atomic_long_dec_return(&fsc->writeback_count) <
CONGESTION_OFF_THRESH(
fsc->mount_options->congestion_kb))
fsc->write_congested = false;

- ceph_put_snap_context(detach_page_private(page));
- end_page_writeback(page);
+ ceph_put_snap_context(folio_detach_private(folio));
+ folio_end_writeback(folio);

if (atomic64_dec_return(&mdsc->dirty_folios) <= 0) {
wake_up_all(&mdsc->flush_end_wq);
WARN_ON(atomic64_read(&mdsc->dirty_folios) < 0);
}

- doutc(cl, "unlocking %p\n", page);
+ doutc(cl, "unlocking %p\n", folio);

if (remove_page)
generic_error_remove_folio(inode->i_mapping,
- page_folio(page));
+ folio);

- unlock_page(page);
+ folio_unlock(folio);
}
doutc(cl, "%llx.%llx wrote %llu bytes cleaned %d pages\n",
ceph_vinop(inode), osd_data->length,

--
2.39.5