[PATCH] io_uring/net: don't charge the folio offset to truesize for managed frags
From: Louis Thiery
Date: Thu Nov 19 2026 - 18:30:31 EST
Registered buffers backed by huge pages are coalesced into one bvec per
folio, so bv_offset is relative to the folio, not to a 4K page.
io_sg_from_iter() adds PAGE_ALIGN(bv_len + bv_offset) to the skb
truesize, which charges the socket for the whole run-up inside the
folio. A 64K send from 1.5MB into a 2MB THP folio adds about 1.6MB of
truesize, and sk_wmem_queued fills long before any real memory is used.
The visible effect is a socket that looks full: with a 2MB send buffer
only 4 of 128 queued 64K sends complete before the sender blocks,
versus 30 of 128 with the same buffer registered as 4K pages, and most
pipelined send_zc requests come back short.
Only the in-page part of the offset matters for how much memory a
fragment ties up, so use offset_in_page(). This matches what
zerocopy_fill_skb_from_iter() charges for the same data.
Fixes: 57bebf807e2a ("io_uring/rsrc: optimise registered huge pages")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Louis Thiery <thiery.louis@xxxxxxxxx>
---
io_uring/net.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/io_uring/net.c b/io_uring/net.c
index 533afd335..8afad1b2d 100644
--- a/io_uring/net.c
+++ b/io_uring/net.c
@@ -1501,7 +1501,12 @@ static int io_sg_from_iter(struct sk_buff *skb,
struct bio_vec v = mp_bvec_iter_bvec(from->bvec, bi);
copied += v.bv_len;
- truesize += PAGE_ALIGN(v.bv_len + v.bv_offset);
+ /*
+ * bv_offset is relative to the folio for coalesced huge page
+ * registrations, so only the in-page part of it matters for
+ * how much memory this fragment ties up.
+ */
+ truesize += PAGE_ALIGN(v.bv_len + offset_in_page(v.bv_offset));
__skb_fill_page_desc_noacc(shinfo, frag++, v.bv_page,
v.bv_offset, v.bv_len);
bvec_iter_advance_single(from->bvec, &bi, v.bv_len);
base-commit: 0659e44ce739ecd856164c75a5325b7959a2921d
--
2.43.0