[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHS8izOMhPLOGgxxWdQgx-FgAmbsUj=j7fEAZBRo1=Z4W=zYFg@mail.gmail.com>
Date: Tue, 12 Aug 2025 17:14:34 -0700
From: Mina Almasry <almasrymina@...gle.com>
To: Pavel Begunkov <asml.silence@...il.com>
Cc: netdev@...r.kernel.org, Jakub Kicinski <kuba@...nel.org>,
Eric Dumazet <edumazet@...gle.com>, Paolo Abeni <pabeni@...hat.com>, davem@...emloft.net,
sdf@...ichev.me, dw@...idwei.uk, Jesper Dangaard Brouer <hawk@...nel.org>,
Ilias Apalodimas <ilias.apalodimas@...aro.org>, Byungchul Park <byungchul@...com>
Subject: Re: [RFC net-next v1 5/6] net: page_pool: convert refcounting helpers
to nmdesc
On Mon, Aug 11, 2025 at 9:28 AM Pavel Begunkov <asml.silence@...il.com> wrote:
>
> Use netmem descriptors for the basic buffer refcounting helpers and use
> them to implement all other variants. This way netmem type aware helpers
> can avoid intermediate netmem casting and bit masking/unmasking.
>
> Signed-off-by: Pavel Begunkov <asml.silence@...il.com>
> ---
> include/net/netmem.h | 5 -----
> include/net/page_pool/helpers.h | 29 ++++++++++++++++++++++-------
> net/core/devmem.c | 5 -----
> 3 files changed, 22 insertions(+), 17 deletions(-)
>
> diff --git a/include/net/netmem.h b/include/net/netmem.h
> index ca6d5d151acc..7b5f1427f272 100644
> --- a/include/net/netmem.h
> +++ b/include/net/netmem.h
> @@ -324,11 +324,6 @@ static inline struct page_pool *netmem_get_pp(netmem_ref netmem)
> return netmem_to_nmdesc(netmem)->pp;
> }
>
> -static inline atomic_long_t *netmem_get_pp_ref_count_ref(netmem_ref netmem)
> -{
> - return &netmem_to_nmdesc(netmem)->pp_ref_count;
> -}
> -
> static inline bool netmem_is_pref_nid(netmem_ref netmem, int pref_nid)
> {
> /* NUMA node preference only makes sense if we're allocating
> diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helpers.h
> index a9774d582933..bc54040186d9 100644
> --- a/include/net/page_pool/helpers.h
> +++ b/include/net/page_pool/helpers.h
> @@ -234,9 +234,14 @@ page_pool_get_dma_dir(const struct page_pool *pool)
> return pool->p.dma_dir;
> }
>
> +static inline void page_pool_fragment_nmdesc(struct netmem_desc *desc, long nr)
> +{
> + atomic_long_set(&desc->pp_ref_count, nr);
> +}
> +
> static inline void page_pool_fragment_netmem(netmem_ref netmem, long nr)
> {
> - atomic_long_set(netmem_get_pp_ref_count_ref(netmem), nr);
> + page_pool_fragment_nmdesc(netmem_to_nmdesc(netmem), nr);
> }
>
> /**
> @@ -259,12 +264,12 @@ static inline void page_pool_fragment_netmem(netmem_ref netmem, long nr)
> */
> static inline void page_pool_fragment_page(struct page *page, long nr)
> {
> - page_pool_fragment_netmem(page_to_netmem(page), nr);
> + page_pool_fragment_nmdesc(pp_page_to_nmdesc(page), nr);
> }
>
> -static inline long page_pool_unref_netmem(netmem_ref netmem, long nr)
> +static inline long page_pool_unref_nmdesc(struct netmem_desc *desc, long nr)
> {
> - atomic_long_t *pp_ref_count = netmem_get_pp_ref_count_ref(netmem);
> + atomic_long_t *pp_ref_count = &desc->pp_ref_count;
nit: I think we can also kill the pp_ref_count local var and use
desc->pp_ref_count directly.
> long ret;
>
> /* If nr == pp_ref_count then we have cleared all remaining
> @@ -307,19 +312,29 @@ static inline long page_pool_unref_netmem(netmem_ref netmem, long nr)
> return ret;
> }
>
> +static inline long page_pool_unref_netmem(netmem_ref netmem, long nr)
> +{
> + return page_pool_unref_nmdesc(netmem_to_nmdesc(netmem), nr);
> +}
> +
> static inline long page_pool_unref_page(struct page *page, long nr)
> {
> - return page_pool_unref_netmem(page_to_netmem(page), nr);
> + return page_pool_unref_nmdesc(pp_page_to_nmdesc(page), nr);
> +}
> +
> +static inline void page_pool_ref_nmdesc(struct netmem_desc *desc)
> +{
> + atomic_long_inc(&desc->pp_ref_count);
> }
>
> static inline void page_pool_ref_netmem(netmem_ref netmem)
> {
> - atomic_long_inc(netmem_get_pp_ref_count_ref(netmem));
> + page_pool_ref_nmdesc(netmem_to_nmdesc(netmem));
> }
>
> static inline void page_pool_ref_page(struct page *page)
> {
> - page_pool_ref_netmem(page_to_netmem(page));
> + page_pool_ref_nmdesc(pp_page_to_nmdesc(page));
> }
>
> static inline bool page_pool_unref_and_test(netmem_ref netmem)
> diff --git a/net/core/devmem.c b/net/core/devmem.c
> index 24c591ab38ae..e084dad11506 100644
> --- a/net/core/devmem.c
> +++ b/net/core/devmem.c
> @@ -440,14 +440,9 @@ void mp_dmabuf_devmem_destroy(struct page_pool *pool)
>
> bool mp_dmabuf_devmem_release_page(struct page_pool *pool, netmem_ref netmem)
> {
> - long refcount = atomic_long_read(netmem_get_pp_ref_count_ref(netmem));
> -
> if (WARN_ON_ONCE(!netmem_is_net_iov(netmem)))
> return false;
>
> - if (WARN_ON_ONCE(refcount != 1))
> - return false;
> -
Rest of the patch looks good to me, but this comes across as a
completely unrelated clean up/change or something? Lets keep the
WARN_ON_ONCE?
--
Thanks,
Mina
Powered by blists - more mailing lists