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 <[email protected]> --- 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

