From: Vishwanath Seshagiri <vishs@meta.com>
To: "Michael S . Tsirkin" <mst@redhat.com>, Jason Wang <jasowang@redhat.com>
Cc: "Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"Andrew Lunn" <andrew+netdev@lunn.ch>,
"David S . Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>, "David Wei" <dw@davidwei.uk>,
"Matteo Croce" <technoboy85@gmail.com>,
"Ilias Apalodimas" <ilias.apalodimas@linaro.org>,
netdev@vger.kernel.org, virtualization@lists.linux.dev,
linux-kernel@vger.kernel.org, kernel-team@meta.com
Subject: [PATCH net-next v5 1/2] page_pool: add page_pool_frag_offset_add() helper
Date: Thu, 5 Feb 2026 16:27:14 -0800 [thread overview]
Message-ID: <20260206002715.1885869-2-vishs@meta.com> (raw)
In-Reply-To: <20260206002715.1885869-1-vishs@meta.com>
Add a helper function to advance the fragment offset without performing
an allocation. This is needed by drivers that extend a buffer to consume
unused space at the end of a page fragment to avoid internal fragmentation.
When a driver uses page_pool_alloc_frag() and determines that the
remaining space in the page is too small for another buffer, it may
extend the current buffer to include that space. However, page_pool's
internal frag_offset is not aware of this extension, which could cause
the next allocation to overlap with the extended buffer.
page_pool_frag_offset_add() allows drivers to advance frag_offset to
match the actual consumed space.
Signed-off-by: Vishwanath Seshagiri <vishs@meta.com>
---
include/net/page_pool/helpers.h | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helpers.h
index 3247026e096a..14907c3badae 100644
--- a/include/net/page_pool/helpers.h
+++ b/include/net/page_pool/helpers.h
@@ -96,6 +96,26 @@ static inline struct page *page_pool_dev_alloc_pages(struct page_pool *pool)
return page_pool_alloc_pages(pool, gfp);
}
+/**
+ * page_pool_frag_offset_add() - advance fragment offset without allocation
+ * @pool: pool to update
+ * @bytes: number of bytes to skip
+ *
+ * Advance the fragment offset by @bytes without performing an allocation.
+ * This is useful when a driver extends a buffer to consume unused space
+ * at the end of a page fragment (to avoid internal fragmentation), and
+ * needs to ensure the next allocation doesn't overlap.
+ *
+ * Must be called in the same context as page_pool_alloc_frag() to avoid
+ * racing with fragment allocations.
+ *
+ */
+static inline void page_pool_frag_offset_add(struct page_pool *pool,
+ unsigned int bytes)
+{
+ pool->frag_offset += bytes;
+}
+
/**
* page_pool_dev_alloc_frag() - allocate a page fragment.
* @pool: pool from which to allocate
--
2.47.3
next prev parent reply other threads:[~2026-02-06 0:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-06 0:27 [PATCH net-next v5 0/2] virtio_net: add page_pool support Vishwanath Seshagiri
2026-02-06 0:27 ` Vishwanath Seshagiri [this message]
2026-02-06 0:27 ` [PATCH net-next v5 2/2] virtio_net: add page_pool support for buffer allocation Vishwanath Seshagiri
2026-02-07 4:41 ` Jakub Kicinski
2026-02-07 5:25 ` Vishwanath Seshagiri
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260206002715.1885869-2-vishs@meta.com \
--to=vishs@meta.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=dw@davidwei.uk \
--cc=edumazet@google.com \
--cc=eperezma@redhat.com \
--cc=ilias.apalodimas@linaro.org \
--cc=jasowang@redhat.com \
--cc=kernel-team@meta.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=technoboy85@gmail.com \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox