Create page_pool_alloc_netmem to be the mirror of page_pool_alloc.
This enables drivers that want currently use page_pool_alloc to
transition to netmem by converting the call sites to
page_pool_alloc_netmem.
Signed-off-by: Mina Almasry <almasrymina@google.com>
---
include/net/page_pool/helpers.h | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helpers.h
index 793e6fd78bc5..8e548ff3044c 100644
--- a/include/net/page_pool/helpers.h
+++ b/include/net/page_pool/helpers.h
@@ -116,22 +116,22 @@ static inline struct page *page_pool_dev_alloc_frag(struct page_pool *pool,
return page_pool_alloc_frag(pool, offset, size, gfp);
}
-static inline struct page *page_pool_alloc(struct page_pool *pool,
- unsigned int *offset,
- unsigned int *size, gfp_t gfp)
+static inline netmem_ref page_pool_alloc_netmem(struct page_pool *pool,
+ unsigned int *offset,
+ unsigned int *size, gfp_t gfp)
{
unsigned int max_size = PAGE_SIZE << pool->p.order;
- struct page *page;
+ netmem_ref netmem;
if ((*size << 1) > max_size) {
*size = max_size;
*offset = 0;
- return page_pool_alloc_pages(pool, gfp);
+ return page_pool_alloc_netmems(pool, gfp);
}
- page = page_pool_alloc_frag(pool, offset, *size, gfp);
- if (unlikely(!page))
- return NULL;
+ netmem = page_pool_alloc_frag_netmem(pool, offset, *size, gfp);
+ if (unlikely(!netmem))
+ return 0;
/* There is very likely not enough space for another fragment, so append
* the remaining size to the current fragment to avoid truesize
@@ -142,7 +142,14 @@ static inline struct page *page_pool_alloc(struct page_pool *pool,
pool->frag_offset = max_size;
}
- return page;
+ return netmem;
+}
+
+static inline struct page *page_pool_alloc(struct page_pool *pool,
+ unsigned int *offset,
+ unsigned int *size, gfp_t gfp)
+{
+ return netmem_to_page(page_pool_alloc_netmem(pool, offset, size, gfp));
}
/**
--
2.47.0.163.g1226f6d8fa-goog
On 2024/10/30 4:45, Mina Almasry wrote: > Create page_pool_alloc_netmem to be the mirror of page_pool_alloc. > > This enables drivers that want currently use page_pool_alloc to > transition to netmem by converting the call sites to > page_pool_alloc_netmem. For old API, page_pool_alloc_pages() always return a whole page, and page_pool_alloc() returns a whole page or a page fragment based on the requested size. For new netmem API, page_pool_alloc_netmems() always return a whole netmem, and page_pool_alloc_netmem() returns a whole netmem or a netmem fragment based on the requested size. Isn't it a little odd that old and new are not following the same pattern?
On Fri, Nov 1, 2024 at 4:14 AM Yunsheng Lin <linyunsheng@huawei.com> wrote: > > On 2024/10/30 4:45, Mina Almasry wrote: > > Create page_pool_alloc_netmem to be the mirror of page_pool_alloc. > > > > This enables drivers that want currently use page_pool_alloc to > > transition to netmem by converting the call sites to > > page_pool_alloc_netmem. > > For old API, page_pool_alloc_pages() always return a whole page, and > page_pool_alloc() returns a whole page or a page fragment based on the > requested size. > > For new netmem API, page_pool_alloc_netmems() always return a whole > netmem, and page_pool_alloc_netmem() returns a whole netmem or a netmem > fragment based on the requested size. > > Isn't it a little odd that old and new are not following the same > pattern? Hi Yunsheng, The intention is that page_pool_alloc_pages is mirrored by page_pool_alloc_netmems. And page_pool_alloc is mirrored by page_pool_alloc_netmem. From your description, the behavior is the same for each function and its mirror. What is the gap in the pattern that you see? -- Thanks, Mina
On 11/1/2024 9:10 PM, Mina Almasry wrote: ... >> >> Isn't it a little odd that old and new are not following the same >> pattern? > > Hi Yunsheng, > > The intention is that page_pool_alloc_pages is mirrored by > page_pool_alloc_netmems. > > And page_pool_alloc is mirrored by page_pool_alloc_netmem. > >>From your description, the behavior is the same for each function and > its mirror. What is the gap in the pattern that you see? I was mostly referring to the API naming pattern. Isn't it better if page_pool_alloc is mirrored by netmem_pool_alloc and netmem_pool_alloc_netmems is mirrored by page_pool_alloc_pages() from API naming prespective? And maybe page_pool_alloc_frag can be mirrored by netmem_pool_alloc_frag in the future? Also, it would be good to update Documentation/networking/page_pool.rst for those new netmem APIs, or create a new doc file for them. >
On Sun, Nov 3, 2024 at 6:35 AM Yunsheng Lin <yunshenglin0825@gmail.com> wrote: > > On 11/1/2024 9:10 PM, Mina Almasry wrote: > > ... > > >> > >> Isn't it a little odd that old and new are not following the same > >> pattern? > > > > Hi Yunsheng, > > > > The intention is that page_pool_alloc_pages is mirrored by > > page_pool_alloc_netmems. > > > > And page_pool_alloc is mirrored by page_pool_alloc_netmem. > > > >>From your description, the behavior is the same for each function and > > its mirror. What is the gap in the pattern that you see? > > I was mostly referring to the API naming pattern. > > Isn't it better if page_pool_alloc is mirrored by netmem_pool_alloc and > netmem_pool_alloc_netmems is mirrored by page_pool_alloc_pages() from > API naming prespective? > I've been treating the page_pool_* prefix to all the page_pool functions as constant in all the renames so far. I replace 'page' with 'netmem' when available, or add a _netmem postfix when available. > And maybe page_pool_alloc_frag can be mirrored by netmem_pool_alloc_frag > in the future? > > Also, it would be good to update Documentation/networking/page_pool.rst > for those new netmem APIs, or create a new doc file for them. > Heard. I do have an action item to update the docs. Currently, outside of drivers immediately looking to immediately adopt devmem tcp, there is no need yet to use the netmem APIs, but I do hope to make them more widespread (and perhaps deprecate the page APIs when it's time to do so). -- Thanks, Mina
© 2016 - 2024 Red Hat, Inc.