Split netmem from struct page
Subsystems (14)
cover Split netmem from struct page
The MM subsystem is trying to reduce struct page to a single pointer. The first step towards that is splitting struct page by its individual users, as has already been done with folio and slab. This patchset does that for netmem which is used for page pools.
Matthew Wilcox tried and stopped the same work, you can see in:
https://lore.kernel.org/linux-mm/[email protected]/
Mina Almasry already has done a lot fo prerequisite works by luck, he said :). I stacked my patches on the top of his work e.i. netmem.
I focused on removing the page pool members in struct page this time, not moving the allocation code of page pool from net to mm. It can be done later if needed.
There are still a lot of works to do, to remove the dependency on struct page in the network subsystem. I will continue to work on this after this base patchset is merged.
This patchset is based on mm tree's mm-unstable branch.
Byungchul Park (19):
netmem: rename struct net_iov to struct netmem_desc
netmem: introduce netmem alloc/put API to wrap page alloc/put API
page_pool: use netmem alloc/put API in __page_pool_alloc_page_order()
page_pool: rename __page_pool_alloc_page_order() to
__page_pool_alloc_large_netmem()
page_pool: use netmem alloc/put API in __page_pool_alloc_pages_slow()
page_pool: rename page_pool_return_page() to page_pool_return_netmem()
page_pool: use netmem alloc/put API in page_pool_return_netmem()
page_pool: rename __page_pool_release_page_dma() to
__page_pool_release_netmem_dma()
page_pool: rename __page_pool_put_page() to __page_pool_put_netmem()
page_pool: rename __page_pool_alloc_pages_slow() to
__page_pool_alloc_netmems_slow()
mlx4: use netmem descriptor and API for page pool
netmem: introduce page_pool_recycle_direct_netmem()
page_pool: expand scope of is_pp_{netmem,page}() to global
mm: page_alloc: do not directly access page->pp_magic but use
is_pp_page()
mlx5: use netmem descriptor and API for page pool
netmem: use _Generic to cover const casting for page_to_netmem()
netmem: remove __netmem_get_pp()
page_pool: make page_pool_get_dma_addr() just wrap
page_pool_get_dma_addr_netmem()
mm, netmem: remove the page pool members in struct page
drivers/net/ethernet/mellanox/mlx4/en_rx.c | 46 ++++---- drivers/net/ethernet/mellanox/mlx4/en_tx.c | 8 +- drivers/net/ethernet/mellanox/mlx4/mlx4_en.h | 4 +- drivers/net/ethernet/mellanox/mlx5/core/en.h | 4 +- .../net/ethernet/mellanox/mlx5/core/en/xdp.c | 18 +-- .../net/ethernet/mellanox/mlx5/core/en/xdp.h | 2 +- .../net/ethernet/mellanox/mlx5/core/en_main.c | 15 ++- .../net/ethernet/mellanox/mlx5/core/en_rx.c | 66 +++++------ include/linux/mm_types.h | 13 +-- include/linux/skbuff.h | 18 ++- include/net/netmem.h | 88 +++++---------- include/net/netmem_type.h | 22 ++++ include/net/page_pool/helpers.h | 17 ++- include/net/page_pool/memory_provider.h | 6 +- include/net/page_pool/types.h | 2 + io_uring/zcrx.c | 42 +++---- mm/page_alloc.c | 5 +- net/core/devmem.c | 14 +-- net/core/devmem.h | 24 ++-- net/core/page_pool.c | 106 ++++++++++-------- net/core/skbuff.c | 5 - net/ipv4/tcp.c | 2 +- 22 files changed, 272 insertions(+), 255 deletions(-) create mode 100644 include/net/netmem_type.h
base-commit: fd93b3350b4314eebd8fbf0fea3ca7fe48d777e3
Signature · 1 line
2.17.1
RFC 1/19 netmem: rename struct net_iov to struct netmem_desc
To simplify struct page, the page pool members of struct page should be moved to other, allowing these members to be removed from struct page.
Reuse struct net_iov for also system memory, that already mirrored the page pool members.
--- include/linux/skbuff.h | 4 +-- include/net/netmem.h | 20 ++++++------ include/net/page_pool/memory_provider.h | 6 ++-- io_uring/zcrx.c | 42 ++++++++++++------------- net/core/devmem.c | 14 ++++----- net/core/devmem.h | 24 +++++++------- net/core/page_pool.c | 6 ++-- net/ipv4/tcp.c | 2 +- 8 files changed, 59 insertions(+), 59 deletions(-)
include/linux/skbuff.h +2 -2
@@ -3598,10 +3598,10 @@ static inline bool skb_frag_is_net_iov(const skb_frag_t *frag)* skb_frag_net_iov - retrieve the net_iov referred to by fragment * @frag: the fragment * -* Return: the &struct net_iov associated with @frag. Returns NULL if this +* Return: the &struct netmem_desc associated with @frag. Returns NULL if this * frag has no associated net_iov. */ -static inline struct net_iov *skb_frag_net_iov (const skb_frag_t *frag) +static inline struct netmem_desc *skb_frag_net_iov (const skb_frag_t *frag) {if (!skb_frag_is_net_iov (frag))return NULL ;
include/net/netmem.h +10 -10
@@ -20,7 +20,7 @@ DECLARE_STATIC_KEY_FALSE(page_pool_mem_providers);*/ #define NET_IOV 0x01UL -struct net_iov { +struct netmem_desc {unsigned long __unused_padding;unsigned long pp_magic;struct page_pool *pp;
@@ -31,7 +31,7 @@ struct net_iov {struct net_iov_area {/* Array of net_iovs for this area. */ -struct net_iov *niovs; +struct netmem_desc *niovs;size_t num_niovs;/* Offset into the dma-buf where this chunk starts. */
@@ -56,19 +56,19 @@ struct net_iov_area {*/ #define NET_IOV_ASSERT_OFFSET (pg, iov) \ static_assert(offsetof(struct page, pg) == \ - offsetof(struct net_iov, iov)) + offsetof(struct netmem_desc, iov))NET_IOV_ASSERT_OFFSET (pp_magic, pp_magic);NET_IOV_ASSERT_OFFSET (pp, pp);NET_IOV_ASSERT_OFFSET (dma_addr, dma_addr);NET_IOV_ASSERT_OFFSET (pp_ref_count, pp_ref_count);#undef NET_IOV_ASSERT_OFFSET -static inline struct net_iov_area *net_iov_owner (const struct net_iov *niov) +static inline struct net_iov_area *net_iov_owner (const struct netmem_desc *niov) {return niov->owner; } -static inline unsigned int net_iov_idx (const struct net_iov *niov) +static inline unsigned int net_iov_idx (const struct netmem_desc *niov) {return niov -net_iov_owner (niov)->niovs; }
@@ -118,17 +118,17 @@ static inline struct page *netmem_to_page(netmem_ref netmem)return __netmem_to_page (netmem); } -static inline struct net_iov *netmem_to_net_iov (netmem_ref netmem) +static inline struct netmem_desc *netmem_to_net_iov (netmem_ref netmem) {if (netmem_is_net_iov (netmem)) -return (struct net_iov *)((__force unsigned long )netmem & +return (struct netmem_desc *)((__force unsigned long )netmem & ~NET_IOV );DEBUG_NET_WARN_ON_ONCE (true);return NULL ; } -static inline netmem_ref net_iov_to_netmem (struct net_iov *niov) +static inline netmem_ref net_iov_to_netmem (struct netmem_desc *niov) {return (__force netmem_ref)((unsigned long )niov |NET_IOV ); }
@@ -168,9 +168,9 @@ static inline unsigned long netmem_pfn_trace(netmem_ref netmem)return page_to_pfn (netmem_to_page (netmem)); } -static inline struct net_iov *__netmem_clear_lsb (netmem_ref netmem) +static inline struct netmem_desc *__netmem_clear_lsb (netmem_ref netmem) { -return (struct net_iov *)((__force unsigned long )netmem & ~NET_IOV ); +return (struct netmem_desc *)((__force unsigned long )netmem & ~NET_IOV ); }/**
include/net/page_pool/memory_provider.h +3 -3
@@ -19,9 +19,9 @@ struct memory_provider_ops {void (*uninstall)(void *mp_priv,struct netdev_rx_queue *rxq); }; -bool net_mp_niov_set_dma_addr (struct net_iov *niov,dma_addr_t addr); -void net_mp_niov_set_page_pool (struct page_pool *pool,struct net_iov *niov); -void net_mp_niov_clear_page_pool (struct net_iov *niov); +bool net_mp_niov_set_dma_addr (struct netmem_desc *niov,dma_addr_t addr); +void net_mp_niov_set_page_pool (struct page_pool *pool,struct netmem_desc *niov); +void net_mp_niov_clear_page_pool (struct netmem_desc *niov);int net_mp_open_rxq (struct net_device *dev,unsigned ifq_idx,struct pp_memory_provider_params *p);
io_uring/zcrx.c +21 -21
161 lines not on this page · raw message
net/core/devmem.c +7 -7
@@ -28,7 +28,7 @@ static DEFINE_XARRAY_FLAGS(net_devmem_dmabuf_bindings, XA_FLAGS_ALLOC1);static const struct memory_provider_ops dmabuf_devmem_ops; -bool net_is_devmem_iov (struct net_iov *niov) +bool net_is_devmem_iov (struct netmem_desc *niov) {return niov->pp->mp_ops == &dmabuf_devmem_ops; }
@@ -43,7 +43,7 @@ static void net_devmem_dmabuf_free_chunk_owner(struct gen_pool *genpool,kfree (owner); } -static dma_addr_t net_devmem_get_dma_addr (const struct net_iov *niov) +static dma_addr_t net_devmem_get_dma_addr (const struct netmem_desc *niov) {struct dmabuf_genpool_chunk_owner *owner;
@@ -74,12 +74,12 @@ void __net_devmem_dmabuf_binding_free(struct net_devmem_dmabuf_binding *binding)kfree (binding); } -struct net_iov * +struct netmem_desc *net_devmem_alloc_dmabuf (struct net_devmem_dmabuf_binding *binding) {struct dmabuf_genpool_chunk_owner *owner;unsigned long dma_addr; -struct net_iov *niov; +struct netmem_desc *niov;ssize_t offset;ssize_t index;
@@ -99,7 +99,7 @@ net_devmem_alloc_dmabuf(struct net_devmem_dmabuf_binding *binding)return niov; } -void net_devmem_free_dmabuf (struct net_iov *niov) +void net_devmem_free_dmabuf (struct netmem_desc *niov) {struct net_devmem_dmabuf_binding *binding =net_devmem_iov_binding (niov);unsigned long dma_addr =net_devmem_get_dma_addr (niov);
@@ -233,7 +233,7 @@ net_devmem_bind_dmabuf(struct net_device *dev, unsigned int dmabuf_fd,dma_addr_t dma_addr =sg_dma_address (sg);struct dmabuf_genpool_chunk_owner *owner;size_t len =sg_dma_len (sg); -struct net_iov *niov; +struct netmem_desc *niov; owner =kzalloc_node (sizeof (*owner),GFP_KERNEL ,dev_to_node (&dev->dev));
@@ -319,7 +319,7 @@ int mp_dmabuf_devmem_init(struct page_pool *pool)netmem_ref mp_dmabuf_devmem_alloc_netmems (struct page_pool *pool,gfp_t gfp) {struct net_devmem_dmabuf_binding *binding = pool->mp_priv; -struct net_iov *niov; +struct netmem_desc *niov;netmem_ref netmem; niov =net_devmem_alloc_dmabuf (binding);
net/core/devmem.h +12 -12
@@ -70,7 +70,7 @@ int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx, struct netlink_ext_ack *extack);static inline struct dmabuf_genpool_chunk_owner * -net_devmem_iov_to_chunk_owner (const struct net_iov *niov) +net_devmem_iov_to_chunk_owner (const struct netmem_desc *niov) {struct net_iov_area *owner =net_iov_owner (niov);
@@ -78,17 +78,17 @@ net_devmem_iov_to_chunk_owner(const struct net_iov *niov) }static inline struct net_devmem_dmabuf_binding * -net_devmem_iov_binding (const struct net_iov *niov) +net_devmem_iov_binding (const struct netmem_desc *niov) {return net_devmem_iov_to_chunk_owner (niov)->binding; } -static inline u32 net_devmem_iov_binding_id (const struct net_iov *niov) +static inline u32 net_devmem_iov_binding_id (const struct netmem_desc *niov) {return net_devmem_iov_binding (niov)->id; } -static inline unsigned long net_iov_virtual_addr (const struct net_iov *niov) +static inline unsigned long net_iov_virtual_addr (const struct netmem_desc *niov) {struct net_iov_area *owner =net_iov_owner (niov);
@@ -111,11 +111,11 @@ net_devmem_dmabuf_binding_put(struct net_devmem_dmabuf_binding *binding) __net_devmem_dmabuf_binding_free(binding); } -struct net_iov * +struct netmem_desc *net_devmem_alloc_dmabuf (struct net_devmem_dmabuf_binding *binding); -void net_devmem_free_dmabuf (struct net_iov *ppiov); +void net_devmem_free_dmabuf (struct netmem_desc *ppiov); -bool net_is_devmem_iov (struct net_iov *niov); +bool net_is_devmem_iov (struct netmem_desc *niov);#else struct net_devmem_dmabuf_binding ;
@@ -146,27 +146,27 @@ net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,return -EOPNOTSUPP ; } -static inline struct net_iov * +static inline struct netmem_desc *net_devmem_alloc_dmabuf (struct net_devmem_dmabuf_binding *binding) {return NULL ; } -static inline void net_devmem_free_dmabuf (struct net_iov *ppiov) +static inline void net_devmem_free_dmabuf (struct netmem_desc *ppiov) { } -static inline unsigned long net_iov_virtual_addr (const struct net_iov *niov) +static inline unsigned long net_iov_virtual_addr (const struct netmem_desc *niov) {return 0 ; } -static inline u32 net_devmem_iov_binding_id (const struct net_iov *niov) +static inline u32 net_devmem_iov_binding_id (const struct netmem_desc *niov) {return 0 ; } -static inline bool net_is_devmem_iov (struct net_iov *niov) +static inline bool net_is_devmem_iov (struct netmem_desc *niov) {return false; }
net/core/page_pool.c +3 -3
@@ -1198,7 +1198,7 @@ void page_pool_update_nid(struct page_pool *pool, int new_nid) }EXPORT_SYMBOL (page_pool_update_nid); -bool net_mp_niov_set_dma_addr (struct net_iov *niov,dma_addr_t addr) +bool net_mp_niov_set_dma_addr (struct netmem_desc *niov,dma_addr_t addr) {return page_pool_set_dma_addr_netmem (net_iov_to_netmem (niov), addr); }
@@ -1206,7 +1206,7 @@ bool net_mp_niov_set_dma_addr(struct net_iov *niov, dma_addr_t addr)/* Associate a niov with a page pool. Should follow with a matching * net_mp_niov_clear_page_pool() */ -void net_mp_niov_set_page_pool (struct page_pool *pool,struct net_iov *niov) +void net_mp_niov_set_page_pool (struct page_pool *pool,struct netmem_desc *niov) {netmem_ref netmem =net_iov_to_netmem (niov);
@@ -1219,7 +1219,7 @@ void net_mp_niov_set_page_pool(struct page_pool *pool, struct net_iov *niov)/* Disassociate a niov from a page pool. Should only be used in the * ->release_netmem() path. */ -void net_mp_niov_clear_page_pool (struct net_iov *niov) +void net_mp_niov_clear_page_pool (struct netmem_desc *niov) {netmem_ref netmem =net_iov_to_netmem (niov);
net/ipv4/tcp.c +1 -1
@@ -2483,7 +2483,7 @@ static int tcp_recvmsg_dmabuf(struct sock *sk, const struct sk_buff *skb,*/ for (i =0 ; i <skb_shinfo (skb)->nr_frags; i++) {skb_frag_t *frag = &skb_shinfo (skb)->frags[i]; -struct net_iov *niov; +struct netmem_desc *niov;u64 frag_offset;int end;
Signature · 1 line
2.17.1
Pavel Begunkov
maintainerRe: [RFC 01/19] netmem: rename struct net_iov to struct netmem_desc
Quoted 6 lines · Byungchul Park
To simplify struct page, the page pool members of struct page should be moved to other, allowing these members to be removed from struct page.
Reuse struct
net_iovfor also system memory, that already mirrored the page pool members.
Quoted 6 lines
Signed-off-by Byungchul Park <[email protected]>--- include/linux/skbuff.h | 4 +-- include/net/netmem.h | 20 ++++++------ include/net/page_pool/memory_provider.h | 6 ++-- io_uring/zcrx.c | 42 ++++++++++++-------------
You're unnecessarily complicating it for yourself. It'll certainly conflict with changes in the io_uring tree, and hence it can't be taken normally through the net tree.
Why are you renaming it in the first place? If there are good reasons, maybe you can try adding a temporary alias of the struct and patch io_uring later separately.
Signature · 1 line
Pavel Begunkov
Re: [RFC 01/19] netmem: rename struct net_iov to struct netmem_desc
Quoted 14 lines · Pavel Begunkov
Quoted 6 lines · Byungchul Park
To simplify struct page, the page pool members of struct page should be moved to other, allowing these members to be removed from struct page.
Reuse struct
net_iovfor also system memory, that already mirrored the page pool members.Quoted 6 lines
Signed-off-by Byungchul Park <[email protected]>--- include/linux/skbuff.h | 4 +-- include/net/netmem.h | 20 ++++++------ include/net/page_pool/memory_provider.h | 6 ++-- io_uring/zcrx.c | 42 ++++++++++++-------------
Quoted 5 lines
You're unnecessarily complicating it for yourself. It'll certainly conflict with changes in the
io_uringtree, and hence it can't be taken normally through the net tree.Why are you renaming it in the first place? If there are good
It's because the struct should be used for not only io vetor things but also system memory. Current network code uses struct page as system memory descriptor but struct page fields for page pool will be gone.
So I had to reuse struct net_iov and I thought renaming it made more sense. It'd be welcome if you have better idea.
Byungchul
Quoted 6 lines
reasons, maybe you can try adding a temporary alias of the struct and patch
io_uringlater separately.Signature · 1 line
Pavel Begunkov
Re: [RFC 01/19] netmem: rename struct net_iov to struct netmem_desc
Quoted 20 lines · Byungchul Park
Quoted 18 lines · Pavel Begunkov
Quoted 6 lines · Byungchul Park
To simplify struct page, the page pool members of struct page should be moved to other, allowing these members to be removed from struct page.
Reuse struct
net_iovfor also system memory, that already mirrored the page pool members.Quoted 6 lines
Signed-off-by Byungchul Park <[email protected]>--- include/linux/skbuff.h | 4 +-- include/net/netmem.h | 20 ++++++------ include/net/page_pool/memory_provider.h | 6 ++-- io_uring/zcrx.c | 42 ++++++++++++-------------You're unnecessarily complicating it for yourself. It'll certainly conflict with changes in the
io_uringtree, and hence it can't be taken normally through the net tree.
Quoted 9 lines
Quoted 1 line
Why are you renaming it in the first place? If there are good
It's because the struct should be used for not only io vetor things but also system memory. Current network code uses struct page as system memory descriptor but struct page fields for page pool will be gone.
So I had to reuse struct
net_iovand I thought renaming it made more sense. It'd be welcome if you have better idea.
As I said in another thread, struct page should not embed struct net_iov as-is. struct net_iov already has fields that are unrelated to page (like net_iov_owner) and more will be added in the future.
I think what Matthew seems to agree with AFAIU in the other thread is creating a new struct, struct netmem_desc, and having struct net_iov embed netmem_desc.
Signature · 2 lines
Thanks, Mina
Re: [RFC 01/19] netmem: rename struct net_iov to struct netmem_desc
Quoted 27 lines · Mina Almasry
Quoted 26 lines · Byungchul Park
Quoted 14 lines · Pavel Begunkov
Quoted 6 lines · Byungchul Park
To simplify struct page, the page pool members of struct page should be moved to other, allowing these members to be removed from struct page.
Reuse struct
net_iovfor also system memory, that already mirrored the page pool members.Quoted 6 lines
Signed-off-by Byungchul Park <[email protected]>--- include/linux/skbuff.h | 4 +-- include/net/netmem.h | 20 ++++++------ include/net/page_pool/memory_provider.h | 6 ++-- io_uring/zcrx.c | 42 ++++++++++++-------------Quoted 5 lines
You're unnecessarily complicating it for yourself. It'll certainly conflict with changes in the
io_uringtree, and hence it can't be taken normally through the net tree.Why are you renaming it in the first place? If there are good
It's because the struct should be used for not only io vetor things but also system memory. Current network code uses struct page as system memory descriptor but struct page fields for page pool will be gone.
Quoted 5 lines
Quoted 3 lines
So I had to reuse struct
net_iovand I thought renaming it made more sense. It'd be welcome if you have better idea.As I said in another thread, struct page should not embed struct
I don't understand here. Can you explain more? Do you mean do not use place holder?
Quoted 6 lines
net_iovas-is. structnet_iovalready has fields that are unrelated to page (likenet_iov_owner) and more will be added in the future.I think what Matthew seems to agree with AFAIU in the other thread is creating a new struct, struct
netmem_desc, and having structnet_iovembednetmem_desc.
This would look better. I will try.
Byungchul
Quoted 3 lines
Signature · 2 lines
Thanks, Mina
Pavel Begunkov
maintainerRe: [RFC 01/19] netmem: rename struct net_iov to struct netmem_desc
Quoted 28 lines · Byungchul Park
Quoted 27 lines · Mina Almasry
Quoted 26 lines · Byungchul Park
Quoted 14 lines · Pavel Begunkov
Quoted 6 lines · Byungchul Park
To simplify struct page, the page pool members of struct page should be moved to other, allowing these members to be removed from struct page.
Reuse struct
net_iovfor also system memory, that already mirrored the page pool members.Quoted 6 lines
Signed-off-by Byungchul Park <[email protected]>--- include/linux/skbuff.h | 4 +-- include/net/netmem.h | 20 ++++++------ include/net/page_pool/memory_provider.h | 6 ++-- io_uring/zcrx.c | 42 ++++++++++++-------------Quoted 5 lines
You're unnecessarily complicating it for yourself. It'll certainly conflict with changes in the
io_uringtree, and hence it can't be taken normally through the net tree.Why are you renaming it in the first place? If there are good
It's because the struct should be used for not only io vetor things but also system memory. Current network code uses struct page as system memory descriptor but struct page fields for page pool will be gone.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
So I had to reuse struct
net_iovand I thought renaming it made more sense. It'd be welcome if you have better idea.As I said in another thread, struct page should not embed struct
I don't understand here. Can you explain more? Do you mean do not use place holder?
I assume this:
struct netmem_desc {
...
};struct net_iov {
netmem_desc desc;
};struct page {
union {
// eventually will go away
netmem_desc desc;
...
};
};And to avoid conflicts with io_uring, you can send something like the following to the net tree, and finish the io_uring conversion later.
struct net_iov {
struct_group_tagged(netmem_desc, desc,
...
);
};Signature · 1 line
Pavel Begunkov
Pavel Begunkov
maintainerRe: [RFC 01/19] netmem: rename struct net_iov to struct netmem_desc
In reply to Byungchul ParkQuoted 15 lines · Byungchul Park
Quoted 14 lines · Pavel Begunkov
Quoted 12 lines · Byungchul Park
To simplify struct page, the page pool members of struct page should be moved to other, allowing these members to be removed from struct page.
Reuse struct
net_iovfor also system memory, that already mirrored the page pool members.Signed-off-by Byungchul Park <[email protected]>--- include/linux/skbuff.h | 4 +-- include/net/netmem.h | 20 ++++++------ include/net/page_pool/memory_provider.h | 6 ++-- io_uring/zcrx.c | 42 ++++++++++++-------------
Quoted 8 lines
Quoted 5 lines
You're unnecessarily complicating it for yourself. It'll certainly conflict with changes in the
io_uringtree, and hence it can't be taken normally through the net tree.Why are you renaming it in the first place? If there are good
It's because the struct should be used for not only io vetor things but also system memory. Current network code uses struct page as system
Not sure what you mean by "io vector things", but it can already point to system memory, and if anything, the use conceptually more resembles struct pages rather than iovec. IOW, it's just a name, neither gives a perfect understanding until you look up details, so you could just leave it net_iov. Or follow what Mina suggested, I like that option.
Quoted 4 lines
memory descriptor but struct page fields for page pool will be gone.
So I had to reuse struct
net_iovand I thought renaming it made more sense. It'd be welcome if you have better idea.
Signature · 1 line
Pavel Begunkov
Re: [RFC 01/19] netmem: rename struct net_iov to struct netmem_desc
Quoted 25 lines · Pavel Begunkov
Quoted 15 lines · Byungchul Park
Quoted 14 lines · Pavel Begunkov
Quoted 12 lines · Byungchul Park
To simplify struct page, the page pool members of struct page should be moved to other, allowing these members to be removed from struct page.
Reuse struct
net_iovfor also system memory, that already mirrored the page pool members.Signed-off-by Byungchul Park <[email protected]>--- include/linux/skbuff.h | 4 +-- include/net/netmem.h | 20 ++++++------ include/net/page_pool/memory_provider.h | 6 ++-- io_uring/zcrx.c | 42 ++++++++++++-------------Quoted 8 lines
Quoted 5 lines
You're unnecessarily complicating it for yourself. It'll certainly conflict with changes in the
io_uringtree, and hence it can't be taken normally through the net tree.Why are you renaming it in the first place? If there are good
It's because the struct should be used for not only io vetor things but also system memory. Current network code uses struct page as system
Quoted 6 lines
Not sure what you mean by "io vector things", but it can already point to system memory, and if anything, the use conceptually more resembles struct pages rather than iovec. IOW, it's just a name, neither gives a perfect understanding until you look up details, so you could just leave it
net_iov. Or follow what Mina suggested, I like that option.
I appreciate all of your feedback and will try to apply them.
Byungchul
Quoted 6 lines
Quoted 4 lines
memory descriptor but struct page fields for page pool will be gone.
So I had to reuse struct
net_iovand I thought renaming it made more sense. It'd be welcome if you have better idea.Signature · 1 line
Pavel Begunkov
RFC 2/19 netmem: introduce netmem alloc/put API to wrap page alloc/put API
In reply to Byungchul ParkTo eliminate the use of struct page in page pool, the page pool code should use netmem descriptor and API instead.
As part of the work, introduce netmem alloc/put API allowing the code to use them rather than struct page things.
--- include/net/netmem.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
include/net/netmem.h +18 -0
@@ -138,6 +138,24 @@ static inline netmem_ref page_to_netmem(struct page *page)return (__force netmem_ref )page; } +static inline netmem_ref alloc_netmems_node (int nid,gfp_t gfp_mask, +unsigned int order) +{ +return page_to_netmem (alloc_pages_node (nid, gfp_mask, order)); +} + +static inline unsigned long alloc_netmems_bulk_node (gfp_t gfp,int nid, +unsigned long nr_netmems,netmem_ref *netmem_array) +{ +return alloc_pages_bulk_node (gfp, nid, nr_netmems, + (struct page **)netmem_array); +} + +static inline void put_netmem (netmem_ref netmem) +{ +put_page (netmem_to_page (netmem)); +} +/** * virt_to_netmem - convert virtual memory pointer to a netmem reference * @data: host memory pointer to convert
Signature · 1 line
2.17.1
Re: [RFC 02/19] netmem: introduce netmem alloc/put API to wrap page alloc/put API
Quoted 27 lines · Byungchul Park
To eliminate the use of struct page in page pool, the page pool code should use netmem descriptor and API instead.
As part of the work, introduce netmem alloc/put API allowing the code to use them rather than struct page things.
Signed-off-by Byungchul Park <[email protected]>--- include/net/netmem.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)include/net/netmem.h +7
-0@@ -138,6 +138,24 @@ static inline netmem_ref page_to_netmem(struct page *page)return (__force netmem_ref )page; } +static inline netmem_ref alloc_netmems_node (int nid,gfp_t gfp_mask, +unsigned int order) +{ +return page_to_netmem (alloc_pages_node (nid, gfp_mask, order)); +} + +static inline unsigned long alloc_netmems_bulk_node(gfp_t gfp, int nid,
include/net/netmem.h static inline netmem_ref page_to_netmem(struct page *page) · line 157
Quoted 10 lines
include/net/netmem.h +10
-0+ unsigned long nr_netmems, netmem_ref *netmem_array) +{ + return alloc_pages_bulk_node(gfp, nid, nr_netmems, + (struct page **)netmem_array); +} + +static inline void put_netmem (netmem_ref netmem) +{ +put_page (netmem_to_page (netmem)); +}
We can't really do this. netmem_ref is an abstraction that can be a struct page or struct net_iov underneath. We can't be sure when put_netmem is called that it is safe to convert to a page via netmem_to_page(). This will crash if put_netmem is called on a netmem_ref that is a net_iov underneath.
Please read the patch series that introduced netmem_ref to familiarize yourself with the background here:
https://lkml.iu.edu/hypermail/linux/kernel/2401.2/09140.html
Signature · 2 lines
Thanks, Mina
Re: [RFC 02/19] netmem: introduce netmem alloc/put API to wrap page alloc/put API
j
Quoted 37 lines · Mina Almasry
Quoted 35 lines · Byungchul Park
To eliminate the use of struct page in page pool, the page pool code should use netmem descriptor and API instead.
As part of the work, introduce netmem alloc/put API allowing the code to use them rather than struct page things.
Signed-off-by Byungchul Park <[email protected]>--- include/net/netmem.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)include/net/netmem.h +15
-0@@ -138,6 +138,24 @@ static inline netmem_ref page_to_netmem(struct page *page)return (__force netmem_ref )page; } +static inline netmem_ref alloc_netmems_node (int nid,gfp_t gfp_mask, +unsigned int order) +{ +return page_to_netmem (alloc_pages_node (nid, gfp_mask, order)); +} + +static inline unsigned long alloc_netmems_bulk_node (gfp_t gfp,int nid, +unsigned long nr_netmems,netmem_ref *netmem_array) +{ +return alloc_pages_bulk_node (gfp, nid, nr_netmems, + (struct page **)netmem_array); +} + +static inline void put_netmem (netmem_ref netmem) +{
Quoted 9 lines
include/net/netmem.h static inline netmem_ref page_to_netmem(struct page *page) · line 157
Quoted 2 lines
include/net/netmem.h +2
-0+put_page (netmem_to_page (netmem)); +}We can't really do this.
netmem_refis an abstraction that can be a struct page or structnet_iovunderneath. We can't be sure whenput_netmemis called that it is safe to convert to a page vianetmem_to_page(). This will crash ifput_netmemis called on anetmem_refthat is anet_iovunderneath.
On a closer look, it looks like this put_netmem is only called from code paths where you are sure the netmem_ref is a page underneath, so this is likely fine for now. There is a net_next series that is adding proper put_netmem support [1]. It's probably best to rebase your work on top of that, but this should be fine in the meantime.
[1] https://lore.kernel.org/netdev/[email protected]/
--
Thanks,
Mina
Re: [RFC 02/19] netmem: introduce netmem alloc/put API to wrap page alloc/put API
Quoted 50 lines · Mina Almasry
j
Quoted 37 lines · Mina Almasry
Quoted 35 lines · Byungchul Park
To eliminate the use of struct page in page pool, the page pool code should use netmem descriptor and API instead.
As part of the work, introduce netmem alloc/put API allowing the code to use them rather than struct page things.
Signed-off-by Byungchul Park <[email protected]>--- include/net/netmem.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)include/net/netmem.h +15
-0@@ -138,6 +138,24 @@ static inline netmem_ref page_to_netmem(struct page *page)return (__force netmem_ref )page; } +static inline netmem_ref alloc_netmems_node (int nid,gfp_t gfp_mask, +unsigned int order) +{ +return page_to_netmem (alloc_pages_node (nid, gfp_mask, order)); +} + +static inline unsigned long alloc_netmems_bulk_node (gfp_t gfp,int nid, +unsigned long nr_netmems,netmem_ref *netmem_array) +{ +return alloc_pages_bulk_node (gfp, nid, nr_netmems, + (struct page **)netmem_array); +} + +static inline void put_netmem (netmem_ref netmem) +{Quoted 9 lines
include/net/netmem.h static inline netmem_ref page_to_netmem(struct page *page) · line 157
Quoted 2 lines
include/net/netmem.h +2
-0+put_page (netmem_to_page (netmem)); +}We can't really do this.
netmem_refis an abstraction that can be a struct page or structnet_iovunderneath. We can't be sure whenput_netmemis called that it is safe to convert to a page vianetmem_to_page(). This will crash ifput_netmemis called on anetmem_refthat is anet_iovunderneath.
Quoted 5 lines
On a closer look, it looks like this
put_netmemis only called from code paths where you are sure thenetmem_refis a page underneath, so this is likely fine for now. There is anet_nextseries that is adding properput_netmemsupport [1]. It's probably best to rebase your work on top of that, but this should be fine in the meantime.
Indeed. Hm.. It'd be the best to work on the top of yours.
If it takes too long, I keep working on as it is for now and will adjust this patch later once your work gets merged.
Byungchul
Quoted 5 lines
[1] https://lore.kernel.org/netdev/[email protected]/
--
Thanks,
Mina
RFC 3/19 page_pool: use netmem alloc/put API in __page_pool_alloc_page_order()
In reply to Byungchul ParkUse netmem alloc/put API instead of page alloc/put API and make it return netmem_ref instead of struct page * in __page_pool_alloc_page_order().
--- net/core/page_pool.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
net/core/page_pool.c +12 -12
@@ -498,29 +498,29 @@ static bool page_pool_dma_map(struct page_pool *pool, netmem_ref netmem)return false; } -static struct page *__page_pool_alloc_page_order (struct page_pool *pool, +static netmem_ref __page_pool_alloc_page_order (struct page_pool *pool,gfp_t gfp) { -struct page *page; +netmem_ref netmem; gfp |= __GFP_COMP; - page =alloc_pages_node (pool->p.nid, gfp, pool->p.order); -if (unlikely (!page)) -return NULL ; + netmem =alloc_netmems_node (pool->p.nid, gfp, pool->p.order); +if (unlikely (!netmem)) +return 0 ; -if (pool->dma_map &&unlikely (!page_pool_dma_map (pool,page_to_netmem (page)))) { -put_page (page); -return NULL ; +if (pool->dma_map &&unlikely (!page_pool_dma_map (pool, netmem))) { +put_netmem (netmem); +return 0 ; }alloc_stat_inc (pool, slow_high_order); -page_pool_set_pp_info (pool,page_to_netmem (page)); +page_pool_set_pp_info (pool, netmem);/* Track how many pages are held 'in-flight' */ pool->pages_state_hold_cnt++; -trace_page_pool_state_hold (pool,page_to_netmem (page), +trace_page_pool_state_hold (pool, netmem, pool->pages_state_hold_cnt); -return page; +return netmem; }/* slow path */
@@ -535,7 +535,7 @@ static noinline netmem_ref __page_pool_alloc_pages_slow(struct page_pool *pool,/* Don't support bulk alloc for high-order pages */ if (unlikely (pp_order)) -return page_to_netmem (__page_pool_alloc_page_order (pool, gfp)); +return __page_pool_alloc_page_order (pool, gfp);/* Unnecessary as alloc cache is empty, but guarantees zero count */ if (unlikely (pool->alloc.count >0 ))
Signature · 1 line
2.17.1
RFC 4/19 page_pool: rename __page_pool_alloc_page_order() to __page_pool_alloc_large_netmem()
In reply to Byungchul ParkNow that __page_pool_alloc_page_order() uses netmem alloc/put API, not page alloc/put API, rename it to __page_pool_alloc_large_netmem() to reflect what it does.
--- net/core/page_pool.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/page_pool.c +2 -2
@@ -498,7 +498,7 @@ static bool page_pool_dma_map(struct page_pool *pool, netmem_ref netmem)return false; } -static netmem_ref __page_pool_alloc_page_order (struct page_pool *pool, +static netmem_ref __page_pool_alloc_large_netmem (struct page_pool *pool,gfp_t gfp) {netmem_ref netmem;
@@ -535,7 +535,7 @@ static noinline netmem_ref __page_pool_alloc_pages_slow(struct page_pool *pool,/* Don't support bulk alloc for high-order pages */ if (unlikely (pp_order)) -return __page_pool_alloc_page_order (pool, gfp); +return __page_pool_alloc_large_netmem (pool, gfp);/* Unnecessary as alloc cache is empty, but guarantees zero count */ if (unlikely (pool->alloc.count >0 ))
Signature · 1 line
2.17.1
RFC 5/19 page_pool: use netmem alloc/put API in __page_pool_alloc_pages_slow()
In reply to Byungchul ParkUse netmem alloc/put API instead of page alloc/put API in __page_pool_alloc_pages_slow().
While at it, improved some comments.
--- net/core/page_pool.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
net/core/page_pool.c +12 -11
@@ -531,7 +531,7 @@ static noinline netmem_ref __page_pool_alloc_pages_slow(struct page_pool *pool,unsigned int pp_order = pool->p.order;bool dma_map = pool->dma_map;netmem_ref netmem; -int i, nr_pages; +int i, nr_netmems;/* Don't support bulk alloc for high-order pages */ if (unlikely (pp_order))
@@ -541,21 +541,21 @@ static noinline netmem_ref __page_pool_alloc_pages_slow(struct page_pool *pool,if (unlikely (pool->alloc.count >0 ))return pool->alloc.cache[--pool->alloc.count]; -/* Mark empty alloc.cache slots "empty" for alloc_pages_bulk */ +/* Mark empty alloc.cache slots "empty" for alloc_netmems_bulk_node() */ memset (&pool->alloc.cache,0 ,sizeof (void *) * bulk); - nr_pages =alloc_pages_bulk_node (gfp, pool->p.nid, bulk, - (struct page **)pool->alloc.cache); -if (unlikely (!nr_pages)) + nr_netmems =alloc_netmems_bulk_node (gfp, pool->p.nid, bulk, + pool->alloc.cache); +if (unlikely (!nr_netmems))return 0 ; -/* Pages have been filled into alloc.cache array, but count is zero and -* page element have not been (possibly) DMA mapped. +/* Netmems have been filled into alloc.cache array, but count is +* zero and elements have not been (possibly) DMA mapped. */ -for (i =0 ; i < nr_pages; i++) { +for (i =0 ; i < nr_netmems; i++) { netmem = pool->alloc.cache[i];if (dma_map &&unlikely (!page_pool_dma_map (pool, netmem))) { -put_page (netmem_to_page (netmem)); +put_netmem (netmem);continue ; }
@@ -567,7 +567,7 @@ static noinline netmem_ref __page_pool_alloc_pages_slow(struct page_pool *pool, pool->pages_state_hold_cnt); } -/* Return last page */ +/* Return the last netmem */ if (likely (pool->alloc.count >0 )) { netmem = pool->alloc.cache[--pool->alloc.count];alloc_stat_inc (pool, slow);
@@ -575,7 +575,8 @@ static noinline netmem_ref __page_pool_alloc_pages_slow(struct page_pool *pool, netmem =0 ; } -/* When page just alloc'ed is should/must have refcnt 1. */ +/* When a netmem has been just allocated, it should/must have +* refcnt 1. */ return netmem; }
Signature · 1 line
2.17.1
RFC 6/19 page_pool: rename page_pool_return_page() to page_pool_return_netmem()
In reply to Byungchul ParkNow that page_pool_return_page() is for returning netmem, not struct page, rename it to page_pool_return_netmem() to reflect what it does.
--- net/core/page_pool.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
net/core/page_pool.c +11 -11
@@ -374,7 +374,7 @@ struct page_pool *page_pool_create(const struct page_pool_params *params) }EXPORT_SYMBOL (page_pool_create); -static void page_pool_return_page (struct page_pool *pool,netmem_ref netmem); +static void page_pool_return_netmem (struct page_pool *pool,netmem_ref netmem); static noinline netmem_ref page_pool_refill_alloc_cache(struct page_pool *pool) {
@@ -412,7 +412,7 @@ static noinline netmem_ref page_pool_refill_alloc_cache(struct page_pool *pool)* (2) break out to fallthrough to alloc_pages_node. * This limit stress on page buddy alloactor. */ -page_pool_return_page (pool, netmem); +page_pool_return_netmem (pool, netmem);alloc_stat_inc (pool, waive); netmem =0 ;break ;
@@ -679,7 +679,7 @@ static __always_inline void __page_pool_release_page_dma(struct page_pool *pool,* a regular page (that will eventually be returned to the normal * page-allocator via put_page). */ -void page_pool_return_page (struct page_pool *pool,netmem_ref netmem) +static void page_pool_return_netmem (struct page_pool *pool,netmem_ref netmem) {int count;bool put;
@@ -796,7 +796,7 @@ __page_pool_put_page(struct page_pool *pool, netmem_ref netmem,* will be invoking put_page. */ recycle_stat_inc (pool, released_refcnt); -page_pool_return_page (pool, netmem); +page_pool_return_netmem (pool, netmem);return 0 ; }
@@ -835,7 +835,7 @@ void page_pool_put_unrefed_netmem(struct page_pool *pool, netmem_ref netmem,if (netmem && !page_pool_recycle_in_ring (pool, netmem)) {/* Cache full, fallback to free pages */ recycle_stat_inc (pool, ring_full); -page_pool_return_page (pool, netmem); +page_pool_return_netmem (pool, netmem); } }EXPORT_SYMBOL (page_pool_put_unrefed_netmem);
@@ -878,7 +878,7 @@ static void page_pool_recycle_ring_bulk(struct page_pool *pool,* since put_page() with refcnt == 1 can be an expensive operation. */ for (; i < bulk_len; i++) -page_pool_return_page (pool, bulk[i]); +page_pool_return_netmem (pool, bulk[i]); }/**
@@ -961,7 +961,7 @@ static netmem_ref page_pool_drain_frag(struct page_pool *pool,return netmem; } -page_pool_return_page (pool, netmem); +page_pool_return_netmem (pool, netmem);return 0 ; }
@@ -975,7 +975,7 @@ static void page_pool_free_frag(struct page_pool *pool)if (!netmem ||page_pool_unref_netmem (netmem, drain_count))return ; -page_pool_return_page (pool, netmem); +page_pool_return_netmem (pool, netmem); } netmem_ref page_pool_alloc_frag_netmem(struct page_pool *pool,
@@ -1042,7 +1042,7 @@ static void page_pool_empty_ring(struct page_pool *pool)pr_crit ("%s() page_pool refcnt %d violation\n" , __func__,netmem_ref_count (netmem)); -page_pool_return_page (pool, netmem); +page_pool_return_netmem (pool, netmem); } }
@@ -1075,7 +1075,7 @@ static void page_pool_empty_alloc_cache_once(struct page_pool *pool)*/ while (pool->alloc.count) { netmem = pool->alloc.cache[--pool->alloc.count]; -page_pool_return_page (pool, netmem); +page_pool_return_netmem (pool, netmem); } }
@@ -1194,7 +1194,7 @@ void page_pool_update_nid(struct page_pool *pool, int new_nid)/* Flush pool alloc cache, as refill will check NUMA node */ while (pool->alloc.count) { netmem = pool->alloc.cache[--pool->alloc.count]; -page_pool_return_page (pool, netmem); +page_pool_return_netmem (pool, netmem); } }EXPORT_SYMBOL (page_pool_update_nid);
Signature · 1 line
2.17.1
RFC 7/19 page_pool: use netmem alloc/put API in page_pool_return_netmem()
In reply to Byungchul ParkUse netmem alloc/put API, put_netmem(), instead of put_page() in page_pool_return_netmem().
While at it, delete #include <linux/mm.h> since the last put_page() in page_pool.c has been just removed with this patch.
--- net/core/page_pool.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
net/core/page_pool.c +2 -3
@@ -20,7 +20,6 @@#include <linux/dma-direction.h> #include <linux/dma-mapping.h> #include <linux/page-flags.h> -#include <linux/mm.h> /* for put_page() */ #include <linux/poison.h> #include <linux/ethtool.h> #include <linux/netdevice.h>
@@ -677,7 +676,7 @@ static __always_inline void __page_pool_release_page_dma(struct page_pool *pool,/* Disconnects a page (from a page_pool). API users can have a need * to disconnect a page (from a page_pool), to allow it to be used as * a regular page (that will eventually be returned to the normal -* page-allocator via put_page). +* page-allocator via put_netmem() and then put_page()). */ static void page_pool_return_netmem (struct page_pool *pool,netmem_ref netmem) {
@@ -698,7 +697,7 @@ static void page_pool_return_netmem(struct page_pool *pool, netmem_ref netmem)if (put) {page_pool_clear_pp_info (netmem); -put_page (netmem_to_page (netmem)); +put_netmem (netmem); }/* An optimization would be to call __free_pages(page, pool->p.order) * knowing page is not part of page-cache (thus avoiding a
Signature · 1 line
2.17.1
RFC 8/19 page_pool: rename __page_pool_release_page_dma() to __page_pool_release_netmem_dma()
In reply to Byungchul ParkNow that __page_pool_release_page_dma() is for releasing netmem, not struct page, rename it to __page_pool_release_netmem_dma() to reflect what it does.
--- net/core/page_pool.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/page_pool.c +2 -2
@@ -653,7 +653,7 @@ void page_pool_clear_pp_info(netmem_ref netmem)netmem_set_pp (netmem,NULL ); } -static __always_inline void __page_pool_release_page_dma(struct page_pool *pool, +static __always_inline void __page_pool_release_netmem_dma(struct page_pool *pool,netmem_ref netmem) {dma_addr_t dma;
@@ -687,7 +687,7 @@ static void page_pool_return_netmem(struct page_pool *pool, netmem_ref netmem)if (static_branch_unlikely (&page_pool_mem_providers) && pool->mp_ops) put = pool->mp_ops->release_netmem (pool, netmem);else -__page_pool_release_page_dma (pool, netmem); +__page_pool_release_netmem_dma (pool, netmem);/* This may be the last page returned, releasing the pool, so * it is not safe to reference pool afterwards.
Signature · 1 line
2.17.1
RFC 9/19 page_pool: rename __page_pool_put_page() to __page_pool_put_netmem()
In reply to Byungchul ParkNow that __page_pool_put_page() puts netmem, not struct page, rename it to __page_pool_put_netmem() to reflect what it does.
--- net/core/page_pool.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/core/page_pool.c +4 -4
@@ -755,7 +755,7 @@ static bool __page_pool_page_can_be_recycled(netmem_ref netmem)* subsystem. */ static __always_inline netmem_ref -__page_pool_put_page (struct page_pool *pool,netmem_ref netmem, +__page_pool_put_netmem (struct page_pool *pool,netmem_ref netmem,unsigned int dma_sync_size,bool allow_direct) {lockdep_assert_no_hardirq ();
@@ -811,7 +811,7 @@ static bool page_pool_napi_local(const struct page_pool *pool)/* Allow direct recycle if we have reasons to believe that we are * in the same context as the consumer would run, so there's * no possible race. -* __page_pool_put_page() makes sure we're not in hardirq context +* __page_pool_put_netmem() makes sure we're not in hardirq context * and interrupts are enabled prior to accessing the cache. */ cpuid =smp_processor_id ();
@@ -830,7 +830,7 @@ void page_pool_put_unrefed_netmem(struct page_pool *pool, netmem_ref netmem, allow_direct =page_pool_napi_local (pool); netmem = -__page_pool_put_page (pool, netmem, dma_sync_size, allow_direct); +__page_pool_put_netmem (pool, netmem, dma_sync_size, allow_direct);if (netmem && !page_pool_recycle_in_ring (pool, netmem)) {/* Cache full, fallback to free pages */ recycle_stat_inc (pool, ring_full);
@@ -931,7 +931,7 @@ void page_pool_put_netmem_bulk(netmem_ref *data, u32 count)continue ; } - netmem =__page_pool_put_page (pool, netmem,-1 , + netmem =__page_pool_put_netmem (pool, netmem,-1 , allow_direct);/* Approved for bulk recycling in ptr_ring cache */ if (netmem)
Signature · 1 line
2.17.1
RFC 10/19 page_pool: rename __page_pool_alloc_pages_slow() to __page_pool_alloc_netmems_slow()
In reply to Byungchul ParkNow that __page_pool_alloc_pages_slow() is for allocating netmem, not struct page, rename it to __page_pool_alloc_netmems_slow() to reflect what it does.
--- net/core/page_pool.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/page_pool.c +2 -2
@@ -523,7 +523,7 @@ static netmem_ref __page_pool_alloc_large_netmem(struct page_pool *pool, }/* slow path */ -static noinline netmem_ref __page_pool_alloc_pages_slow(struct page_pool *pool, +static noinline netmem_ref __page_pool_alloc_netmems_slow(struct page_pool *pool,gfp_t gfp) {const int bulk =PP_ALLOC_CACHE_REFILL ;
@@ -595,7 +595,7 @@ netmem_ref page_pool_alloc_netmems(struct page_pool *pool, gfp_t gfp)if (static_branch_unlikely (&page_pool_mem_providers) && pool->mp_ops) netmem = pool->mp_ops->alloc_netmems (pool, gfp);else - netmem =__page_pool_alloc_pages_slow (pool, gfp); + netmem =__page_pool_alloc_netmems_slow (pool, gfp);return netmem; }EXPORT_SYMBOL (page_pool_alloc_netmems);
Signature · 1 line
2.17.1
RFC 11/19 mlx4: use netmem descriptor and API for page pool
In reply to Byungchul ParkTo simplify struct page, the effort to seperate its own descriptor from struct page is required and the work for page pool is on going.
Use netmem descriptor and API for page pool in mlx4 code.
--- drivers/net/ethernet/mellanox/mlx4/en_rx.c | 46 +++++++++++--------- drivers/net/ethernet/mellanox/mlx4/en_tx.c | 8 ++-- drivers/net/ethernet/mellanox/mlx4/mlx4_en.h | 4 +- 3 files changed, 31 insertions(+), 27 deletions(-)
drivers/net/ethernet/mellanox/mlx4/en_rx.c +25 -21
@@ -62,18 +62,18 @@ static int mlx4_en_alloc_frags(struct mlx4_en_priv *priv,int i;for (i =0 ; i < priv->num_frags; i++, frags++) { -if (!frags->page) { - frags->page =page_pool_alloc_pages (ring->pp, gfp); -if (!frags->page) { +if (!frags->netmem) { + frags->netmem =page_pool_alloc_netmems (ring->pp, gfp); +if (!frags->netmem) { ring->alloc_fail++;return -ENOMEM ; } -page_pool_fragment_page (frags->page,1 ); +page_pool_fragment_netmem (frags->netmem,1 ); frags->page_offset = priv->rx_headroom; ring->rx_alloc_pages++; } - dma =page_pool_get_dma_addr (frags->page); + dma =page_pool_get_dma_addr_netmem (frags->netmem); rx_desc->data[i].addr =cpu_to_be64 (dma + frags->page_offset); }return 0 ;
@@ -83,10 +83,10 @@ static void mlx4_en_free_frag(const struct mlx4_en_priv *priv, struct mlx4_en_rx_ring *ring, struct mlx4_en_rx_alloc *frag) { -if (frag->page) -page_pool_put_full_page (ring->pp, frag->page, false); +if (frag->netmem) +page_pool_put_full_netmem (ring->pp, frag->netmem, false);/* We need to clear all fields, otherwise a change of priv->log_rx_info -* could lead to see garbage later in frag->page. +* could lead to see garbage later in frag->netmem. */ memset (frag,0 ,sizeof (*frag)); }
@@ -440,29 +440,33 @@ static int mlx4_en_complete_rx_desc(struct mlx4_en_priv *priv,unsigned int truesize =0 ;bool release = true;int nr, frag_size; -struct page *page; +netmem_ref netmem;dma_addr_t dma;/* Collect used fragments while replacing them in the HW descriptors */ for (nr =0 ;; frags++) { frag_size =min_t (int, length, frag_info->frag_size); - page = frags->page; -if (unlikely (!page)) + netmem = frags->netmem; +if (unlikely (!netmem)) goto fail; - dma =page_pool_get_dma_addr (page); + dma =page_pool_get_dma_addr_netmem (netmem);dma_sync_single_range_for_cpu (priv->ddev, dma, frags->page_offset, frag_size, priv->dma_dir); -__skb_fill_page_desc (skb, nr, page, frags->page_offset, +__skb_fill_netmem_desc (skb, nr, netmem, frags->page_offset, frag_size); truesize += frag_info->frag_stride;if (frag_info->frag_stride ==PAGE_SIZE /2 ) { +struct page *page =netmem_to_page (netmem); +atomic_long_t *pp_ref_count = +netmem_get_pp_ref_count_ref (netmem); + frags->page_offset ^=PAGE_SIZE /2 ; release =page_count (page) !=1 || -atomic_long_read (&page->pp_ref_count) !=1 || +atomic_long_read (pp_ref_count) !=1 ||page_is_pfmemalloc (page) ||page_to_nid (page) !=numa_mem_id (); }else if (!priv->rx_headroom) {
@@ -476,9 +480,9 @@ static int mlx4_en_complete_rx_desc(struct mlx4_en_priv *priv, release = frags->page_offset + frag_info->frag_size >PAGE_SIZE ; }if (release) { - frags->page =NULL ; + frags->netmem =0 ; }else { -page_pool_ref_page (page); +page_pool_ref_netmem (netmem); } nr++;
@@ -719,7 +723,7 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int budint nr; frags = ring->rx_info + (index << priv->log_rx_info); - va =page_address (frags[0 ].page) + frags[0 ].page_offset; + va =netmem_address (frags[0 ].netmem) + frags[0 ].page_offset;net_prefetchw (va);/* * make sure we read the CQE after we read the ownership bit
@@ -748,7 +752,7 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int bud/* Get pointer to first fragment since we haven't * skb yet and cast it to ethhdr struct */ - dma =page_pool_get_dma_addr (frags[0 ].page); + dma =page_pool_get_dma_addr_netmem (frags[0 ].netmem); dma += frags[0 ].page_offset;dma_sync_single_for_cpu (priv->ddev, dma,sizeof (*ethh),DMA_FROM_DEVICE );
@@ -788,7 +792,7 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int budvoid *orig_data;u32 act; - dma =page_pool_get_dma_addr (frags[0 ].page); + dma =page_pool_get_dma_addr_netmem (frags[0 ].netmem); dma += frags[0 ].page_offset; dma_sync_single_for_cpu(priv->ddev, dma, priv->frag_info[0].frag_size,
@@ -818,7 +822,7 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int budif (likely (!xdp_do_redirect (dev, &mxbuf.xdp, xdp_prog))) { ring->xdp_redirect++; xdp_redir_flush = true; - frags[0 ].page =NULL ; + frags[0 ].netmem =0 ; goto next; } ring->xdp_redirect_fail++;
@@ -828,7 +832,7 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int budif (likely (!mlx4_en_xmit_frame (ring, frags, priv, length, cq_ring, &doorbell_pending))) { - frags[0 ].page =NULL ; + frags[0 ].netmem =0 ; goto next; }trace_xdp_exception (dev, xdp_prog, act);
drivers/net/ethernet/mellanox/mlx4/en_tx.c +4 -4
@@ -354,7 +354,7 @@ u32 mlx4_en_recycle_tx_desc(struct mlx4_en_priv *priv,struct page_pool *pool = ring->recycle_ring->pp;/* Note that napi_mode = 0 means ndo_close() path, not budget = 0 */ -page_pool_put_full_page (pool, tx_info->page, !!napi_mode); +page_pool_put_full_netmem (pool, tx_info->netmem, !!napi_mode);return tx_info->nr_txbb; }
@@ -1191,10 +1191,10 @@ netdev_tx_t mlx4_en_xmit_frame(struct mlx4_en_rx_ring *rx_ring, tx_desc = ring->buf + (index <<LOG_TXBB_SIZE ); data = &tx_desc->data; - dma =page_pool_get_dma_addr (frame->page); + dma =page_pool_get_dma_addr_netmem (frame->netmem); - tx_info->page = frame->page; - frame->page =NULL ; + tx_info->netmem = frame->netmem; + frame->netmem =0 ; tx_info->map0_dma = dma; tx_info->nr_bytes = max_t(unsigned int, length, ETH_ZLEN);
drivers/net/ethernet/mellanox/mlx4/mlx4_en.h +2 -2
@@ -213,7 +213,7 @@ enum cq_type {struct mlx4_en_tx_info {union {struct sk_buff *skb; -struct page *page; +netmem_ref netmem; };dma_addr_t map0_dma;u32 map0_byte_count;
@@ -246,7 +246,7 @@ struct mlx4_en_tx_desc {#define MLX4_EN_CX3_HIGH_ID 0x1005struct mlx4_en_rx_alloc { -struct page *page; +netmem_ref netmem;u32 page_offset; };
Signature · 1 line
2.17.1
RFC 12/19 netmem: introduce page_pool_recycle_direct_netmem()
In reply to Byungchul ParkAll the callers to page_pool_recycle_direct() need to be converted to use netmem descriptor and API instead of struct page things.
As part of the work, introduce page_pool_recycle_direct_netmem() allowing the callers to use netmem descriptor and API.
--- include/net/page_pool/helpers.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/net/page_pool/helpers.h +6 -0
@@ -395,6 +395,12 @@ static inline void page_pool_recycle_direct(struct page_pool *pool,page_pool_put_full_page (pool, page, true); } +static inline void page_pool_recycle_direct_netmem (struct page_pool *pool, +netmem_ref netmem) +{ +page_pool_put_full_netmem (pool, netmem, true); +} +#define PAGE_POOL_32BIT_ARCH_WITH_64BIT_DMA \ (sizeof(dma_addr_t) > sizeof(unsigned long))
Signature · 1 line
2.17.1
RFC 13/19 page_pool: expand scope of is_pp_{netmem,page}() to global
In reply to Byungchul ParkOther than skbuff.c might need to check if a page or netmem is for page pool, for example, page_alloc.c needs to check the page state, whether it comes from page pool or not for their own purpose.
Expand the scope of is_pp_netmem() and introduce is_pp_page() newly, so that those who want to check the source can achieve the checking without accessing page pool member, page->pp_magic, directly.
--- include/net/page_pool/types.h | 2 ++ net/core/page_pool.c | 10 ++++++++++ net/core/skbuff.c | 5 ----- 3 files changed, 12 insertions(+), 5 deletions(-)
include/net/page_pool/types.h +2 -0
@@ -299,4 +299,6 @@ static inline bool is_page_pool_compiled_in(void)/* Caller must provide appropriate safe context, e.g. NAPI. */ void page_pool_update_nid (struct page_pool *pool,int new_nid); +bool is_pp_netmem (netmem_ref netmem); +bool is_pp_page (struct page *page);#endif /* _NET_PAGE_POOL_H */
net/core/page_pool.c +10 -0
@@ -1225,3 +1225,13 @@ void net_mp_niov_clear_page_pool(struct netmem_desc *niov)page_pool_clear_pp_info (netmem); } + +bool is_pp_netmem (netmem_ref netmem) +{ +return (netmem_get_pp_magic (netmem) & ~0x3UL ) ==PP_SIGNATURE ; +} + +bool is_pp_page (struct page *page) +{ +return is_pp_netmem (page_to_netmem (page)); +}
net/core/skbuff.c +0 -5
@@ -893,11 +893,6 @@ static void skb_clone_fraglist(struct sk_buff *skb)skb_get (list); } -static bool is_pp_netmem (netmem_ref netmem) -{ -return (netmem_get_pp_magic (netmem) & ~0x3UL ) ==PP_SIGNATURE ; -} -int skb_pp_cow_data (struct page_pool *pool,struct sk_buff **pskb,unsigned int headroom) {
Signature · 1 line
2.17.1
kernel test robot
build botRe: [RFC 13/19] page_pool: expand scope of is_pp_{netmem,page}() to global
kernel test robot noticed the following build errors:
Hi Byungchul,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:
[auto build test ERROR on fd93b3350b4314eebd8fbf0fea3ca7fe48d777e3]
url: https://github.com/intel-lab-lkp/linux/commits/Byungchul-Park/netmem-rename-struct-net_iov-to-struct-netmem_desc/20250509-195458 base: fd93b3350b4314eebd8fbf0fea3ca7fe48d777e3 patch link: https://lore.kernel.org/r/20250509115126.63190-14-byungchul%40sk.com patch subject: [RFC 13/19] page_pool: expand scope of is_pp_{netmem,page}() to global config: x86_64-buildonly-randconfig-001-20250510 (https://download.01.org/0day-ci/archive/20250510/[email protected]/config) compiler: clang version 20.1.2 (https://github.com/llvm/llvm-project 58df0ef89dd64126512e4ee27b4ac3fd8ddf6247) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250510/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> ld.lld: error: undefined symbol: is_pp_netmem >>> referenced by skbuff.c:1040 (net/core/skbuff.c:1040) >>> net/core/skbuff.o:(skb_pp_frag_ref) in archive vmlinux.a
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [RFC 13/19] page_pool: expand scope of is_pp_{netmem,page}() to global
In reply to Byungchul ParkQuoted 49 lines · Byungchul Park
Other than
skbuff.cmight need to check if a page or netmem is for page pool, for example,page_alloc.cneeds to check the page state, whether it comes from page pool or not for their own purpose.Expand the scope of
is_pp_netmem()and introduceis_pp_page()newly, so that those who want to check the source can achieve the checking without accessing page pool member,page->pp_magic, directly.Signed-off-by Byungchul Park <[email protected]>--- include/net/page_pool/types.h | 2 ++ net/core/page_pool.c | 10 ++++++++++ net/core/skbuff.c | 5 ----- 3 files changed, 12 insertions(+), 5 deletions(-)include/net/page_pool/types.h +2
-0@@ -299,4 +299,6 @@ static inline bool is_page_pool_compiled_in(void)/* Caller must provide appropriate safe context, e.g. NAPI. */ void page_pool_update_nid (struct page_pool *pool,int new_nid); +bool is_pp_netmem (netmem_ref netmem); +bool is_pp_page (struct page *page);#endif /* _NET_PAGE_POOL_H */ net/core/page_pool.c +10
-0@@ -1225,3 +1225,13 @@ void net_mp_niov_clear_page_pool(struct netmem_desc *niov)page_pool_clear_pp_info (netmem); } + +bool is_pp_netmem (netmem_ref netmem) +{ +return (netmem_get_pp_magic (netmem) & ~0x3UL ) ==PP_SIGNATURE ; +} + +bool is_pp_page (struct page *page) +{ +return is_pp_netmem (page_to_netmem (page)); +}net/core/skbuff.c +0
-0
net/core/skbuff.c static void skb_clone_fraglist(struct sk_buff *skb) · line 900
Quoted 8 lines
net/core/skbuff.c +0
-5@@ -893,11 +893,6 @@ static void skb_clone_fraglist(struct sk_buff *skb)skb_get (list); } -static bool is_pp_netmem (netmem_ref netmem) -{ -return (netmem_get_pp_magic (netmem) & ~0x3UL ) ==PP_SIGNATURE ; -} -
This has already been moved to mm.h (and the check changed) by commit:
cd3c93167da0 ("page_pool: Move pp_magic check into helper functions")
You should definitely rebase this series on top of that (and the subsequent ee62ce7a1d90 ("page_pool: Track DMA-mapped pages and unmap them when destroying the pool")), as these change the semantics of how page_pool interacts with struct page.
Both of these are in net-next, which Mina already asked you to rebase on, so I guess you'll pick it up there, put flagging it here just for completeness :)
-Toke
Re: [RFC 13/19] page_pool: expand scope of is_pp_{netmem,page}() to global
Quoted 64 lines · Toke Høiland-Jørgensen
Quoted 49 lines · Byungchul Park
Other than
skbuff.cmight need to check if a page or netmem is for page pool, for example,page_alloc.cneeds to check the page state, whether it comes from page pool or not for their own purpose.Expand the scope of
is_pp_netmem()and introduceis_pp_page()newly, so that those who want to check the source can achieve the checking without accessing page pool member,page->pp_magic, directly.Signed-off-by Byungchul Park <[email protected]>--- include/net/page_pool/types.h | 2 ++ net/core/page_pool.c | 10 ++++++++++ net/core/skbuff.c | 5 ----- 3 files changed, 12 insertions(+), 5 deletions(-)include/net/page_pool/types.h +2
-0@@ -299,4 +299,6 @@ static inline bool is_page_pool_compiled_in(void)/* Caller must provide appropriate safe context, e.g. NAPI. */ void page_pool_update_nid (struct page_pool *pool,int new_nid); +bool is_pp_netmem (netmem_ref netmem); +bool is_pp_page (struct page *page);#endif /* _NET_PAGE_POOL_H */ net/core/page_pool.c +10
-0@@ -1225,3 +1225,13 @@ void net_mp_niov_clear_page_pool(struct netmem_desc *niov)page_pool_clear_pp_info (netmem); } + +bool is_pp_netmem (netmem_ref netmem) +{ +return (netmem_get_pp_magic (netmem) & ~0x3UL ) ==PP_SIGNATURE ; +} + +bool is_pp_page (struct page *page) +{ +return is_pp_netmem (page_to_netmem (page)); +}net/core/skbuff.c +0
-0net/core/skbuff.c static void skb_clone_fraglist(struct sk_buff *skb) · line 900
Quoted 8 lines
net/core/skbuff.c +0
-5@@ -893,11 +893,6 @@ static void skb_clone_fraglist(struct sk_buff *skb)skb_get (list); } -static bool is_pp_netmem (netmem_ref netmem) -{ -return (netmem_get_pp_magic (netmem) & ~0x3UL ) ==PP_SIGNATURE ; -} -This has already been moved to
mm.h(and the check changed) by commit:
cd3c93167da0("page_pool: Movepp_magiccheck into helper functions")
Quoted 8 lines
You should definitely rebase this series on top of that (and the subsequent
ee62ce7a1d90("page_pool: Track DMA-mapped pages and unmap them when destroying the pool")), as these change the semantics of howpage_poolinteracts with struct page.Both of these are in net-next, which Mina already asked you to rebase on, so I guess you'll pick it up there, put flagging it here just for completeness :)
I will not miss it. Thanks.
Byungchul
Quoted 3 lines
-Toke
Re: [RFC 13/19] page_pool: expand scope of is_pp_{netmem,page}() to global
In reply to Toke Høiland-JørgensenQuoted 62 lines · Toke Høiland-Jørgensen
Quoted 49 lines · Byungchul Park
Other than
skbuff.cmight need to check if a page or netmem is for page pool, for example,page_alloc.cneeds to check the page state, whether it comes from page pool or not for their own purpose.Expand the scope of
is_pp_netmem()and introduceis_pp_page()newly, so that those who want to check the source can achieve the checking without accessing page pool member,page->pp_magic, directly.Signed-off-by Byungchul Park <[email protected]>--- include/net/page_pool/types.h | 2 ++ net/core/page_pool.c | 10 ++++++++++ net/core/skbuff.c | 5 ----- 3 files changed, 12 insertions(+), 5 deletions(-)include/net/page_pool/types.h +2
-0@@ -299,4 +299,6 @@ static inline bool is_page_pool_compiled_in(void)/* Caller must provide appropriate safe context, e.g. NAPI. */ void page_pool_update_nid (struct page_pool *pool,int new_nid); +bool is_pp_netmem (netmem_ref netmem); +bool is_pp_page (struct page *page);#endif /* _NET_PAGE_POOL_H */ net/core/page_pool.c +10
-0@@ -1225,3 +1225,13 @@ void net_mp_niov_clear_page_pool(struct netmem_desc *niov)page_pool_clear_pp_info (netmem); } + +bool is_pp_netmem (netmem_ref netmem) +{ +return (netmem_get_pp_magic (netmem) & ~0x3UL ) ==PP_SIGNATURE ; +} + +bool is_pp_page (struct page *page) +{ +return is_pp_netmem (page_to_netmem (page)); +}net/core/skbuff.c +0
-0net/core/skbuff.c static void skb_clone_fraglist(struct sk_buff *skb) · line 900
Quoted 8 lines
net/core/skbuff.c +0
-5@@ -893,11 +893,6 @@ static void skb_clone_fraglist(struct sk_buff *skb)skb_get (list); } -static bool is_pp_netmem (netmem_ref netmem) -{ -return (netmem_get_pp_magic (netmem) & ~0x3UL ) ==PP_SIGNATURE ; -} -This has already been moved to
mm.h(and the check changed) by commit:
Quoted 8 lines
cd3c93167da0("page_pool: Movepp_magiccheck into helper functions")You should definitely rebase this series on top of that (and the subsequent
ee62ce7a1d90("page_pool: Track DMA-mapped pages and unmap them when destroying the pool")), as these change the semantics of howpage_poolinteracts with struct page.Both of these are in net-next, which Mina already asked you to rebase
Is this net-next you are mentioning? I will rebase on this if so.
https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/
Byungchul
Quoted 5 lines
on, so I guess you'll pick it up there, put flagging it here just for completeness :)
-Toke
Re: [RFC 13/19] page_pool: expand scope of is_pp_{netmem,page}() to global
Quoted 70 lines · Byungchul Park
Quoted 69 lines · Toke Høiland-Jørgensen
Quoted 49 lines · Byungchul Park
Other than
skbuff.cmight need to check if a page or netmem is for page pool, for example,page_alloc.cneeds to check the page state, whether it comes from page pool or not for their own purpose.Expand the scope of
is_pp_netmem()and introduceis_pp_page()newly, so that those who want to check the source can achieve the checking without accessing page pool member,page->pp_magic, directly.Signed-off-by Byungchul Park <[email protected]>--- include/net/page_pool/types.h | 2 ++ net/core/page_pool.c | 10 ++++++++++ net/core/skbuff.c | 5 ----- 3 files changed, 12 insertions(+), 5 deletions(-)include/net/page_pool/types.h +2
-0@@ -299,4 +299,6 @@ static inline bool is_page_pool_compiled_in(void)/* Caller must provide appropriate safe context, e.g. NAPI. */ void page_pool_update_nid (struct page_pool *pool,int new_nid); +bool is_pp_netmem (netmem_ref netmem); +bool is_pp_page (struct page *page);#endif /* _NET_PAGE_POOL_H */ net/core/page_pool.c +10
-0@@ -1225,3 +1225,13 @@ void net_mp_niov_clear_page_pool(struct netmem_desc *niov)page_pool_clear_pp_info (netmem); } + +bool is_pp_netmem (netmem_ref netmem) +{ +return (netmem_get_pp_magic (netmem) & ~0x3UL ) ==PP_SIGNATURE ; +} + +bool is_pp_page (struct page *page) +{ +return is_pp_netmem (page_to_netmem (page)); +}net/core/skbuff.c +0
-0net/core/skbuff.c static void skb_clone_fraglist(struct sk_buff *skb) · line 900
Quoted 8 lines
net/core/skbuff.c +0
-5@@ -893,11 +893,6 @@ static void skb_clone_fraglist(struct sk_buff *skb)skb_get (list); } -static bool is_pp_netmem (netmem_ref netmem) -{ -return (netmem_get_pp_magic (netmem) & ~0x3UL ) ==PP_SIGNATURE ; -} -This has already been moved to
mm.h(and the check changed) by commit:
cd3c93167da0("page_pool: Movepp_magiccheck into helper functions")You should definitely rebase this series on top of that (and the subsequent
ee62ce7a1d90("page_pool: Track DMA-mapped pages and unmap them when destroying the pool")), as these change the semantics of howpage_poolinteracts with struct page.
Quoted 5 lines
Quoted 1 line
Both of these are in net-next, which Mina already asked you to rebase
Is this net-next you are mentioning? I will rebase on this if so.
https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/
Yup :)
-Toke
RFC 14/19 mm: page_alloc: do not directly access page->pp_magic but use is_pp_page()
In reply to Byungchul ParkTo simplify struct page, the effort to seperate its own descriptor from struct page is required and the work for page pool is on going.
To achieve that, all the code should avoid accessing page pool members of struct page directly, but use safe API for the corresponding purpose, that is is_pp_page() in this case.
Use is_pp_page() instead of accessing the members directly, when checking if a page comes from page pool or not.
--- mm/page_alloc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
mm/page_alloc.c +3 -2
@@ -55,6 +55,7 @@#include <linux/delayacct.h> #include <linux/cacheinfo.h> #include <linux/pgalloc_tag.h> +#include <net/page_pool/types.h> /* for page pool checking */ #include <asm/div64.h> #include "internal.h" #include "shuffle.h"
@@ -899,7 +900,7 @@ static inline bool page_expected_state(struct page *page, page->memcg_data |#endif #ifdef CONFIG_PAGE_POOL - ((page->pp_magic & ~0x3UL) == PP_SIGNATURE) | + (is_pp_page(page)) | #endif (page->flags & check_flags)))return false;
@@ -928,7 +929,7 @@ static const char *page_bad_reason(struct page *page, unsigned long flags) bad_reason ="page still charged to cgroup" ;#endif #ifdef CONFIG_PAGE_POOL -if (unlikely ((page->pp_magic & ~0x3UL ) ==PP_SIGNATURE )) +if (unlikely (is_pp_page (page))) bad_reason ="page_pool leak" ;#endif return bad_reason;
Signature · 1 line
2.17.1
RFC 15/19 mlx5: use netmem descriptor and API for page pool
In reply to Byungchul ParkTo simplify struct page, the effort to seperate its own descriptor from struct page is required and the work for page pool is on going.
Use netmem descriptor and API for page pool in mlx5 code.
--- drivers/net/ethernet/mellanox/mlx5/core/en.h | 4 +- .../net/ethernet/mellanox/mlx5/core/en/xdp.c | 18 ++--- .../net/ethernet/mellanox/mlx5/core/en/xdp.h | 2 +- .../net/ethernet/mellanox/mlx5/core/en_main.c | 15 +++-- .../net/ethernet/mellanox/mlx5/core/en_rx.c | 66 +++++++++---------- include/linux/skbuff.h | 14 ++++ include/net/page_pool/helpers.h | 4 ++ 7 files changed, 73 insertions(+), 50 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en.h +2 -2
@@ -551,7 +551,7 @@ struct mlx5e_icosq { }____cacheline_aligned_in_smp ;struct mlx5e_frag_page { -struct page *page; +netmem_ref netmem;u16 frags; };
@@ -623,7 +623,7 @@ struct mlx5e_dma_info {dma_addr_t addr;union {struct mlx5e_frag_page *frag_page; -struct page *page; +netmem_ref netmem; }; };
drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c +9 -9
@@ -61,7 +61,7 @@ static inline bool mlx5e_xmit_xdp_buff(struct mlx5e_xdpsq *sq, struct mlx5e_rq *rq, struct xdp_buff *xdp) { - struct page *page = virt_to_page(xdp->data); + netmem_ref netmem = virt_to_netmem(xdp->data);struct mlx5e_xmit_data_frags xdptxdf = {};struct mlx5e_xmit_data *xdptxd;struct xdp_frame *xdpf;
@@ -122,7 +122,7 @@ mlx5e_xmit_xdp_buff(struct mlx5e_xdpsq *sq, struct mlx5e_rq *rq,* mode. */ - dma_addr =page_pool_get_dma_addr (page) + (xdpf->data - (void *)xdpf); + dma_addr =page_pool_get_dma_addr_netmem (netmem) + (xdpf->data - (void *)xdpf);dma_sync_single_for_device (sq->pdev, dma_addr, xdptxd->len,DMA_BIDIRECTIONAL );if (xdptxd->has_frags) {
@@ -134,7 +134,7 @@ mlx5e_xmit_xdp_buff(struct mlx5e_xdpsq *sq, struct mlx5e_rq *rq,dma_addr_t addr;u32 len; - addr =page_pool_get_dma_addr (skb_frag_page (frag)) + + addr =page_pool_get_dma_addr_netmem (skb_frag_netmem (frag)) +skb_frag_off (frag); len =skb_frag_size (frag); dma_sync_single_for_device(sq->pdev, addr, len,
@@ -157,19 +157,19 @@ mlx5e_xmit_xdp_buff(struct mlx5e_xdpsq *sq, struct mlx5e_rq *rq, (union mlx5e_xdp_info ) { .page.num = 1 + xdptxdf.sinfo->nr_frags });mlx5e_xdpi_fifo_push (&sq->db.xdpi_fifo, - (union mlx5e_xdp_info ) { .page.page = page }); + (union mlx5e_xdp_info ) { .page.netmem = netmem });for (i =0 ; i < xdptxdf.sinfo->nr_frags; i++) {skb_frag_t *frag = &xdptxdf.sinfo->frags[i];mlx5e_xdpi_fifo_push (&sq->db.xdpi_fifo, (union mlx5e_xdp_info ) - { .page.page =skb_frag_page (frag) }); + { .page.netmem =skb_frag_netmem (frag) }); } }else {mlx5e_xdpi_fifo_push (&sq->db.xdpi_fifo, (union mlx5e_xdp_info ) { .page.num =1 });mlx5e_xdpi_fifo_push (&sq->db.xdpi_fifo, - (union mlx5e_xdp_info ) { .page.page = page }); + (union mlx5e_xdp_info ) { .page.netmem = netmem }); }return true;
@@ -702,15 +702,15 @@ static void mlx5e_free_xdpsq_desc(struct mlx5e_xdpsq *sq, num = xdpi.page.num;do { -struct page *page; +netmem_ref netmem; xdpi =mlx5e_xdpi_fifo_pop (xdpi_fifo); - page = xdpi.page.page; + netmem = xdpi.page.netmem;/* No need to check ((page->pp_magic & ~0x3UL) == PP_SIGNATURE) * as we know this is a page_pool page. */ -page_pool_recycle_direct (page->pp, page); +page_pool_recycle_direct_netmem (netmem_get_pp (netmem), netmem); }while (++n < num);break ;
drivers/net/ethernet/mellanox/mlx5/core/en/xdp.h +1 -1
@@ -96,7 +96,7 @@ union mlx5e_xdp_info {union {struct mlx5e_rq *rq;u8 num; -struct page *page; +netmem_ref netmem; } page;struct xsk_tx_metadata_compl xsk_meta; };
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +10 -5
@@ -708,24 +708,29 @@ static void mlx5e_rq_err_cqe_work(struct work_struct *recover_work)static int mlx5e_alloc_mpwqe_rq_drop_page (struct mlx5e_rq *rq) { - rq->wqe_overflow.page =alloc_page (GFP_KERNEL ); -if (!rq->wqe_overflow.page) +struct page *page =alloc_page (GFP_KERNEL ); + +if (!page)return -ENOMEM ; - rq->wqe_overflow.addr =dma_map_page (rq->pdev, rq->wqe_overflow.page,0 , + rq->wqe_overflow.addr =dma_map_page (rq->pdev, page,0 ,PAGE_SIZE , rq->buff.map_dir);if (dma_mapping_error (rq->pdev, rq->wqe_overflow.addr)) { -__free_page (rq->wqe_overflow.page); +__free_page (page);return -ENOMEM ; } + + rq->wqe_overflow.netmem =page_to_netmem (page);return 0 ; }static void mlx5e_free_mpwqe_rq_drop_page (struct mlx5e_rq *rq) { +struct page *page =netmem_to_page (rq->wqe_overflow.netmem); +dma_unmap_page (rq->pdev, rq->wqe_overflow.addr,PAGE_SIZE , rq->buff.map_dir); -__free_page (rq->wqe_overflow.page); +__free_page (page); } static int mlx5e_init_rxq_rq(struct mlx5e_channel *c, struct mlx5e_params *params,
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +33 -33
203 lines not on this page · raw message
include/linux/skbuff.h +14 -0
@@ -3882,6 +3882,20 @@ static inline bool skb_can_coalesce(struct sk_buff *skb, int i,return false; } +static inline bool skb_can_coalesce_netmem (struct sk_buff *skb,int i, +const netmem_ref netmem,int off) +{ +if (skb_zcopy (skb)) +return false; +if (i) { +const skb_frag_t *frag = &skb_shinfo (skb)->frags[i -1 ]; + +return netmem ==skb_frag_netmem (frag) && + off ==skb_frag_off (frag) +skb_frag_size (frag); + } +return false; +} +static inline int __skb_linearize (struct sk_buff *skb) {return __pskb_pull_tail (skb, skb->data_len) ?0 : -ENOMEM ;
include/net/page_pool/helpers.h +4 -0
@@ -150,6 +150,10 @@ static inline netmem_ref page_pool_dev_alloc_netmem(struct page_pool *pool, {gfp_t gfp =GFP_ATOMIC | __GFP_NOWARN; +WARN_ON ((!offset && size) || (offset && !size)); +if (!offset || !size) +return page_pool_alloc_netmems (pool, gfp); +return page_pool_alloc_netmem (pool, offset, size, gfp); }
Signature · 1 line
2.17.1
RFC 16/19 netmem: use _Generic to cover const casting for page_to_netmem()
In reply to Byungchul ParkThe current page_to_netmem() doesn't cover const casting resulting in trying to cast const struct page * to const netmem_ref fails.
To cover the case, change page_to_netmem() to use macro and _Generic.
--- include/net/netmem.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
include/net/netmem.h +3 -4
@@ -133,10 +133,9 @@ static inline netmem_ref net_iov_to_netmem(struct netmem_desc *niov)return (__force netmem_ref)((unsigned long )niov |NET_IOV ); } -static inline netmem_ref page_to_netmem (struct page *page) -{ -return (__force netmem_ref )page; -} +#define page_to_netmem (p) (_Generic((p), \ + const struct page *: (__force const netmem_ref)(p), \ + struct page *: (__force netmem_ref)(p)))static inline netmem_ref alloc_netmems_node (int nid,gfp_t gfp_mask,unsigned int order)
Signature · 1 line
2.17.1
RFC 17/19 netmem: remove __netmem_get_pp()
In reply to Byungchul ParkThere are no users of __netmem_get_pp(). Remove it.
--- include/net/netmem.h | 16 ---------------- 1 file changed, 16 deletions(-)
include/net/netmem.h +0 -16
@@ -190,22 +190,6 @@ static inline struct netmem_desc *__netmem_clear_lsb(netmem_ref netmem)return (struct netmem_desc *)((__force unsigned long )netmem & ~NET_IOV ); } -/** -* __netmem_get_pp - unsafely get pointer to the &page_pool backing @netmem -* @netmem: netmem reference to get the pointer from -* -* Unsafe version of netmem_get_pp(). When @netmem is always page-backed, -* e.g. when it's a header buffer, performs faster and generates smaller -* object code (avoids clearing the LSB). When @netmem points to IOV, -* provokes invalid memory access. -* -* Return: pointer to the &page_pool (garbage if @netmem is not page-backed). -*/ -static inline struct page_pool *__netmem_get_pp (netmem_ref netmem) -{ -return __netmem_to_page (netmem)->pp; -} -static inline struct page_pool *netmem_get_pp (netmem_ref netmem) {return __netmem_clear_lsb (netmem)->pp;
Signature · 1 line
2.17.1
Re: [RFC 17/19] netmem: remove __netmem_get_pp()
Quoted 4 lines · Byungchul Park
There are no users of
__netmem_get_pp(). Remove it.Signed-off-by Byungchul Park <[email protected]>
Signature · 2 lines
Thanks, Mina
RFC 18/19 page_pool: make page_pool_get_dma_addr() just wrap page_pool_get_dma_addr_netmem()
In reply to Byungchul ParkThe page pool members in struct page cannot be removed unless it's not allowed to access any of them via struct page.
Do not access 'page->dma_addr' directly in page_pool_get_dma_addr() but just wrap page_pool_get_dma_addr_netmem() safely.
--- include/net/page_pool/helpers.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
include/net/page_pool/helpers.h +1 -6
@@ -441,12 +441,7 @@ static inline dma_addr_t page_pool_get_dma_addr_netmem(netmem_ref netmem)*/ static inline dma_addr_t page_pool_get_dma_addr (const struct page *page) { -dma_addr_t ret = page->dma_addr; - -if (PAGE_POOL_32BIT_ARCH_WITH_64BIT_DMA ) - ret <<=PAGE_SHIFT ; - -return ret; +return page_pool_get_dma_addr_netmem (page_to_netmem (page)); } static inline void __page_pool_dma_sync_for_cpu(const struct page_pool *pool,
Signature · 1 line
2.17.1
Re: [RFC 18/19] page_pool: make page_pool_get_dma_addr() just wrap page_pool_get_dma_addr_netmem()
Quoted 8 lines · Byungchul Park
The page pool members in struct page cannot be removed unless it's not allowed to access any of them via struct page.
Do not access '
page->dma_addr' directly inpage_pool_get_dma_addr()but just wrappage_pool_get_dma_addr_netmem()safely.Signed-off-by Byungchul Park <[email protected]>
Signature · 2 lines
Thanks, Mina
Re: [RFC 18/19] page_pool: make page_pool_get_dma_addr() just wrap page_pool_get_dma_addr_netmem()
In reply to Byungchul ParkQuoted 31 lines · Byungchul Park
The page pool members in struct page cannot be removed unless it's not allowed to access any of them via struct page.
Do not access '
page->dma_addr' directly inpage_pool_get_dma_addr()but just wrappage_pool_get_dma_addr_netmem()safely.Signed-off-by Byungchul Park <[email protected]>--- include/net/page_pool/helpers.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)include/net/page_pool/helpers.h +1
-7@@ -441,12 +441,7 @@ static inline dma_addr_t page_pool_get_dma_addr_netmem(netmem_ref netmem)*/ static inline dma_addr_t page_pool_get_dma_addr (const struct page *page) { -dma_addr_t ret = page->dma_addr; - -if (PAGE_POOL_32BIT_ARCH_WITH_64BIT_DMA ) - ret <<=PAGE_SHIFT ; - -return ret; +return page_pool_get_dma_addr_netmem (page_to_netmem (page)); } static inline void __page_pool_dma_sync_for_cpu(const struct page_pool *pool, --
Quoted 2 lines
2.17.1
RFC 19/19 mm, netmem: remove the page pool members in struct page
In reply to Byungchul ParkNow that all the users of the page pool members in struct page have been gone, the members can be removed from struct page. However, the space in struct page needs to be kept using a place holder with the same size, until struct netmem_desc has its own instance, not overlayed onto struct page, to avoid conficting with other members within struct page.
Remove the page pool members in struct page and replace with a place holder. The place holder should be removed once struct netmem_desc has its own instance.
--- include/linux/mm_types.h | 13 ++----------- include/net/netmem.h | 35 +---------------------------------- include/net/netmem_type.h | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+), 45 deletions(-) create mode 100644 include/net/netmem_type.h
include/linux/mm_types.h +2 -11
@@ -20,6 +20,7 @@#include <linux/seqlock.h> #include <linux/percpu_counter.h> #include <linux/types.h> +#include <net/netmem_type.h> /* for page pool */ #include <asm/mmu.h>
@@ -118,17 +119,7 @@ struct page {*/ unsigned long private; }; -struct {/* page_pool used by netstack */ -/** -* @pp_magic: magic value to avoid recycling non -* page_pool allocated pages. -*/ -unsigned long pp_magic; -struct page_pool *pp; -unsigned long _pp_mapping_pad; -unsigned long dma_addr; -atomic_long_t pp_ref_count; - }; +struct __netmem_desc place_holder_1;/* for page pool */ struct {/* Tail pages of compound page */ unsigned long compound_head;/* Bit zero is set */ };
include/net/netmem.h +1 -34
@@ -10,6 +10,7 @@#include <linux/mm.h> #include <net/net_debug.h> +#include <net/netmem_type.h> /* net_iov */
@@ -20,15 +21,6 @@ DECLARE_STATIC_KEY_FALSE(page_pool_mem_providers);*/ #define NET_IOV 0x01UL -struct netmem_desc { -unsigned long __unused_padding; -unsigned long pp_magic; -struct page_pool *pp; -struct net_iov_area *owner; -unsigned long dma_addr; -atomic_long_t pp_ref_count; -}; -struct net_iov_area {/* Array of net_iovs for this area. */ struct netmem_desc *niovs;
@@ -38,31 +30,6 @@ struct net_iov_area {unsigned long base_virtual; }; -/* These fields in struct page are used by the page_pool and net stack: -* -* struct { -* unsigned long pp_magic; -* struct page_pool *pp; -* unsigned long _pp_mapping_pad; -* unsigned long dma_addr; -* atomic_long_t pp_ref_count; -* }; -* -* We mirror the page_pool fields here so the page_pool can access these fields -* without worrying whether the underlying fields belong to a page or net_iov. -* -* The non-net stack fields of struct page are private to the mm stack and must -* never be mirrored to net_iov. -*/ -#define NET_IOV_ASSERT_OFFSET (pg, iov) \ - static_assert(offsetof(struct page, pg) == \ - offsetof(struct netmem_desc, iov)) -NET_IOV_ASSERT_OFFSET (pp_magic, pp_magic); -NET_IOV_ASSERT_OFFSET (pp, pp); -NET_IOV_ASSERT_OFFSET (dma_addr, dma_addr); -NET_IOV_ASSERT_OFFSET (pp_ref_count, pp_ref_count); -#undef NET_IOV_ASSERT_OFFSET -static inline struct net_iov_area *net_iov_owner (const struct netmem_desc *niov) {return niov->owner;
include/net/netmem_type.h new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Author: Byungchul Park <[email protected]> +*/ + +#ifndef _NET_NETMEM_TYPE_H +#define _NET_NETMEM_TYPE_H + +#include <linux/stddef.h> + +struct netmem_desc { +unsigned long __unused_padding; + struct_group_tagged(__netmem_desc, actual_data, + unsigned long pp_magic; +struct page_pool *pp; +struct net_iov_area *owner; +unsigned long dma_addr; +atomic_long_t pp_ref_count; + ); +}; + +#endif /* _NET_NETMEM_TYPE_H */
Signature · 1 line
2.17.1
Re: [RFC 19/19] mm, netmem: remove the page pool members in struct page
Quoted 139 lines · Byungchul Park
Now that all the users of the page pool members in struct page have been gone, the members can be removed from struct page. However, the space in struct page needs to be kept using a place holder with the same size, until struct
netmem_deschas its own instance, not overlayed onto struct page, to avoid conficting with other members within struct page.Remove the page pool members in struct page and replace with a place holder. The place holder should be removed once struct
netmem_deschas its own instance.Signed-off-by Byungchul Park <[email protected]>--- include/linux/mm_types.h | 13 ++----------- include/net/netmem.h | 35 +---------------------------------- include/net/netmem_type.h | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+), 45 deletions(-) create mode 100644 include/net/netmem_type.hinclude/linux/mm_types.h +2
-11@@ -20,6 +20,7 @@#include <linux/seqlock.h> #include <linux/percpu_counter.h> #include <linux/types.h> +#include <net/netmem_type.h> /* for page pool */ #include <asm/mmu.h> @@ -118,17 +119,7 @@ struct page {*/ unsigned long private; }; -struct {/* page_pool used by netstack */ -/** -* @pp_magic: magic value to avoid recycling non -* page_pool allocated pages. -*/ -unsigned long pp_magic; -struct page_pool *pp; -unsigned long _pp_mapping_pad; -unsigned long dma_addr; -atomic_long_t pp_ref_count; - }; +struct __netmem_desc place_holder_1;/* for page pool */ struct {/* Tail pages of compound page */ unsigned long compound_head;/* Bit zero is set */ };include/net/netmem.h +1
-34@@ -10,6 +10,7 @@#include <linux/mm.h> #include <net/net_debug.h> +#include <net/netmem_type.h> /* net_iov */ @@ -20,15 +21,6 @@ DECLARE_STATIC_KEY_FALSE(page_pool_mem_providers);*/ #define NET_IOV 0x01UL -struct netmem_desc { -unsigned long __unused_padding; -unsigned long pp_magic; -struct page_pool *pp; -struct net_iov_area *owner; -unsigned long dma_addr; -atomic_long_t pp_ref_count; -}; -struct net_iov_area {/* Array of net_iovs for this area. */ struct netmem_desc *niovs;@@ -38,31 +30,6 @@ struct net_iov_area {unsigned long base_virtual; }; -/* These fields in struct page are used by the page_pool and net stack: -* -* struct { -* unsigned long pp_magic; -* struct page_pool *pp; -* unsigned long _pp_mapping_pad; -* unsigned long dma_addr; -* atomic_long_t pp_ref_count; -* }; -* -* We mirror the page_pool fields here so the page_pool can access these fields -* without worrying whether the underlying fields belong to a page or net_iov. -* -* The non-net stack fields of struct page are private to the mm stack and must -* never be mirrored to net_iov. -*/ -#define NET_IOV_ASSERT_OFFSET (pg, iov) \ - static_assert(offsetof(struct page, pg) == \ - offsetof(struct netmem_desc, iov)) -NET_IOV_ASSERT_OFFSET (pp_magic, pp_magic); -NET_IOV_ASSERT_OFFSET (pp, pp); -NET_IOV_ASSERT_OFFSET (dma_addr, dma_addr); -NET_IOV_ASSERT_OFFSET (pp_ref_count, pp_ref_count); -#undef NET_IOV_ASSERT_OFFSET -static inline struct net_iov_area *net_iov_owner (const struct netmem_desc *niov) {return niov->owner;include/net/netmem_type.h new file +22
-1@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Author: Byungchul Park <[email protected]> +*/ + +#ifndef _NET_NETMEM_TYPE_H +#define _NET_NETMEM_TYPE_H + +#include <linux/stddef.h> + +struct netmem_desc { +unsigned long __unused_padding; + struct_group_tagged(__netmem_desc, actual_data, + unsigned long pp_magic; +struct page_pool *pp; +struct net_iov_area *owner; +unsigned long dma_addr; +atomic_long_t pp_ref_count; + ); +}; + +#endif /* _NET_NETMEM_TYPE_H */ --
Quoted 2 lines
2.17.1
Currently the only restriction on net_iov is that some of its fields need to be cache aligned with some of the fields of struct page, but there is no restriction on new fields added to net_iov. We already have fields in net_iov that have nothing to do with struct page and shouldn't be part of struct page. Like net_iov_area *owner. I don't think net_iov_area should be part of struct page and I don't think we should add restrictions of net_iov.
What I would suggest here is, roughly:
1. Add a new struct:
struct netmem_desc {
unsigned long pp_magic;
struct page_pool *pp;
unsigned long _pp_mapping_pad;
unsigned long dma_addr;
atomic_long_t pp_ref_count;
};2. Then update struct page to include this entry instead of the definitions:
struct page {
...
struct netmem_desc place_holder_1; /* for page pool */
...
}
3. And update struct net_iov to also include netmem_desc:
struct net_iov {
struct netmem_desc desc;
struct net_iov_area *owner;
/* More net_iov specific fields in the future */
};And drop patch 1 which does a rename.
Essentially netmem_desc can be an encapsulation of the shared fields between struct page and struct net_iov.
Signature · 2 lines
Thanks, Mina
Re: [RFC 19/19] mm, netmem: remove the page pool members in struct page
Quoted 2 lines · Mina Almasry
Currently the only restriction on
net_iovis that some of its fields need to be cache aligned with some of the fields of struct page, but
Cache aligned? Do you mean alias (ie be at the same offset)?
Quoted 12 lines
What I would suggest here is, roughly:
1. Add a new struct:
struct netmem_desc { unsigned long pp_magic; struct page_pool *pp; unsigned long _pp_mapping_pad; unsigned long dma_addr; atomic_long_t pp_ref_count; };
Quoted 7 lines
2. Then update struct page to include this entry instead of the definitions:
struct page {
...
structnetmem_descplace_holder_1; /* for page pool */
...
}
No, the point is to move these fields out of struct page entirely.
At some point (probably this year), we'll actually kmalloc the netmem_desc (and shrink struct page), but for now, it'll overlap the other fields in struct page.
Quoted 8 lines
3. And update struct
net_iovto also includenetmem_desc:struct net_iov { struct netmem_desc desc; struct net_iov_area *owner; /* More net_iov specific fields in the future */ };
Quoted 4 lines
And drop patch 1 which does a rename.
Essentially
netmem_desccan be an encapsulation of the shared fields between struct page and structnet_iov.
That is not the goal.
Re: [RFC 19/19] mm, netmem: remove the page pool members in struct page
Quoted 27 lines · Matthew Wilcox
Quoted 2 lines · Mina Almasry
Currently the only restriction on
net_iovis that some of its fields need to be cache aligned with some of the fields of struct page, butCache aligned? Do you mean alias (ie be at the same offset)?
Quoted 12 lines
What I would suggest here is, roughly:
1. Add a new struct:
struct netmem_desc { unsigned long pp_magic; struct page_pool *pp; unsigned long _pp_mapping_pad; unsigned long dma_addr; atomic_long_t pp_ref_count; };Quoted 7 lines
2. Then update struct page to include this entry instead of the definitions:
struct page {
...
structnetmem_descplace_holder_1; /* for page pool */
...
}
Quoted 6 lines
No, the point is to move these fields out of struct page entirely.
At some point (probably this year), we'll actually kmalloc the
netmem_desc(and shrink struct page), but for now, it'll overlap the other fields in struct page.
Right, all I'm saying is that if it's at all possible to keep net_iov something that can be extended with fields unrelated to struct page, lets do that. net_iov already has fields that should not belong in struct page like net_iov_owner and I think more will be added.
I'm thinking netmem_desc can be the fields that are shared between struct net_iov and struct page (but both can have more specific to the different memory types). As you say, for now netmem_desc can currently overlap fields in struct page and struct net_iov, and a follow up change can replace it with something that gets kmalloced and (I guess?) there is a pointer in struct page or struct net_iov that refers to the netmem_desc that contains the shared fields.
Signature · 2 lines
Thanks, Mina
Re: [RFC 19/19] mm, netmem: remove the page pool members in struct page
Quoted 4 lines · Mina Almasry
Right, all I'm saying is that if it's at all possible to keep
net_iovsomething that can be extended with fields unrelated to struct page, lets do that.net_iovalready has fields that should not belong in struct page likenet_iov_ownerand I think more will be added.
Sure, that's fine.
Quoted 7 lines
I'm thinking
netmem_desccan be the fields that are shared between structnet_iovand struct page (but both can have more specific to the different memory types). As you say, for nownetmem_desccan currently overlap fields in struct page and structnet_iov, and a follow up change can replace it with something that gets kmalloced and (I guess?) there is a pointer in struct page or structnet_iovthat refers to thenetmem_descthat contains the shared fields.
I'm sure I've pointed you at
https://kernelnewbies.org/MatthewWilcox/Memdescs before.
But I wouldn't expect to have net_iov contain a pointer to netmem_desc, rather it would embed a netmem_desc. Unless there's a good reason to separate them.
Actually, I'd hope to do away with net_iov entirely. Networking should handle memory-on-PCI-devices the same way everybody else does (as hotplugged memory) rather than with its own special structures.
Re: [RFC 19/19] mm, netmem: remove the page pool members in struct page
Quoted 9 lines · Matthew Wilcox
Quoted 4 lines · Mina Almasry
Right, all I'm saying is that if it's at all possible to keep
net_iovsomething that can be extended with fields unrelated to struct page, lets do that.net_iovalready has fields that should not belong in struct page likenet_iov_ownerand I think more will be added.Sure, that's fine.
Excellent!
Quoted 11 lines
Quoted 7 lines
I'm thinking
netmem_desccan be the fields that are shared between structnet_iovand struct page (but both can have more specific to the different memory types). As you say, for nownetmem_desccan currently overlap fields in struct page and structnet_iov, and a follow up change can replace it with something that gets kmalloced and (I guess?) there is a pointer in struct page or structnet_iovthat refers to thenetmem_descthat contains the shared fields.I'm sure I've pointed you at
https://kernelnewbies.org/MatthewWilcox/Memdescs before.
I've gone through that again. Some of it is a bit over my head (sorry), but this page does say that page->compound_head will have a link to memdesc:
https://kernelnewbies.org/MatthewWilcox/Memdescs/Path
That's an approach that sounds fine to me. We can have net_iov follow that pattern if necessary (have in it a field that points to the memdesc).
Quoted 4 lines
But I wouldn't expect to have
net_iovcontain a pointer tonetmem_desc, rather it would embed anetmem_desc. Unless there's a good reason to separate them.
net_iov embedding netmem_desc sounds fine as well to me.
Quoted 4 lines
Actually, I'd hope to do away with
net_ioventirely. Networking should handle memory-on-PCI-devices the same way everybody else does (as hotplugged memory) rather than with its own special structures.
Doing away with net_iov entirely is a different conversation. From the devmem TCP side, you're much more of an expert than me but my experience is that the GPU devices we initially net_iovs for, dmabuf is the standard way of sharing memory, and the dma-buf importer just gets a scatterlist, and has to either work with the scatterlist directly or create descriptors (like net_iov) to handle chunks of the scatterlist.
I think we discussed this before and you said to me you have long term plans to get rid of scatterlists. Once that is done we may be able to do away with the dma-buf use case for net_iovs, but the conversation about migrating scatterlists to something new is well over my head and probably needs discussion with the dma-buf maintainers.
Note also that the users of net_iov have expanded and io_uring has a dependency on it as well.
The good news (I think) is that Byungchul's effort does not require the removal of net_iov. From looking at this patchset I think what he's trying to do is very compatible with net_iovs with minor modifications.
Signature · 2 lines
Thanks, Mina
Re: [RFC 19/19] mm, netmem: remove the page pool members in struct page
In reply to Byungchul ParkQuoted 18 lines · Byungchul Park
+++
b/include/linux/mm_types.hinclude/linux/mm_types.h +1
-5@@ -20,6 +20,7 @@#include <linux/seqlock.h> #include <linux/percpu_counter.h> #include <linux/types.h> +#include <net/netmem_type.h> /* for page pool */ #include <asm/mmu.h> @@ -118,17 +119,7 @@ struct page {*/ unsigned long private; }; -struct {/* page_pool used by netstack */ -/** -* @pp_magic: magic value to avoid recycling non -* page_pool allocated pages. -*/
include/linux/mm_types.h struct page { · line 125
Quoted 10 lines
include/linux/mm_types.h +1
-6-unsigned long pp_magic; -struct page_pool *pp; -unsigned long _pp_mapping_pad; -unsigned long dma_addr; -atomic_long_t pp_ref_count; - }; +struct __netmem_desc place_holder_1;/* for page pool */ struct {/* Tail pages of compound page */ unsigned long compound_head;/* Bit zero is set */ };
The include and the place holder aren't needed.
include/net/netmem.h line 13
Quoted 9 lines
include/net/netmem.h +1
-0@@ -10,6 +10,7 @@#include <linux/mm.h> #include <net/net_debug.h> +#include <net/netmem_type.h>
... which I think means you don't need the separate header file.
Quoted 36 lines
include/net/netmem.h +0
-23/* net_iov */ @@ -20,15 +21,6 @@ DECLARE_STATIC_KEY_FALSE(page_pool_mem_providers);*/ #define NET_IOV 0x01UL -struct netmem_desc { -unsigned long __unused_padding; -unsigned long pp_magic; -struct page_pool *pp; -struct net_iov_area *owner; -unsigned long dma_addr; -atomic_long_t pp_ref_count; -}; -struct net_iov_area {/* Array of net_iovs for this area. */ struct netmem_desc *niovs;@@ -38,31 +30,6 @@ struct net_iov_area {unsigned long base_virtual; }; -/* These fields in struct page are used by the page_pool and net stack: -* -* struct { -* unsigned long pp_magic; -* struct page_pool *pp; -* unsigned long _pp_mapping_pad; -* unsigned long dma_addr; -* atomic_long_t pp_ref_count; -* }; -* -* We mirror the page_pool fields here so the page_pool can access these fields -* without worrying whether the underlying fields belong to a page or net_iov. -* -* The non-net stack fields of struct page are private to the mm stack and must
include/net/netmem.h struct net_iov_area { · line 64
Quoted 10 lines
include/net/netmem.h +0
-10-* never be mirrored to net_iov. -*/ -#define NET_IOV_ASSERT_OFFSET (pg, iov) \ - static_assert(offsetof(struct page, pg) == \ - offsetof(struct netmem_desc, iov)) -NET_IOV_ASSERT_OFFSET (pp_magic, pp_magic); -NET_IOV_ASSERT_OFFSET (pp, pp); -NET_IOV_ASSERT_OFFSET (dma_addr, dma_addr); -NET_IOV_ASSERT_OFFSET (pp_ref_count, pp_ref_count); -#undef NET_IOV_ASSERT_OFFSET
... but you do want to keep asserting that netmem_desc and net_iov have the same offsets. And you want to assert that struct page is big enough to hold everything in netmem_desc, like we do for slab:
static_assert(sizeof(struct slab) <= sizeof(struct page));
Re: [RFC 19/19] mm, netmem: remove the page pool members in struct page
Quoted 23 lines · Matthew Wilcox
Quoted 22 lines · Byungchul Park
+++
b/include/linux/mm_types.hinclude/linux/mm_types.h +1
-9@@ -20,6 +20,7 @@#include <linux/seqlock.h> #include <linux/percpu_counter.h> #include <linux/types.h> +#include <net/netmem_type.h> /* for page pool */ #include <asm/mmu.h> @@ -118,17 +119,7 @@ struct page {*/ unsigned long private; }; -struct {/* page_pool used by netstack */ -/** -* @pp_magic: magic value to avoid recycling non -* page_pool allocated pages. -*/ -unsigned long pp_magic; -struct page_pool *pp; -unsigned long _pp_mapping_pad; -unsigned long dma_addr;
Quoted 8 lines
include/linux/mm_types.h struct page { · line 125
Quoted 6 lines
include/linux/mm_types.h +1
-2-atomic_long_t pp_ref_count; - }; +struct __netmem_desc place_holder_1;/* for page pool */ struct {/* Tail pages of compound page */ unsigned long compound_head;/* Bit zero is set */ };The include and the place holder aren't needed.
Or netmem_desc overlaying struct page might be conflict with other fields of sturct page e.g. _mapcount, _refcount and the like, once the layout of struct page *extremly changes* in the future before netmem_desc has its own instance.
So placing a place holder like this is the safest way, IMO, to prevent the unextected result. Am I missing something?
Quoted 11 lines
include/net/netmem.h line 13
Quoted 9 lines
include/net/netmem.h +1
-0@@ -10,6 +10,7 @@#include <linux/mm.h> #include <net/net_debug.h> +#include <net/netmem_type.h> ... which I think means you don't need the separate header file.
Agree if I don't use the place holder in mm_types.h.
Quoted 51 lines
Quoted 36 lines
include/net/netmem.h +0
-23/* net_iov */ @@ -20,15 +21,6 @@ DECLARE_STATIC_KEY_FALSE(page_pool_mem_providers);*/ #define NET_IOV 0x01UL -struct netmem_desc { -unsigned long __unused_padding; -unsigned long pp_magic; -struct page_pool *pp; -struct net_iov_area *owner; -unsigned long dma_addr; -atomic_long_t pp_ref_count; -}; -struct net_iov_area {/* Array of net_iovs for this area. */ struct netmem_desc *niovs;@@ -38,31 +30,6 @@ struct net_iov_area {unsigned long base_virtual; }; -/* These fields in struct page are used by the page_pool and net stack: -* -* struct { -* unsigned long pp_magic; -* struct page_pool *pp; -* unsigned long _pp_mapping_pad; -* unsigned long dma_addr; -* atomic_long_t pp_ref_count; -* }; -* -* We mirror the page_pool fields here so the page_pool can access these fields -* without worrying whether the underlying fields belong to a page or net_iov. -* -* The non-net stack fields of struct page are private to the mm stack and must include/net/netmem.h struct net_iov_area { · line 64
Quoted 10 lines
include/net/netmem.h +0
-10-* never be mirrored to net_iov. -*/ -#define NET_IOV_ASSERT_OFFSET (pg, iov) \ - static_assert(offsetof(struct page, pg) == \ - offsetof(struct netmem_desc, iov)) -NET_IOV_ASSERT_OFFSET (pp_magic, pp_magic); -NET_IOV_ASSERT_OFFSET (pp, pp); -NET_IOV_ASSERT_OFFSET (dma_addr, dma_addr); -NET_IOV_ASSERT_OFFSET (pp_ref_count, pp_ref_count); -#undef NET_IOV_ASSERT_OFFSET... but you do want to keep asserting that
netmem_descandnet_iovhave the same offsets. And you want to assert that struct page is big enough to hold everything innetmem_desc, like we do for slab:
Quoted 1 line
static_assert(sizeof(struct slab) <= sizeof(struct page));
I will. However, as I mentioned above, the total size doesn't matter but the layout change of struct page might matter, I think.
Byungchul
Re: [RFC 19/19] mm, netmem: remove the page pool members in struct page
Quoted 8 lines · Byungchul Park
Quoted 6 lines · Matthew Wilcox
include/linux/mm_types.h struct page { · line 125
Quoted 4 lines
include/linux/mm_types.h +1
-0+struct __netmem_desc place_holder_1;/* for page pool */ struct {/* Tail pages of compound page */ unsigned long compound_head;/* Bit zero is set */ };The include and the place holder aren't needed.
Quoted 4 lines
Or
netmem_descoverlaying struct page might be conflict with other fields of sturct page e.g._mapcount,_refcountand the like, once the layout of struct page *extremly changes* in the future beforenetmem_deschas its own instance.
That's not how it'll happen. When the layout of struct page changes, it'll shrink substantially (cut in half). That means that dynamically allocating netmem_desc must happen first (along with slab, folio, etc, etc).
Re: [RFC 19/19] mm, netmem: remove the page pool members in struct page
Quoted 14 lines · Matthew Wilcox
Quoted 8 lines · Byungchul Park
Quoted 6 lines · Matthew Wilcox
include/linux/mm_types.h struct page { · line 125
Quoted 4 lines
include/linux/mm_types.h +1
-0+struct __netmem_desc place_holder_1;/* for page pool */ struct {/* Tail pages of compound page */ unsigned long compound_head;/* Bit zero is set */ };The include and the place holder aren't needed.
Quoted 4 lines
Or
netmem_descoverlaying struct page might be conflict with other fields of sturct page e.g._mapcount,_refcountand the like, once the layout of struct page *extremly changes* in the future beforenetmem_deschas its own instance.
Quoted 4 lines
That's not how it'll happen. When the layout of struct page changes, it'll shrink substantially (cut in half). That means that dynamically allocating
netmem_descmust happen first (along with slab, folio, etc, etc).
Just in case, lemme explain what I meant, for *example*:
struct page {
unsigned long flags;
union {
struct A { /* 24 bytes */ };
struct B { /* 40 bytes */ };
struct page_pool { /* 40 bytes */ };
};
atomic_t _mapcount;
atomic_t _refcount;
unsigend long memcf_data;
...
};
/* overlayed on struct page */
struct netmem_desc { /* 8 + 40 bytes */ };After removing page_pool fields:
struct page {
unsigned long flags;
union {
struct A { /* 24 bytes */ };
struct B { /* 40 bytes */ };
};
atomic_t _mapcount;
atomic_t _refcount;
unsigend long memcf_data;
...
};
/* overlayed on struct page */
struct netmem_desc { /* 8 + 40 bytes */ };The above still looks okay cuz operating on struct netmem_desc is not touching _mapcount or _refcount in struct page.
However, either the size of struct B gets reduced to 32 bytes or struct B gets away out of struct page for some reason, it will look like:
struct page {
unsigned long flags;
union {
struct A { /* 24 bytes */ };
struct B { /* 32 bytes */ };
};
atomic_t _mapcount;
atomic_t _refcount;
unsigend long memcf_data;
...
};
/* overlayed on struct page */
struct netmem_desc { /* 8 + 40 bytes */ };In here, operating on struct netmem_desc can smash _mapcount and _refcount in struct page unexpectedly, even though sizeof(struct netmem_desc) <= sizeof(struct page). That's why I think the place holder is necessary until it completely gets separated so as to have its own instance.
If you believe it's still okay, I will remove the place holder, I still concern it tho.
Byungchul
Re: [RFC 19/19] mm, netmem: remove the page pool members in struct page
Quoted 1 line · Byungchul Park
Just in case, lemme explain what I meant, for *example*:
I understood what you meant.
Quoted 5 lines
In here, operating on struct
netmem_desccan smash_mapcountand_refcountin struct page unexpectedly, even thoughsizeof(struct netmem_desc)<= sizeof(struct page). That's why I think the place holder is necessary until it completely gets separated so as to have its own instance.
We could tighten up the assert a bit. eg
static_assert(sizeof(struct netmem_desc) <= offsetof(struct page, _refcount));
We _can't_ shrink struct page until struct folio is dynamically allocated. The same patch series that dynamically allocates folio will do the same for netmem and slab and ptdesc and ...
Re: [RFC 19/19] mm, netmem: remove the page pool members in struct page
Quoted 11 lines · Matthew Wilcox
Quoted 1 line · Byungchul Park
Just in case, lemme explain what I meant, for *example*:
I understood what you meant.
Quoted 5 lines
In here, operating on struct
netmem_desccan smash_mapcountand_refcountin struct page unexpectedly, even thoughsizeof(struct netmem_desc)<= sizeof(struct page). That's why I think the place holder is necessary until it completely gets separated so as to have its own instance.
Quoted 3 lines
We could tighten up the assert a bit. eg
static_assert(sizeof(struct netmem_desc) <= offsetof(struct page, _refcount));
This mitigates what I concern. I will replace the place holder with this (but it must never happen to relocate the fields in struct page by any chance for any reason until the day. I trust you :).
Byungchul
Quoted 3 lines
We _can't_ shrink struct page until struct folio is dynamically allocated. The same patch series that dynamically allocates folio will do the same for netmem and slab and ptdesc and ...
kernel test robot
build botRe: [RFC 19/19] mm, netmem: remove the page pool members in struct page
In reply to Byungchul Parkkernel test robot noticed the following build errors:
Hi Byungchul,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:
[auto build test ERROR on fd93b3350b4314eebd8fbf0fea3ca7fe48d777e3]
url: https://github.com/intel-lab-lkp/linux/commits/Byungchul-Park/netmem-rename-struct-net_iov-to-struct-netmem_desc/20250509-195458 base: fd93b3350b4314eebd8fbf0fea3ca7fe48d777e3 patch link: https://lore.kernel.org/r/20250509115126.63190-20-byungchul%40sk.com patch subject: [RFC 19/19] mm, netmem: remove the page pool members in struct page config: x86_64-buildonly-randconfig-003-20250510 (https://download.01.org/0day-ci/archive/20250510/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250510/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
drivers/net/netdevsim/netdev.c: In function 'nsim_pp_hold_write':
>> drivers/net/netdevsim/netdev.c:852:49: error: 'struct page' has no member named 'pp'
852 | page_pool_put_full_page(ns->page->pp, ns->page, false);
| ^~
drivers/net/netdevsim/netdev.c: In function 'nsim_destroy':
drivers/net/netdevsim/netdev.c:1077:49: error: 'struct page' has no member named 'pp'
1077 | page_pool_put_full_page(ns->page->pp, ns->page, false);
| ^~vim +852 drivers/net/netdevsim/netdev.c
1580cbcbfe770b Jakub Kicinski 2024-04-12 827
1580cbcbfe770b Jakub Kicinski 2024-04-12 828 static ssize_t
1580cbcbfe770b Jakub Kicinski 2024-04-12 829 nsim_pp_hold_write(struct file *file, const char __user *data,
1580cbcbfe770b Jakub Kicinski 2024-04-12 830 size_t count, loff_t *ppos)
1580cbcbfe770b Jakub Kicinski 2024-04-12 831 {
1580cbcbfe770b Jakub Kicinski 2024-04-12 832 struct netdevsim *ns = file->private_data;
1580cbcbfe770b Jakub Kicinski 2024-04-12 833 ssize_t ret;
1580cbcbfe770b Jakub Kicinski 2024-04-12 834 bool val;
1580cbcbfe770b Jakub Kicinski 2024-04-12 835
1580cbcbfe770b Jakub Kicinski 2024-04-12 836 ret = kstrtobool_from_user(data, count, &val);
1580cbcbfe770b Jakub Kicinski 2024-04-12 837 if (ret)
1580cbcbfe770b Jakub Kicinski 2024-04-12 838 return ret;
1580cbcbfe770b Jakub Kicinski 2024-04-12 839
1580cbcbfe770b Jakub Kicinski 2024-04-12 840 rtnl_lock();
1580cbcbfe770b Jakub Kicinski 2024-04-12 841 ret = count;
1580cbcbfe770b Jakub Kicinski 2024-04-12 842 if (val == !!ns->page)
1580cbcbfe770b Jakub Kicinski 2024-04-12 843 goto exit;
1580cbcbfe770b Jakub Kicinski 2024-04-12 844
1580cbcbfe770b Jakub Kicinski 2024-04-12 845 if (!netif_running(ns->netdev) && val) {
1580cbcbfe770b Jakub Kicinski 2024-04-12 846 ret = -ENETDOWN;
1580cbcbfe770b Jakub Kicinski 2024-04-12 847 } else if (val) {
915c82f842f955 Jakub Kicinski 2025-01-07 848 ns->page = page_pool_dev_alloc_pages(ns->rq[0]->page_pool);
1580cbcbfe770b Jakub Kicinski 2024-04-12 849 if (!ns->page)
1580cbcbfe770b Jakub Kicinski 2024-04-12 850 ret = -ENOMEM;
1580cbcbfe770b Jakub Kicinski 2024-04-12 851 } else {
1580cbcbfe770b Jakub Kicinski 2024-04-12 @852 page_pool_put_full_page(ns->page->pp, ns->page, false);
1580cbcbfe770b Jakub Kicinski 2024-04-12 853 ns->page = NULL;
1580cbcbfe770b Jakub Kicinski 2024-04-12 854 }
1580cbcbfe770b Jakub Kicinski 2024-04-12 855
1580cbcbfe770b Jakub Kicinski 2024-04-12 856 exit:
b9b8301d369b4c Eric Dumazet 2024-12-16 857 rtnl_unlock();
b9b8301d369b4c Eric Dumazet 2024-12-16 858 return ret;
1580cbcbfe770b Jakub Kicinski 2024-04-12 859 }
1580cbcbfe770b Jakub Kicinski 2024-04-12 860 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Ilias Apalodimas
maintainerRe: [RFC 19/19] mm, netmem: remove the page pool members in struct page
In reply to Byungchul ParkHi Byungchul
Quoted 7 lines · Byungchul Park
Now that all the users of the page pool members in struct page have been gone, the members can be removed from struct page. However, the space in struct page needs to be kept using a place holder with the same size, until struct
netmem_deschas its own instance, not overlayed onto struct page, to avoid conficting with other members within struct page.
FWIW similar mirroring was intially proposed [0] a few years ago
Quoted 3 lines
Remove the page pool members in struct page and replace with a place holder. The place holder should be removed once struct
netmem_deschas its own instance.
instance? To make sure I understand this, the netmem_descs are expected to be allocated in the future right?
[...]
include/net/netmem_type.h line 3
Quoted 13 lines
include/net/netmem.h +0
-1-static inline struct net_iov_area *net_iov_owner (const struct netmem_desc *niov) {return niov->owner;include/net/netmem_type.h new file +3
-0@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Author: Byungchul Park <[email protected]>
Shouldn't Minas authorship be preserved here?
Quoted 20 lines
include/net/netmem_type.h new file +19
-1+*/ + +#ifndef _NET_NETMEM_TYPE_H +#define _NET_NETMEM_TYPE_H + +#include <linux/stddef.h> + +struct netmem_desc { +unsigned long __unused_padding; + struct_group_tagged(__netmem_desc, actual_data, + unsigned long pp_magic; +struct page_pool *pp; +struct net_iov_area *owner; +unsigned long dma_addr; +atomic_long_t pp_ref_count; + ); +}; + +#endif /* _NET_NETMEM_TYPE_H */ --
Quoted 2 lines
2.17.1
[0] https://lore.kernel.org/netdev/[email protected]/
Thanks
/Ilias
Re: [RFC 19/19] mm, netmem: remove the page pool members in struct page
Quoted 11 lines · Ilias Apalodimas
Hi Byungchul
Quoted 7 lines · Byungchul Park
Now that all the users of the page pool members in struct page have been gone, the members can be removed from struct page. However, the space in struct page needs to be kept using a place holder with the same size, until struct
netmem_deschas its own instance, not overlayed onto struct page, to avoid conficting with other members within struct page.
Quoted 8 lines
FWIW similar mirroring was intially proposed [0] a few years ago
Quoted 3 lines
Remove the page pool members in struct page and replace with a place holder. The place holder should be removed once struct
netmem_deschas its own instance.instance? To make sure I understand this, the
netmem_descsare expected to be allocated in the future right?
Yes.
Quoted 17 lines
[...]
include/net/netmem_type.h line 3
Quoted 13 lines
include/net/netmem.h +0
-1-static inline struct net_iov_area *net_iov_owner (const struct netmem_desc *niov) {return niov->owner;include/net/netmem_type.h new file +3
-0@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Author: Byungchul Park <[email protected]> Shouldn't Minas authorship be preserved here?
Ah. I dunno what I'm supposed to do in the case. I will remove the author part :) if it's still okay.
Byungchul
Quoted 26 lines
Quoted 20 lines
include/net/netmem_type.h new file +19
-1+*/ + +#ifndef _NET_NETMEM_TYPE_H +#define _NET_NETMEM_TYPE_H + +#include <linux/stddef.h> + +struct netmem_desc { +unsigned long __unused_padding; + struct_group_tagged(__netmem_desc, actual_data, + unsigned long pp_magic; +struct page_pool *pp; +struct net_iov_area *owner; +unsigned long dma_addr; +atomic_long_t pp_ref_count; + ); +}; + +#endif /* _NET_NETMEM_TYPE_H */ --Quoted 2 lines
2.17.1
[0] https://lore.kernel.org/netdev/[email protected]/
Thanks
/Ilias
Quoted 17 lines · Byungchul Park
The MM subsystem is trying to reduce struct page to a single pointer. The first step towards that is splitting struct page by its individual users, as has already been done with folio and slab. This patchset does that for netmem which is used for page pools.
Matthew Wilcox tried and stopped the same work, you can see in:
https://lore.kernel.org/linux-mm/[email protected]/Mina Almasry already has done a lot fo prerequisite works by luck, he said :). I stacked my patches on the top of his work e.i. netmem.
I focused on removing the page pool members in struct page this time, not moving the allocation code of page pool from net to mm. It can be done later if needed.
Quoted 6 lines
There are still a lot of works to do, to remove the dependency on struct page in the network subsystem. I will continue to work on this after this base patchset is merged.
This patchset is based on mm tree's mm-unstable branch.
This series largely looks good to me, but a couple of things:
- For deep changes like this to the page_pool, I think we need a before/after run to Jesper's currently out-of-tree benchmark to see any regressions:
https://lore.kernel.org/netdev/[email protected]/
- Also please CC Pavel on iterations related to netmem/net_iov, they are reusing that in io_uring code for iouring rx rc as well.
--
Thanks,
Mina
Quoted 25 lines · Mina Almasry
Quoted 17 lines · Byungchul Park
The MM subsystem is trying to reduce struct page to a single pointer. The first step towards that is splitting struct page by its individual users, as has already been done with folio and slab. This patchset does that for netmem which is used for page pools.
Matthew Wilcox tried and stopped the same work, you can see in:
https://lore.kernel.org/linux-mm/[email protected]/Mina Almasry already has done a lot fo prerequisite works by luck, he said :). I stacked my patches on the top of his work e.i. netmem.
I focused on removing the page pool members in struct page this time, not moving the allocation code of page pool from net to mm. It can be done later if needed.
Quoted 6 lines
There are still a lot of works to do, to remove the dependency on struct page in the network subsystem. I will continue to work on this after this base patchset is merged.
This patchset is based on mm tree's mm-unstable branch.
Quoted 6 lines
This series largely looks good to me, but a couple of things:
- For deep changes like this to the
page_pool, I think we need a before/after run to Jesper's currently out-of-tree benchmark to see any regressions:
https://lore.kernel.org/netdev/[email protected]/
Sure. I will check it.
Quoted 2 lines
- Also please CC Pavel on iterations related to netmem/net_iov, they are reusing that in
io_uringcode for iouring rx rc as well.
I will. Thank you.
Byungchul
Quoted 3 lines
--
Thanks,
Mina
Pavel Begunkov
maintainerQuoted 33 lines · Byungchul Park
Quoted 25 lines · Mina Almasry
Quoted 17 lines · Byungchul Park
The MM subsystem is trying to reduce struct page to a single pointer. The first step towards that is splitting struct page by its individual users, as has already been done with folio and slab. This patchset does that for netmem which is used for page pools.
Matthew Wilcox tried and stopped the same work, you can see in:
https://lore.kernel.org/linux-mm/[email protected]/Mina Almasry already has done a lot fo prerequisite works by luck, he said :). I stacked my patches on the top of his work e.i. netmem.
I focused on removing the page pool members in struct page this time, not moving the allocation code of page pool from net to mm. It can be done later if needed.
Quoted 6 lines
There are still a lot of works to do, to remove the dependency on struct page in the network subsystem. I will continue to work on this after this base patchset is merged.
This patchset is based on mm tree's mm-unstable branch.
Quoted 6 lines
This series largely looks good to me, but a couple of things:
- For deep changes like this to the
page_pool, I think we need a before/after run to Jesper's currently out-of-tree benchmark to see any regressions:
https://lore.kernel.org/netdev/[email protected]/
Quoted 6 lines
Sure. I will check it.
Quoted 2 lines
- Also please CC Pavel on iterations related to netmem/net_iov, they are reusing that in
io_uringcode for iouring rx rc as well.I will. Thank you.
Mina, thanks for CC'ing. And since it's touching io_uring, future versions need to CC it as well.
Signature · 1 line
Pavel Begunkov