linux/include/net/netmem.h
Mina Almasry 4dec64c52e page_pool: convert to use netmem
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>
2024-07-02 18:59:33 -07:00

57 lines
1.4 KiB
C

/* SPDX-License-Identifier: GPL-2.0
*
* Network memory
*
* Author: Mina Almasry <almasrymina@google.com>
*/
#ifndef _NET_NETMEM_H
#define _NET_NETMEM_H
/**
* typedef netmem_ref - a nonexistent type marking a reference to generic
* network memory.
*
* A netmem_ref currently is always a reference to a struct page. This
* abstraction is introduced so support for new memory types can be added.
*
* Use the supplied helpers to obtain the underlying memory pointer and fields.
*/
typedef unsigned long __bitwise netmem_ref;
/* This conversion fails (returns NULL) if the netmem_ref is not struct page
* backed.
*
* Currently struct page is the only possible netmem, and this helper never
* fails.
*/
static inline struct page *netmem_to_page(netmem_ref netmem)
{
return (__force struct page *)netmem;
}
/* Converting from page to netmem is always safe, because a page can always be
* a netmem.
*/
static inline netmem_ref page_to_netmem(struct page *page)
{
return (__force netmem_ref)page;
}
static inline int netmem_ref_count(netmem_ref netmem)
{
return page_ref_count(netmem_to_page(netmem));
}
static inline unsigned long netmem_to_pfn(netmem_ref netmem)
{
return page_to_pfn(netmem_to_page(netmem));
}
static inline netmem_ref netmem_compound_head(netmem_ref netmem)
{
return page_to_netmem(compound_head(netmem_to_page(netmem)));
}
#endif /* _NET_NETMEM_H */