From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C399C4167B for ; Fri, 1 Dec 2023 09:59:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E31D28D006A; Fri, 1 Dec 2023 04:59:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DE1DF8D0001; Fri, 1 Dec 2023 04:59:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C5CD38D006A; Fri, 1 Dec 2023 04:59:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B24F68D0001 for ; Fri, 1 Dec 2023 04:59:42 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 8200CA0184 for ; Fri, 1 Dec 2023 09:59:42 +0000 (UTC) X-FDA: 81517802604.07.7B6B6ED Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) by imf27.hostedemail.com (Postfix) with ESMTP id 681FB40005 for ; Fri, 1 Dec 2023 09:59:40 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=linaro.org header.s=google header.b=CoLaofTp; spf=pass (imf27.hostedemail.com: domain of ilias.apalodimas@linaro.org designates 209.85.208.170 as permitted sender) smtp.mailfrom=ilias.apalodimas@linaro.org; dmarc=pass (policy=none) header.from=linaro.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701424780; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=v8xfEISk7pzBuxwXZ9jIgMgJUtpQ3vF9P/DTU1ldOiQ=; b=hYHu16x+k5vKyB+imKfvltctN1lbMZq2+GNWRIZ2DSJQwKCOY2dbo2TEzFDnAsu9TeyN32 DVyuvYfoEXY+oRzU8UO/biRWRXC2Mtg4Fla0vqfjvgazGhdc8M40jWpQiKJlOBdU19/1Qu w/XZV2lBYPAICx5CHUlL+MScMyM+u3Y= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701424780; a=rsa-sha256; cv=none; b=ncv5htQSLItzV0BNNBi/8t/rxP+CTZ3MfPCxMmZXU2MgP6AGFJ0EG36eAtMlZcQMa4er9V lp0SD7ffC9bZSlXXJIDeiWKqxyX44GJLd4Pj6sTyf7FKWtgxZv+obWnpwjWYOkRwZDp5Ew XYcYjrNh/8/2zkf7sVSqioVWVg/0vRA= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=linaro.org header.s=google header.b=CoLaofTp; spf=pass (imf27.hostedemail.com: domain of ilias.apalodimas@linaro.org designates 209.85.208.170 as permitted sender) smtp.mailfrom=ilias.apalodimas@linaro.org; dmarc=pass (policy=none) header.from=linaro.org Received: by mail-lj1-f170.google.com with SMTP id 38308e7fff4ca-2c9b8363683so23872221fa.3 for ; Fri, 01 Dec 2023 01:59:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1701424778; x=1702029578; darn=kvack.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=v8xfEISk7pzBuxwXZ9jIgMgJUtpQ3vF9P/DTU1ldOiQ=; b=CoLaofTp11qTQn//m8s+/rOXpw6Hn82zpxW1ds/TXY2BVP3Q7Ph0BAvL2TZlFJpOm2 uJnFrOFwkeKZEUx2eWRzIFDeOo0yJGZeibo4ZLJSG//w7ieIfLA/DiaKb4T0Iu7tF+KO 6cYxGNpvArjUAifbxa3DR22q0O4ZHzM2LMrVIOmgl3e/FzHqZUwpBRMfv8MLsSt7lmw+ SV018e6l7Gjn13W6lXeJSyAX88g2prKc/+LS3/EXKfFxtoq2mVo5iVm4Je5cksK4KfMW qDWmSMhzyEVQ2IWJc4GLKslcjM5Xg8vJEyp/L+Af/e7jCUVI8j407MIjlgLfMFynkpU4 8Iqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701424778; x=1702029578; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=v8xfEISk7pzBuxwXZ9jIgMgJUtpQ3vF9P/DTU1ldOiQ=; b=JPAJIfJbkulSJLVMAqh9ww+IQDRU+8S4uZsHk9/PeIunw7UZDHf5oxU0Nw/XTW0zhr yrbppA6V8E5m2bcZwnyT+qwPCfJl9JhaBDah8YAsro8RjkZQhQegTm/DGXQOkSC001fU +uza0cgpxHel5uyl8/5Xt+2HqG5zDJF6A/0u4aTP23QcSuJQtVI20MmoIZI5xKwO0KN8 Vx0Z5jQwUCUEI0HLqgJOkoLbPNh2cnNf+o8K/jQXnwToqNeRPgONaYvQgcZa0aeXLH8o W25Zcu5iCNnKdEAlZwF1+XY5SWzIgrrdIN0NS10S8f+pZH95S2z8supTWv9703lRfcyp D89Q== X-Gm-Message-State: AOJu0YwSGJE9zrBDl8PjjqwoJ9X/lA8Gv1lyL1eNZBWhqbyS5njmMIAW 47OHlDsFBj1sEFohtMREsmWVk1lPrVLanrEbhueu6w== X-Google-Smtp-Source: AGHT+IGltiXMMV1luSXBgaT/R2iQg3uBrCZ5i0upMVhksLGBYJazC2Kz+X2cyym/LkioE/ajFvOhj8ENfD5YA7WbFxc= X-Received: by 2002:a2e:904a:0:b0:2c9:af1b:de5f with SMTP id n10-20020a2e904a000000b002c9af1bde5fmr594561ljg.37.1701424778405; Fri, 01 Dec 2023 01:59:38 -0800 (PST) MIME-Version: 1.0 References: <20231130115611.6632-1-liangchen.linux@gmail.com> <20231130115611.6632-2-liangchen.linux@gmail.com> In-Reply-To: <20231130115611.6632-2-liangchen.linux@gmail.com> From: Ilias Apalodimas Date: Fri, 1 Dec 2023 11:59:02 +0200 Message-ID: Subject: Re: [PATCH net-next v6 1/4] page_pool: Rename pp_frag_count to pp_ref_count To: Liang Chen Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, hawk@kernel.org, linyunsheng@huawei.com, netdev@vger.kernel.org, linux-mm@kvack.org, jasowang@redhat.com Content-Type: multipart/alternative; boundary="0000000000008781cf060b6fd3f9" X-Rspamd-Queue-Id: 681FB40005 X-Rspam-User: X-Stat-Signature: psn5rmanqyxrtrra4tf94odbhfkeanfs X-Rspamd-Server: rspam03 X-HE-Tag: 1701424780-892901 X-HE-Meta: U2FsdGVkX182bLYDyfpB43TuVfeerFxgEmj6eoGPxPg4f+AijQPmkQGF+w7UQhKrG+azkuDsTTtnLOJRXbSMrFNnQM5nOMicujECV2uKcQ/XdncFNJqtiOHu7ZS/NcB4Ieja1gnDsKA13DMf7Q3tlDkAXszuMtfQiyvWAo+4+1FG2UbOdtPNEwItOJnrI/IXNOWxTGMUs4H851mXvtZA1oSNV4WauMof/b0RjO/DvdF32wnv6POCZOE/0nRwAVHLDXNgd7wsPg87qDwMtjayZUCBEP6WsCO2iGMX+cXs8oPb7vBdB5Vgl+OUtvjnJP8shmTXD++3ivVsBT2RcPyUWewQso7fLzOKrOjHgCpv8km5y6XVrnDkGkfxIQE4zOm5x9sLW0Bj+NLGXKEdgZnrMKEe8gRJj5oxT/FVJXD1zSOALmpsyDMDRzh24O8i/KYiBycYyovNEW1QTxkN9WVUvayVVpEU85//jdn92A5PfosWuubkkcZxnKBE/3DowEQQvzNzU1fYbXE62T2yAJpG6GLnF7jtRfVj26L94NW8izVIzdA15kHLnI/ivVz85J8/W8joh18/1P+M6VC+sztGxbPmLU3blSsPeNayhedAAG0kYziHzuQkJep1lUJVWfyijg4Nf4LT2f7SzJkGSNuTCCfS+fTEYdUfbvEswoO5v7Oxjl92grLKIJwfWiUe8uuE74UIIqfEVUUIg0fGJDUo1rSohztnuiaZEymrxiSrah7Iurb7Q+9DbRAyQlHkGpIZ3xKUc1eSwNTUhCHMSYtPn9yK2dxNs9yvkoU1qYDMbVKRO5fGiRrkLF7pWz+U6p4FVTRHQ1SbORmhxUd24fRH8M1sZZShSs+NjQm0BvKABmovozXKusDNFN2uyjt3DqmAZjdtTncVs35wwvf7dp0DpzhAbAGzDeErvRwRolo5VRv+HrdOdhKxiSQkFHdD9IM4/JHa9lQFTf8Q1CIMs1e WvRNnZN/ BGUaGQygF90LujfAMlZz3ciz2WYpZXVWjddrqqNoeGa7+rwbnyIxPBdBXKnI/nRcoMEWCdVuKmYtsvJnA82HBV7mpQIq02h7Vgj2aT+Jzlp1sOf21bR6SwbWBNwwVWSdFun3FX/ZoN7hSULnTpwKJVE3EGAbeWOvT7RKkFFOP4uKOR9D4x6V2BjkjGeV9DLmOgMJOE6PqQBfNvOrC4esWwGIJYUIVONt3BwK3dlduvDw5kWUugykEBKltYAcFKnGKXS8r4MsI3yFDyRNgobl5R6NDFsIAjGrLFHj8OjTu2g939ukMNLHVZQwsxQ/79LgxWyfOYOSZF86nf76yjz5EL2BwHFfz8tAwgms7S1lPZDVti2mBk5ZDC3FG+84k4TAHCGMWT57GkcP+GL2uHICF2VrVfCIg9wtb3pm9MMYUobdpb/Uu8Nx9WDOVOxjWH2ZhKCNhanuiFQKI2T2sSz2Ucfj+gpNZWkx5nuQ21AtygX2TS2sApM9LhZzomKa1QPkosTZqiZc/eY9oMBLQ7ZtBRzkBl5hjr5rMQfQLyVBdgPi5m58= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: --0000000000008781cf060b6fd3f9 Content-Type: text/plain; charset="UTF-8" Hi Liang, On Thu, 30 Nov 2023 at 13:59, Liang Chen wrote: > To support multiple users referencing the same fragment, pp_frag_count is > renamed to pp_ref_count to better reflect its actual meaning based on the > suggestion from [1]. > The patch does more than what the description says and those should be in 2 different patches. I am ok with pp_frag_count -> pp_ref_count, for the functions I am not the rename makes anything better. Jakub are you ok with the name changes or is it going to make bisecting a pain? Thanks /Ilias > [1] > > http://lore.kernel.org/netdev/f71d9448-70c8-8793-dc9a-0eb48a570300@huawei.com > > Signed-off-by: Liang Chen > Reviewed-by: Yunsheng Lin > --- > .../net/ethernet/mellanox/mlx5/core/en_rx.c | 4 +- > include/linux/mm_types.h | 2 +- > include/net/page_pool/helpers.h | 45 ++++++++++--------- > include/net/page_pool/types.h | 6 +-- > net/core/page_pool.c | 12 ++--- > 5 files changed, 37 insertions(+), 32 deletions(-) > > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c > b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c > index 8d9743a5e42c..98d33ac7ec64 100644 > --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c > +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c > @@ -298,8 +298,8 @@ static void mlx5e_page_release_fragmented(struct > mlx5e_rq *rq, > u16 drain_count = MLX5E_PAGECNT_BIAS_MAX - frag_page->frags; > struct page *page = frag_page->page; > > - if (page_pool_defrag_page(page, drain_count) == 0) > - page_pool_put_defragged_page(rq->page_pool, page, -1, > true); > + if (page_pool_unref_page(page, drain_count) == 0) > + page_pool_put_unrefed_page(rq->page_pool, page, -1, true); > } > > static inline int mlx5e_get_rx_frag(struct mlx5e_rq *rq, > diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h > index 957ce38768b2..64e4572ef06d 100644 > --- a/include/linux/mm_types.h > +++ b/include/linux/mm_types.h > @@ -125,7 +125,7 @@ struct page { > struct page_pool *pp; > unsigned long _pp_mapping_pad; > unsigned long dma_addr; > - atomic_long_t pp_frag_count; > + atomic_long_t pp_ref_count; > }; > struct { /* Tail pages of compound page */ > unsigned long compound_head; /* Bit zero is set > */ > diff --git a/include/net/page_pool/helpers.h > b/include/net/page_pool/helpers.h > index 4ebd544ae977..9dc8eaf8a959 100644 > --- a/include/net/page_pool/helpers.h > +++ b/include/net/page_pool/helpers.h > @@ -29,7 +29,7 @@ > * page allocated from page pool. Page splitting enables memory saving > and thus > * avoids TLB/cache miss for data access, but there also is some cost to > * implement page splitting, mainly some cache line dirtying/bouncing for > - * 'struct page' and atomic operation for page->pp_frag_count. > + * 'struct page' and atomic operation for page->pp_ref_count. > * > * The API keeps track of in-flight pages, in order to let API users know > when > * it is safe to free a page_pool object, the API users must call > @@ -214,69 +214,74 @@ inline enum dma_data_direction > page_pool_get_dma_dir(struct page_pool *pool) > return pool->p.dma_dir; > } > > -/* pp_frag_count represents the number of writers who can update the page > +/* pp_ref_count represents the number of writers who can update the page > * either by updating skb->data or via DMA mappings for the device. > * We can't rely on the page refcnt for that as we don't know who might be > * holding page references and we can't reliably destroy or sync DMA > mappings > * of the fragments. > * > - * When pp_frag_count reaches 0 we can either recycle the page if the page > + * pp_ref_count initially corresponds to the number of fragments. However, > + * when multiple users start to reference a single fragment, for example > in > + * skb_try_coalesce, the pp_ref_count will become greater than the number > of > + * fragments. > + * > + * When pp_ref_count reaches 0 we can either recycle the page if the page > * refcnt is 1 or return it back to the memory allocator and destroy any > * mappings we have. > */ > static inline void page_pool_fragment_page(struct page *page, long nr) > { > - atomic_long_set(&page->pp_frag_count, nr); > + atomic_long_set(&page->pp_ref_count, nr); > } > > -static inline long page_pool_defrag_page(struct page *page, long nr) > +static inline long page_pool_unref_page(struct page *page, long nr) > { > long ret; > > - /* If nr == pp_frag_count then we have cleared all remaining > + /* If nr == pp_ref_count then we have cleared all remaining > * references to the page: > * 1. 'n == 1': no need to actually overwrite it. > * 2. 'n != 1': overwrite it with one, which is the rare case > - * for pp_frag_count draining. > + * for pp_ref_count draining. > * > * The main advantage to doing this is that not only we avoid a > atomic > * update, as an atomic_read is generally a much cheaper operation > than > * an atomic update, especially when dealing with a page that may > be > - * partitioned into only 2 or 3 pieces; but also unify the > pp_frag_count > + * referenced by only 2 or 3 users; but also unify the pp_ref_count > * handling by ensuring all pages have partitioned into only 1 > piece > * initially, and only overwrite it when the page is partitioned > into > * more than one piece. > */ > - if (atomic_long_read(&page->pp_frag_count) == nr) { > + if (atomic_long_read(&page->pp_ref_count) == nr) { > /* As we have ensured nr is always one for constant case > using > * the BUILD_BUG_ON(), only need to handle the > non-constant case > - * here for pp_frag_count draining, which is a rare case. > + * here for pp_ref_count draining, which is a rare case. > */ > BUILD_BUG_ON(__builtin_constant_p(nr) && nr != 1); > if (!__builtin_constant_p(nr)) > - atomic_long_set(&page->pp_frag_count, 1); > + atomic_long_set(&page->pp_ref_count, 1); > > return 0; > } > > - ret = atomic_long_sub_return(nr, &page->pp_frag_count); > + ret = atomic_long_sub_return(nr, &page->pp_ref_count); > WARN_ON(ret < 0); > > - /* We are the last user here too, reset pp_frag_count back to 1 to > + /* We are the last user here too, reset pp_ref_count back to 1 to > * ensure all pages have been partitioned into 1 piece initially, > * this should be the rare case when the last two fragment users > call > - * page_pool_defrag_page() currently. > + * page_pool_unref_page() currently. > */ > if (unlikely(!ret)) > - atomic_long_set(&page->pp_frag_count, 1); > + atomic_long_set(&page->pp_ref_count, 1); > > return ret; > } > > -static inline bool page_pool_is_last_frag(struct page *page) > +static inline bool page_pool_is_last_ref(struct page *page) > { > - /* If page_pool_defrag_page() returns 0, we were the last user */ > - return page_pool_defrag_page(page, 1) == 0; > + /* If page_pool_unref_page() returns 0, we were the last user */ > + return page_pool_unref_page(page, 1) == 0; > } > > /** > @@ -301,10 +306,10 @@ static inline void page_pool_put_page(struct > page_pool *pool, > * allow registering MEM_TYPE_PAGE_POOL, but shield linker. > */ > #ifdef CONFIG_PAGE_POOL > - if (!page_pool_is_last_frag(page)) > + if (!page_pool_is_last_ref(page)) > return; > > - page_pool_put_defragged_page(pool, page, dma_sync_size, > allow_direct); > + page_pool_put_unrefed_page(pool, page, dma_sync_size, > allow_direct); > #endif > } > > diff --git a/include/net/page_pool/types.h b/include/net/page_pool/types.h > index e1bb92c192de..6a5323619f6e 100644 > --- a/include/net/page_pool/types.h > +++ b/include/net/page_pool/types.h > @@ -224,9 +224,9 @@ static inline void page_pool_put_page_bulk(struct > page_pool *pool, void **data, > } > #endif > > -void page_pool_put_defragged_page(struct page_pool *pool, struct page > *page, > - unsigned int dma_sync_size, > - bool allow_direct); > +void page_pool_put_unrefed_page(struct page_pool *pool, struct page *page, > + unsigned int dma_sync_size, > + bool allow_direct); > > static inline bool is_page_pool_compiled_in(void) > { > diff --git a/net/core/page_pool.c b/net/core/page_pool.c > index df2a06d7da52..106220b1f89c 100644 > --- a/net/core/page_pool.c > +++ b/net/core/page_pool.c > @@ -650,8 +650,8 @@ __page_pool_put_page(struct page_pool *pool, struct > page *page, > return NULL; > } > > -void page_pool_put_defragged_page(struct page_pool *pool, struct page > *page, > - unsigned int dma_sync_size, bool > allow_direct) > +void page_pool_put_unrefed_page(struct page_pool *pool, struct page *page, > + unsigned int dma_sync_size, bool > allow_direct) > { > page = __page_pool_put_page(pool, page, dma_sync_size, > allow_direct); > if (page && !page_pool_recycle_in_ring(pool, page)) { > @@ -660,7 +660,7 @@ void page_pool_put_defragged_page(struct page_pool > *pool, struct page *page, > page_pool_return_page(pool, page); > } > } > -EXPORT_SYMBOL(page_pool_put_defragged_page); > +EXPORT_SYMBOL(page_pool_put_unrefed_page); > > /** > * page_pool_put_page_bulk() - release references on multiple pages > @@ -687,7 +687,7 @@ void page_pool_put_page_bulk(struct page_pool *pool, > void **data, > struct page *page = virt_to_head_page(data[i]); > > /* It is not the last user for the page frag case */ > - if (!page_pool_is_last_frag(page)) > + if (!page_pool_is_last_ref(page)) > continue; > > page = __page_pool_put_page(pool, page, -1, false); > @@ -729,7 +729,7 @@ static struct page *page_pool_drain_frag(struct > page_pool *pool, > long drain_count = BIAS_MAX - pool->frag_users; > > /* Some user is still using the page frag */ > - if (likely(page_pool_defrag_page(page, drain_count))) > + if (likely(page_pool_unref_page(page, drain_count))) > return NULL; > > if (page_ref_count(page) == 1 && !page_is_pfmemalloc(page)) { > @@ -750,7 +750,7 @@ static void page_pool_free_frag(struct page_pool *pool) > > pool->frag_page = NULL; > > - if (!page || page_pool_defrag_page(page, drain_count)) > + if (!page || page_pool_unref_page(page, drain_count)) > return; > > page_pool_return_page(pool, page); > -- > 2.31.1 > > --0000000000008781cf060b6fd3f9 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Liang,

On Thu, 30 Nov 2023 at 13:59= , Liang Chen <liangchen.lin= ux@gmail.com> wrote:
To support multiple users referencing the same fragment, pp_fra= g_count is
renamed to pp_ref_count to better reflect its actual meaning based on the suggestion from [1].

The patch does more than what = the description says and those should be in 2 different patches.
I am ok with= pp_frag_count -> pp_ref_count, for the functions I am not the rename ma= kes anything better.

Jakub are you ok with the name changes or is it going= to make bisecting a pain?

Thanks
/Ilias


[1]
http://lore.kernel.org/= netdev/f71d9448-70c8-8793-dc9a-0eb48a570300@huawei.com

Signed-off-by: Liang Chen <liangchen.linux@gmail.com>
Reviewed-by: Yunsheng Lin <linyunsheng@huawei.com>
---
=C2=A0.../net/ethernet/mellanox/mlx5/core/en_rx.c=C2=A0 =C2=A0|=C2=A0 4 +-<= br> =C2=A0include/linux/mm_types.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 2 +-
=C2=A0include/net/page_pool/helpers.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0| 45 ++++++++++---------
=C2=A0include/net/page_pool/types.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0|=C2=A0 6 +--
=C2=A0net/core/page_pool.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | 12 ++---
=C2=A05 files changed, 37 insertions(+), 32 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c b/drivers/net/= ethernet/mellanox/mlx5/core/en_rx.c
index 8d9743a5e42c..98d33ac7ec64 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
@@ -298,8 +298,8 @@ static void mlx5e_page_release_fragmented(struct mlx5e_= rq *rq,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 u16 drain_count =3D MLX5E_PAGECNT_BIAS_MAX - fr= ag_page->frags;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 struct page *page =3D frag_page->page;

-=C2=A0 =C2=A0 =C2=A0 =C2=A0if (page_pool_defrag_page(page, drain_count) = =3D=3D 0)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0page_pool_put_defra= gged_page(rq->page_pool, page, -1, true);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (page_pool_unref_page(page, drain_count) = =3D=3D 0)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0page_pool_put_unref= ed_page(rq->page_pool, page, -1, true);
=C2=A0}

=C2=A0static inline int mlx5e_get_rx_frag(struct mlx5e_rq *rq,
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 957ce38768b2..64e4572ef06d 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -125,7 +125,7 @@ struct page {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 struct page_pool *pp;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 unsigned long _pp_mapping_pad;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 unsigned long dma_addr;
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0atomic_long_t pp_frag_count;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0atomic_long_t pp_ref_count;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 };
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 struct {=C2=A0 =C2= =A0 =C2=A0 =C2=A0 /* Tail pages of compound page */
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 unsigned long compound_head;=C2=A0 =C2=A0 /* Bit zero is set */<= br> diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helper= s.h
index 4ebd544ae977..9dc8eaf8a959 100644
--- a/include/net/page_pool/helpers.h
+++ b/include/net/page_pool/helpers.h
@@ -29,7 +29,7 @@
=C2=A0 * page allocated from page pool. Page splitting enables memory savin= g and thus
=C2=A0 * avoids TLB/cache miss for data access, but there also is some cost= to
=C2=A0 * implement page splitting, mainly some cache line dirtying/bouncing= for
- * 'struct page' and atomic operation for page->pp_frag_count.<= br> + * 'struct page' and atomic operation for page->pp_ref_count. =C2=A0 *
=C2=A0 * The API keeps track of in-flight pages, in order to let API users = know when
=C2=A0 * it is safe to free a page_pool object, the API users must call
@@ -214,69 +214,74 @@ inline enum dma_data_direction page_pool_get_dma_dir(= struct page_pool *pool)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return pool->p.dma_dir;
=C2=A0}

-/* pp_frag_count represents the number of writers who can update the page<= br> +/* pp_ref_count represents the number of writers who can update the page =C2=A0 * either by updating skb->data or via DMA mappings for the device= .
=C2=A0 * We can't rely on the page refcnt for that as we don't know= who might be
=C2=A0 * holding page references and we can't reliably destroy or sync = DMA mappings
=C2=A0 * of the fragments.
=C2=A0 *
- * When pp_frag_count reaches 0 we can either recycle the page if the page=
+ * pp_ref_count initially corresponds to the number of fragments. However,=
+ * when multiple users start to reference a single fragment, for example i= n
+ * skb_try_coalesce, the pp_ref_count will become greater than the number = of
+ * fragments.
+ *
+ * When pp_ref_count reaches 0 we can either recycle the page if the page<= br> =C2=A0 * refcnt is 1 or return it back to the memory allocator and destroy = any
=C2=A0 * mappings we have.
=C2=A0 */
=C2=A0static inline void page_pool_fragment_page(struct page *page, long nr= )
=C2=A0{
-=C2=A0 =C2=A0 =C2=A0 =C2=A0atomic_long_set(&page->pp_frag_count, nr= );
+=C2=A0 =C2=A0 =C2=A0 =C2=A0atomic_long_set(&page->pp_ref_count, nr)= ;
=C2=A0}

-static inline long page_pool_defrag_page(struct page *page, long nr)
+static inline long page_pool_unref_page(struct page *page, long nr)
=C2=A0{
=C2=A0 =C2=A0 =C2=A0 =C2=A0 long ret;

-=C2=A0 =C2=A0 =C2=A0 =C2=A0/* If nr =3D=3D pp_frag_count then we have clea= red all remaining
+=C2=A0 =C2=A0 =C2=A0 =C2=A0/* If nr =3D=3D pp_ref_count then we have clear= ed all remaining
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* references to the page:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* 1. 'n =3D=3D 1': no need to act= ually overwrite it.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* 2. 'n !=3D 1': overwrite it wit= h one, which is the rare case
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 *=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 for pp_frag_count draining.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 *=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 for pp_ref_count draining.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0*
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* The main advantage to doing this is tha= t not only we avoid a atomic
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* update, as an atomic_read is generally = a much cheaper operation than
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* an atomic update, especially when deali= ng with a page that may be
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 * partitioned into only 2 or 3 pieces; but als= o unify the pp_frag_count
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 * referenced by only 2 or 3 users; but also un= ify the pp_ref_count
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* handling by ensuring all pages have par= titioned into only 1 piece
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* initially, and only overwrite it when t= he page is partitioned into
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* more than one piece.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0*/
-=C2=A0 =C2=A0 =C2=A0 =C2=A0if (atomic_long_read(&page->pp_frag_coun= t) =3D=3D nr) {
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (atomic_long_read(&page->pp_ref_count= ) =3D=3D nr) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* As we have ensur= ed nr is always one for constant case using
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* the BUILD_B= UG_ON(), only need to handle the non-constant case
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 * here for pp_frag= _count draining, which is a rare case.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 * here for pp_ref_= count draining, which is a rare case.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0*/
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 BUILD_BUG_ON(__buil= tin_constant_p(nr) && nr !=3D 1);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (!__builtin_cons= tant_p(nr))
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0atomic_long_set(&page->pp_frag_count, 1);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0atomic_long_set(&page->pp_ref_count, 1);

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return 0;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 }

-=C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D atomic_long_sub_return(nr, &page-&g= t;pp_frag_count);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D atomic_long_sub_return(nr, &page-&g= t;pp_ref_count);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 WARN_ON(ret < 0);

-=C2=A0 =C2=A0 =C2=A0 =C2=A0/* We are the last user here too, reset pp_frag= _count back to 1 to
+=C2=A0 =C2=A0 =C2=A0 =C2=A0/* We are the last user here too, reset pp_ref_= count back to 1 to
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* ensure all pages have been partitioned = into 1 piece initially,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* this should be the rare case when the l= ast two fragment users call
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 * page_pool_defrag_page() currently.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 * page_pool_unref_page() currently.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0*/
=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (unlikely(!ret))
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0atomic_long_set(&am= p;page->pp_frag_count, 1);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0atomic_long_set(&am= p;page->pp_ref_count, 1);

=C2=A0 =C2=A0 =C2=A0 =C2=A0 return ret;
=C2=A0}

-static inline bool page_pool_is_last_frag(struct page *page)
+static inline bool page_pool_is_last_ref(struct page *page)
=C2=A0{
-=C2=A0 =C2=A0 =C2=A0 =C2=A0/* If page_pool_defrag_page() returns 0, we wer= e the last user */
-=C2=A0 =C2=A0 =C2=A0 =C2=A0return page_pool_defrag_page(page, 1) =3D=3D 0;=
+=C2=A0 =C2=A0 =C2=A0 =C2=A0/* If page_pool_unref_page() returns 0, we were= the last user */
+=C2=A0 =C2=A0 =C2=A0 =C2=A0return page_pool_unref_page(page, 1) =3D=3D 0;<= br> =C2=A0}

=C2=A0/**
@@ -301,10 +306,10 @@ static inline void page_pool_put_page(struct page_poo= l *pool,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* allow registering MEM_TYPE_PAGE_POOL, b= ut shield linker.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0*/
=C2=A0#ifdef CONFIG_PAGE_POOL
-=C2=A0 =C2=A0 =C2=A0 =C2=A0if (!page_pool_is_last_frag(page))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (!page_pool_is_last_ref(page))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return;

-=C2=A0 =C2=A0 =C2=A0 =C2=A0page_pool_put_defragged_page(pool, page, dma_sy= nc_size, allow_direct);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0page_pool_put_unrefed_page(pool, page, dma_sync= _size, allow_direct);
=C2=A0#endif
=C2=A0}

diff --git a/include/net/page_pool/types.h b/include/net/page_pool/types.h<= br> index e1bb92c192de..6a5323619f6e 100644
--- a/include/net/page_pool/types.h
+++ b/include/net/page_pool/types.h
@@ -224,9 +224,9 @@ static inline void page_pool_put_page_bulk(struct page_= pool *pool, void **data,
=C2=A0}
=C2=A0#endif

-void page_pool_put_defragged_page(struct page_pool *pool, struct page *pag= e,
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned int dma_sync_size, -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0bool allow_direct);
+void page_pool_put_unrefed_page(struct page_pool *pool, struct page *page,=
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned int dma_sync_size,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0bool allow_direct);

=C2=A0static inline bool is_page_pool_compiled_in(void)
=C2=A0{
diff --git a/net/core/page_pool.c b/net/core/page_pool.c
index df2a06d7da52..106220b1f89c 100644
--- a/net/core/page_pool.c
+++ b/net/core/page_pool.c
@@ -650,8 +650,8 @@ __page_pool_put_page(struct page_pool *pool, struct pag= e *page,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return NULL;
=C2=A0}

-void page_pool_put_defragged_page(struct page_pool *pool, struct page *pag= e,
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned int dma_sync_size, bo= ol allow_direct)
+void page_pool_put_unrefed_page(struct page_pool *pool, struct page *page,=
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned int dma_sync_size, bool allo= w_direct)
=C2=A0{
=C2=A0 =C2=A0 =C2=A0 =C2=A0 page =3D __page_pool_put_page(pool, page, dma_s= ync_size, allow_direct);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (page && !page_pool_recycle_in_ring(= pool, page)) {
@@ -660,7 +660,7 @@ void page_pool_put_defragged_page(struct page_pool *poo= l, struct page *page,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 page_pool_return_pa= ge(pool, page);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
=C2=A0}
-EXPORT_SYMBOL(page_pool_put_defragged_page);
+EXPORT_SYMBOL(page_pool_put_unrefed_page);

=C2=A0/**
=C2=A0 * page_pool_put_page_bulk() - release references on multiple pages @@ -687,7 +687,7 @@ void page_pool_put_page_bulk(struct page_pool *pool, vo= id **data,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 struct page *page = =3D virt_to_head_page(data[i]);

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* It is not the la= st user for the page frag case */
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!page_pool_is_l= ast_frag(page))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!page_pool_is_l= ast_ref(page))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 continue;

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 page =3D __page_poo= l_put_page(pool, page, -1, false);
@@ -729,7 +729,7 @@ static struct page *page_pool_drain_frag(struct page_po= ol *pool,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 long drain_count =3D BIAS_MAX - pool->frag_u= sers;

=C2=A0 =C2=A0 =C2=A0 =C2=A0 /* Some user is still using the page frag */ -=C2=A0 =C2=A0 =C2=A0 =C2=A0if (likely(page_pool_defrag_page(page, drain_co= unt)))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (likely(page_pool_unref_page(page, drain_cou= nt)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return NULL;

=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (page_ref_count(page) =3D=3D 1 && !p= age_is_pfmemalloc(page)) {
@@ -750,7 +750,7 @@ static void page_pool_free_frag(struct page_pool *pool)=

=C2=A0 =C2=A0 =C2=A0 =C2=A0 pool->frag_page =3D NULL;

-=C2=A0 =C2=A0 =C2=A0 =C2=A0if (!page || page_pool_defrag_page(page, drain_= count))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0if (!page || page_pool_unref_page(page, drain_c= ount))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return;

=C2=A0 =C2=A0 =C2=A0 =C2=A0 page_pool_return_page(pool, page);
--
2.31.1

--0000000000008781cf060b6fd3f9--