public inbox for linux-mm@kvack.org
 help / color / mirror / Atom feed
* [PATCH] mm/page_io: use folios in sio_write_complete()
@ 2026-03-23 17:04 David Carlier
  2026-03-23 22:54 ` Andrew Morton
  2026-03-23 23:13 ` [PATCH] mm/page_io: fix PSWPIN undercount for large folios in sio_read_complete() David Carlier
  0 siblings, 2 replies; 4+ messages in thread
From: David Carlier @ 2026-03-23 17:04 UTC (permalink / raw)
  To: Kairui Song, Chris Li, Andrew Morton, Kemeng Shi; +Cc: linux-mm, David Carlier

Convert sio_write_complete() from legacy page APIs to folio equivalents,
matching the conversion already done for sio_read_complete() in commit
6a8c068774ad ("mm/page_io: use a folio in sio_read_complete()").

Replace set_page_dirty(), ClearPageReclaim() and end_page_writeback()
with folio_mark_dirty(), folio_clear_reclaim() and folio_end_writeback()
respectively, saving implicit calls to compound_head().

Also replace page_swap_entry() with a direct folio->swap access since
bvec entries are always set via bvec_set_folio(), meaning bv_page is
always the head page.

Signed-off-by: David Carlier <devnexen@gmail.com>
---
 mm/page_io.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/mm/page_io.c b/mm/page_io.c
index 63b262f4c5a9..6c7ab3c394ad 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -348,7 +348,6 @@ int sio_pool_init(void)
 static void sio_write_complete(struct kiocb *iocb, long ret)
 {
 	struct swap_iocb *sio = container_of(iocb, struct swap_iocb, iocb);
-	struct page *page = sio->bvec[0].bv_page;
 	int p;
 
 	if (ret != sio->len) {
@@ -356,21 +355,24 @@ static void sio_write_complete(struct kiocb *iocb, long ret)
 		 * 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
+		 * Mark the folio dirty and avoid
 		 * folio_rotate_reclaimable but rate-limit the
 		 * messages.
 		 */
+		struct folio *folio = page_folio(sio->bvec[0].bv_page);
 		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));
 		for (p = 0; p < sio->pages; p++) {
-			page = sio->bvec[p].bv_page;
-			set_page_dirty(page);
-			ClearPageReclaim(page);
+			folio = page_folio(sio->bvec[p].bv_page);
+			folio_mark_dirty(folio);
+			folio_clear_reclaim(folio);
 		}
 	}
 
-	for (p = 0; p < sio->pages; p++)
-		end_page_writeback(sio->bvec[p].bv_page);
+	for (p = 0; p < sio->pages; p++) {
+		struct folio *folio = page_folio(sio->bvec[p].bv_page);
+		folio_end_writeback(folio);
+	}
 
 	mempool_free(sio, sio_pool);
 }
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/page_io: use folios in sio_write_complete()
  2026-03-23 17:04 [PATCH] mm/page_io: use folios in sio_write_complete() David Carlier
@ 2026-03-23 22:54 ` Andrew Morton
  2026-03-23 23:07   ` David CARLIER
  2026-03-23 23:13 ` [PATCH] mm/page_io: fix PSWPIN undercount for large folios in sio_read_complete() David Carlier
  1 sibling, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2026-03-23 22:54 UTC (permalink / raw)
  To: David Carlier; +Cc: Kairui Song, Chris Li, Kemeng Shi, linux-mm

On Mon, 23 Mar 2026 17:04:49 +0000 David Carlier <devnexen@gmail.com> wrote:

> Convert sio_write_complete() from legacy page APIs to folio equivalents,
> matching the conversion already done for sio_read_complete() in commit
> 6a8c068774ad ("mm/page_io: use a folio in sio_read_complete()").
> 
> Replace set_page_dirty(), ClearPageReclaim() and end_page_writeback()
> with folio_mark_dirty(), folio_clear_reclaim() and folio_end_writeback()
> respectively, saving implicit calls to compound_head().
> 
> Also replace page_swap_entry() with a direct folio->swap access since
> bvec entries are always set via bvec_set_folio(), meaning bv_page is
> always the head page.
> 

This prompted AI review to look at sio_read_complete() and it didn't
like what it saw.  Can you please check
https://sashiko.dev/#/patchset/20260323170449.26333-1-devnexen@gmail.com?

Also, mm.git is (over)full.  Can we please park the nice-to-have
cleanups until after next -rc1?


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/page_io: use folios in sio_write_complete()
  2026-03-23 22:54 ` Andrew Morton
@ 2026-03-23 23:07   ` David CARLIER
  0 siblings, 0 replies; 4+ messages in thread
From: David CARLIER @ 2026-03-23 23:07 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Kairui Song, Chris Li, Kemeng Shi, linux-mm

Hi Andrew,

  Thanks for pointing that out. I'll park the folio conversion until
  after -rc1.

  Sashiko's observation is correct — sio_read_complete() undercounts
  PSWPIN for large folios. sio->pages tracks bvec entries (folios), not
  base pages. The bdev paths correctly use folio_nr_pages(folio) but the
  sio path doesn't.

  I'll send a fix replacing sio->pages with sio->len >> PAGE_SHIFT,
  which gives the correct base page count since sio->len is accumulated
  via folio_size(folio).

Cheers !

On Mon, 23 Mar 2026 at 22:54, Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Mon, 23 Mar 2026 17:04:49 +0000 David Carlier <devnexen@gmail.com> wrote:
>
> > Convert sio_write_complete() from legacy page APIs to folio equivalents,
> > matching the conversion already done for sio_read_complete() in commit
> > 6a8c068774ad ("mm/page_io: use a folio in sio_read_complete()").
> >
> > Replace set_page_dirty(), ClearPageReclaim() and end_page_writeback()
> > with folio_mark_dirty(), folio_clear_reclaim() and folio_end_writeback()
> > respectively, saving implicit calls to compound_head().
> >
> > Also replace page_swap_entry() with a direct folio->swap access since
> > bvec entries are always set via bvec_set_folio(), meaning bv_page is
> > always the head page.
> >
>
> This prompted AI review to look at sio_read_complete() and it didn't
> like what it saw.  Can you please check
> https://sashiko.dev/#/patchset/20260323170449.26333-1-devnexen@gmail.com?
>
> Also, mm.git is (over)full.  Can we please park the nice-to-have
> cleanups until after next -rc1?


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] mm/page_io: fix PSWPIN undercount for large folios in sio_read_complete()
  2026-03-23 17:04 [PATCH] mm/page_io: use folios in sio_write_complete() David Carlier
  2026-03-23 22:54 ` Andrew Morton
@ 2026-03-23 23:13 ` David Carlier
  1 sibling, 0 replies; 4+ messages in thread
From: David Carlier @ 2026-03-23 23:13 UTC (permalink / raw)
  To: Kairui Song, Chris Li, Andrew Morton, Kemeng Shi; +Cc: linux-mm, David Carlier

sio_read_complete() uses sio->pages to account global PSWPIN vm events,
but sio->pages tracks the number of bvec entries (folios), not base
pages. For large folios this undercounts compared to the per-memcg path
which correctly uses folio_nr_pages(), and compared to the bdev read
paths which also use folio_nr_pages().

Use sio->len >> PAGE_SHIFT instead, which gives the correct base page
count since sio->len is accumulated via folio_size(folio).

Fixes: 6a8c068774ad ("mm/page_io: use a folio in sio_read_complete()")
Signed-off-by: David Carlier <devnexen@gmail.com>
---
 mm/page_io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/page_io.c b/mm/page_io.c
index 63b262f4c5a9..1389cd57ca88 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -497,7 +497,7 @@ static void sio_read_complete(struct kiocb *iocb, long ret)
 			folio_mark_uptodate(folio);
 			folio_unlock(folio);
 		}
-		count_vm_events(PSWPIN, sio->pages);
+		count_vm_events(PSWPIN, sio->len >> PAGE_SHIFT);
 	} else {
 		for (p = 0; p < sio->pages; p++) {
 			struct folio *folio = page_folio(sio->bvec[p].bv_page);
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-03-23 23:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-23 17:04 [PATCH] mm/page_io: use folios in sio_write_complete() David Carlier
2026-03-23 22:54 ` Andrew Morton
2026-03-23 23:07   ` David CARLIER
2026-03-23 23:13 ` [PATCH] mm/page_io: fix PSWPIN undercount for large folios in sio_read_complete() David Carlier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox