diff mbox series

[net-next,v9,09/20] net: page_pool: introduce page_pool_mp_return_in_cache

Message ID 20241218003748.796939-10-dw@davidwei.uk (mailing list archive)
State New
Delegated to: Netdev Maintainers
Headers show
Series [net-next,v9,01/20] net: page_pool: don't cast mp param to devmem | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next, async
netdev/apply fail Patch does not apply to net-next-0

Commit Message

David Wei Dec. 18, 2024, 12:37 a.m. UTC
From: Pavel Begunkov <asml.silence@gmail.com>

Add a helper that allows a page pool memory provider to efficiently
return a netmem off the allocation callback.

Reviewed-by: Mina Almasry <almasrymina@google.com>
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: David Wei <dw@davidwei.uk>
---
 include/net/page_pool/helpers.h |  2 ++
 net/core/page_pool.c            | 15 +++++++++++++++
 2 files changed, 17 insertions(+)
diff mbox series

Patch

diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helpers.h
index 872947179bae..d968eebc4322 100644
--- a/include/net/page_pool/helpers.h
+++ b/include/net/page_pool/helpers.h
@@ -486,6 +486,8 @@  static inline void page_pool_nid_changed(struct page_pool *pool, int new_nid)
 #if defined(CONFIG_PAGE_POOL)
 void page_pool_set_pp_info(struct page_pool *pool, netmem_ref netmem);
 void page_pool_clear_pp_info(netmem_ref netmem);
+
+void page_pool_mp_return_in_cache(struct page_pool *pool, netmem_ref netmem);
 #else
 static inline void page_pool_set_pp_info(struct page_pool *pool,
 					 netmem_ref netmem)
diff --git a/net/core/page_pool.c b/net/core/page_pool.c
index 784a547b2ca4..bd7f33d02652 100644
--- a/net/core/page_pool.c
+++ b/net/core/page_pool.c
@@ -1195,3 +1195,18 @@  void page_pool_update_nid(struct page_pool *pool, int new_nid)
 	}
 }
 EXPORT_SYMBOL(page_pool_update_nid);
+
+/*
+ * page_pool_mp_return_in_cache() - return a netmem to the allocation cache.
+ * @pool:	pool from which pages were allocated
+ * @netmem:	netmem to return
+ *
+ * Return already allocated and accounted netmem to the page pool's allocation
+ * cache. The function doesn't provide synchronisation and can only be called
+ * off the mp_ops->alloc_netmems() path.
+ */
+void page_pool_mp_return_in_cache(struct page_pool *pool, netmem_ref netmem)
+{
+	page_pool_dma_sync_for_device(pool, netmem, -1);
+	pool->alloc.cache[pool->alloc.count++] = netmem;
+}