mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-09 23:39:18 +00:00
4dec64c52e
Abstract the memory type from the page_pool so we can later add support for new memory types. Convert the page_pool to use the new netmem type abstraction, rather than use struct page directly. As of this patch the netmem type is a no-op abstraction: it's always a struct page underneath. All the page pool internals are converted to use struct netmem instead of struct page, and the page pool now exports 2 APIs: 1. The existing struct page API. 2. The new struct netmem API. Keeping the existing API is transitional; we do not want to refactor all the current drivers using the page pool at once. The netmem abstraction is currently a no-op. The page_pool uses page_to_netmem() to convert allocated pages to netmem, and uses netmem_to_page() to convert the netmem back to pages to pass to mm APIs, Follow up patches to this series add non-paged netmem support to the page_pool. This change is factored out on its own to limit the code churn to this 1 patch, for ease of code review. Signed-off-by: Mina Almasry <almasrymina@google.com> Reviewed-by: Pavel Begunkov <asml.silence@gmail.com> Link: https://patch.msgid.link/20240628003253.1694510-6-almasrymina@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
76 lines
1.7 KiB
C
76 lines
1.7 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/*
|
|
* Skb ref helpers.
|
|
*
|
|
*/
|
|
|
|
#ifndef _LINUX_SKBUFF_REF_H
|
|
#define _LINUX_SKBUFF_REF_H
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
/**
|
|
* __skb_frag_ref - take an addition reference on a paged fragment.
|
|
* @frag: the paged fragment
|
|
*
|
|
* Takes an additional reference on the paged fragment @frag.
|
|
*/
|
|
static inline void __skb_frag_ref(skb_frag_t *frag)
|
|
{
|
|
get_page(skb_frag_page(frag));
|
|
}
|
|
|
|
/**
|
|
* skb_frag_ref - take an addition reference on a paged fragment of an skb.
|
|
* @skb: the buffer
|
|
* @f: the fragment offset.
|
|
*
|
|
* Takes an additional reference on the @f'th paged fragment of @skb.
|
|
*/
|
|
static inline void skb_frag_ref(struct sk_buff *skb, int f)
|
|
{
|
|
__skb_frag_ref(&skb_shinfo(skb)->frags[f]);
|
|
}
|
|
|
|
bool napi_pp_put_page(netmem_ref netmem);
|
|
|
|
static inline void
|
|
skb_page_unref(struct page *page, bool recycle)
|
|
{
|
|
#ifdef CONFIG_PAGE_POOL
|
|
if (recycle && napi_pp_put_page(page_to_netmem(page)))
|
|
return;
|
|
#endif
|
|
put_page(page);
|
|
}
|
|
|
|
/**
|
|
* __skb_frag_unref - release a reference on a paged fragment.
|
|
* @frag: the paged fragment
|
|
* @recycle: recycle the page if allocated via page_pool
|
|
*
|
|
* Releases a reference on the paged fragment @frag
|
|
* or recycles the page via the page_pool API.
|
|
*/
|
|
static inline void __skb_frag_unref(skb_frag_t *frag, bool recycle)
|
|
{
|
|
skb_page_unref(skb_frag_page(frag), recycle);
|
|
}
|
|
|
|
/**
|
|
* skb_frag_unref - release a reference on a paged fragment of an skb.
|
|
* @skb: the buffer
|
|
* @f: the fragment offset
|
|
*
|
|
* Releases a reference on the @f'th paged fragment of @skb.
|
|
*/
|
|
static inline void skb_frag_unref(struct sk_buff *skb, int f)
|
|
{
|
|
struct skb_shared_info *shinfo = skb_shinfo(skb);
|
|
|
|
if (!skb_zcopy_managed(skb))
|
|
__skb_frag_unref(&shinfo->frags[f], skb->pp_recycle);
|
|
}
|
|
|
|
#endif /* _LINUX_SKBUFF_REF_H */
|