From: David Carlier Date: Thu, 2 Apr 2026 06:14:07 +0000 (+0100) Subject: mm/page_io: use sio->len for PSWPIN accounting in sio_read_complete() X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=df620ec4d4d703f11f3b0adecd4450c34489e0f1;p=thirdparty%2Fkernel%2Flinux.git mm/page_io: use sio->len for PSWPIN accounting in sio_read_complete() 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. While large folios cannot currently reach this path (SWP_FS_OPS and SWP_SYNCHRONOUS_IO are mutually exclusive, and mTHP swap-in allocation is gated on SWP_SYNCHRONOUS_IO), the accounting is semantically inconsistent with the per-memcg path which correctly uses 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). Link: https://lore.kernel.org/20260402061408.36119-1-devnexen@gmail.com Signed-off-by: David Carlier Acked-by: David Hildenbrand (Arm) Cc: Baoquan He Cc: Chris Li Cc: Kairui Song Cc: Kemeng Shi Cc: NeilBrown Cc: Nhat Pham Signed-off-by: Andrew Morton --- diff --git a/mm/page_io.c b/mm/page_io.c index 93d03d9e2a6a..70cea9e24d2f 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);