Re: [PATCH v2] mm/page_io: fix PSWPIN undercount for large folios in sio_read_complete()

From: Andrew Morton

Date: Mon Mar 30 2026 - 18:29:51 EST


On Mon, 30 Mar 2026 08:12:29 +0100 David Carlier <devnexen@xxxxxxxxx> wrote:

> 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).

Thanks. What are the userspace-visible runtime effects of the bug?
Just /proc/vmstat wrongness?

Seems pretty minor, and it's been in there for several years. But I
guess I'll slip a cc:stable in there, let it trickle back at a later
time.

> --- 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
>