include/net/netmem.h
Source file repositories/reference/linux-study-clean/include/net/netmem.h
File Facts
- System
- Linux kernel
- Corpus path
include/net/netmem.h- Extension
.h- Size
- 11863 bytes
- Lines
- 417
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/dma-mapping.hlinux/mm.hnet/net_debug.h
Detected Declarations
struct netmem_descstruct net_iovstruct net_iov_areaenum net_iov_typefunction net_iov_idxfunction net_iov_initfunction netmem_is_net_iovfunction netmem_to_pagefunction net_iov_to_netmemfunction virt_to_netmemfunction netmem_ref_countfunction netmem_pfn_tracefunction netmem_reffunction netmem_get_ppfunction netmem_is_pref_nidfunction netmem_compound_headfunction netmem_addressfunction netmem_is_pfmemallocfunction netmem_get_dma_addrfunction net_is_devmem_iovfunction net_is_devmem_iovfunction get_netmemfunction put_netmemfunction netmem_dma_unmap_page_attrs
Annotated Snippet
struct netmem_desc {
unsigned long _flags;
unsigned long pp_magic;
struct page_pool *pp;
unsigned long _pp_mapping_pad;
unsigned long dma_addr;
atomic_long_t pp_ref_count;
};
#define NETMEM_DESC_ASSERT_OFFSET(pg, desc) \
static_assert(offsetof(struct page, pg) == \
offsetof(struct netmem_desc, desc))
NETMEM_DESC_ASSERT_OFFSET(flags, _flags);
NETMEM_DESC_ASSERT_OFFSET(pp_magic, pp_magic);
NETMEM_DESC_ASSERT_OFFSET(pp, pp);
NETMEM_DESC_ASSERT_OFFSET(_pp_mapping_pad, _pp_mapping_pad);
NETMEM_DESC_ASSERT_OFFSET(dma_addr, dma_addr);
NETMEM_DESC_ASSERT_OFFSET(pp_ref_count, pp_ref_count);
#undef NETMEM_DESC_ASSERT_OFFSET
/*
* Since struct netmem_desc uses the space in struct page, the size
* should be checked, until struct netmem_desc has its own instance from
* slab, to avoid conflicting with other members within struct page.
*/
static_assert(sizeof(struct netmem_desc) <= offsetof(struct page, _refcount));
/* net_iov */
DECLARE_STATIC_KEY_FALSE(page_pool_mem_providers);
/* We overload the LSB of the struct page pointer to indicate whether it's
* a page or net_iov.
*/
#define NET_IOV 0x01UL
enum net_iov_type {
NET_IOV_DMABUF,
NET_IOV_IOURING,
};
/* A memory descriptor representing abstract networking I/O vectors,
* generally for non-pages memory that doesn't have its corresponding
* struct page and needs to be explicitly allocated through slab.
*
* net_iovs are allocated and used by networking code, and the size of
* the chunk is PAGE_SIZE.
*
* This memory can be any form of non-struct paged memory. Examples
* include imported dmabuf memory and imported io_uring memory. See
* net_iov_type for all the supported types.
*
* @pp_magic: pp field, similar to the one in struct page/struct
* netmem_desc.
* @pp: the pp this net_iov belongs to, if any.
* @dma_addr: the dma addrs of the net_iov. Needed for the network
* card to send/receive this net_iov.
* @pp_ref_count: the pp ref count of this net_iov, exactly the same
* usage as struct page/struct netmem_desc.
* @owner: the net_iov_area this net_iov belongs to, if any.
* @type: the type of the memory. Different types of net_iovs are
* supported.
*/
struct net_iov {
struct netmem_desc desc;
enum net_iov_type type;
struct net_iov_area *owner;
};
struct net_iov_area {
/* Array of net_iovs for this area. */
struct net_iov *niovs;
size_t num_niovs;
/* Offset into the dma-buf where this chunk starts. */
unsigned long base_virtual;
};
static inline struct net_iov_area *net_iov_owner(const struct net_iov *niov)
{
return niov->owner;
}
static inline unsigned int net_iov_idx(const struct net_iov *niov)
{
return niov - net_iov_owner(niov)->niovs;
}
/* Initialize a niov: stamp the owning area, the memory provider type.
*/
Annotation
- Immediate include surface: `linux/dma-mapping.h`, `linux/mm.h`, `net/net_debug.h`.
- Detected declarations: `struct netmem_desc`, `struct net_iov`, `struct net_iov_area`, `enum net_iov_type`, `function net_iov_idx`, `function net_iov_init`, `function netmem_is_net_iov`, `function netmem_to_page`, `function net_iov_to_netmem`, `function virt_to_netmem`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.