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 D9BE5C61DF7 for ; Thu, 23 Nov 2023 14:30:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 559726B06B8; Thu, 23 Nov 2023 09:30:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4E33F6B06B9; Thu, 23 Nov 2023 09:30:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 35B9A6B06BA; Thu, 23 Nov 2023 09:30:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 22B676B06B8 for ; Thu, 23 Nov 2023 09:30:50 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id EB140161122 for ; Thu, 23 Nov 2023 14:30:49 +0000 (UTC) X-FDA: 81489455418.01.EA47181 Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) by imf22.hostedemail.com (Postfix) with ESMTP id 104B0C0014 for ; Thu, 23 Nov 2023 14:30:47 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ODeju6q1; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf22.hostedemail.com: domain of liangchen.linux@gmail.com designates 209.85.218.46 as permitted sender) smtp.mailfrom=liangchen.linux@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700749848; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GI29TqTKej4lf3cUYmz69Bg9cqaGxciaGgk9rREOFK0=; b=QLJkJSRnNTwzp3GLrYikFRQhH5vBL2xEgppEMSbZtcOdcVEtCQVVXzgjjd+NnwUDVoY2cw 0/KVdCL7G3d9qRVTfqIdrt7p3oEme+HaSoUt6uS4ZsvPU1J2QWfQ4ycv/g5A3UbYDD13H4 44FRAcIMLXIOqR4cuS51WgrtT5rxwr0= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ODeju6q1; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf22.hostedemail.com: domain of liangchen.linux@gmail.com designates 209.85.218.46 as permitted sender) smtp.mailfrom=liangchen.linux@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700749848; a=rsa-sha256; cv=none; b=ozG8aalK7x3DHN2pJeCqi/AJWGlV8bCieIqbImPdAh88PtYdTguY/dIwhNwPVQVMuoQSlP mM0+Hddo7SSpub55BfGhkp5GQ51HOmZUMbNbb7i5/+MCkjt2cXDVMNVFUxc/AyP2Sd++QJ krdlSRN4us3EzSXNujb/QvvkHSVbFnQ= Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-9fa2714e828so121066166b.1 for ; Thu, 23 Nov 2023 06:30:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700749846; x=1701354646; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=GI29TqTKej4lf3cUYmz69Bg9cqaGxciaGgk9rREOFK0=; b=ODeju6q1LEdfWybFMu2oy8Vc3NZMVwkU0S7wT4iRRQ3UEtS1PUsGWDiO73ezO6MIpC GyA9zjzDEqy9ByCnq1Sim6eauJKo9y3yqWD31RWRqrRVP99LLzzl722q4dtsYtJU5rCo QJeK3TzGJsenX5MkGXJn8ay7rKLPaFqgQwDrUqbl6uppV6ZIyvPuoSPjMZntVpD0mH8i GNUr6CCn1Ui5xDy48Mukc7uTJXNOCGGxnV/lklKUMf+i2qVWOm57gmTy2uyhdr1/xGmB 3EeiJuGHthfFe1SprIthXNCiCjhnm/gh/o7+utM6d2GtQmfmok53j0kSHb7vryVZGngg 84Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700749846; x=1701354646; h=content-transfer-encoding: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=GI29TqTKej4lf3cUYmz69Bg9cqaGxciaGgk9rREOFK0=; b=kKseEPjWtkcIARHMJaOjGgRY818mcpMl9StpBE85jp+FCh6aq2QA7ts9b2FzlL8xDn rTNcxKY8Ku1HD1yMjVBmxtvs5c8O3bj9+qyfTlNXCSZHEFipD4Gjaapwinxic3gexl80 znd3y8u2e6kDh/qPIXdWe9ShngycvktKuajNX9QugQ+PuX5CVPcDquLS0LCwOX5DETZA 6cCqfSe0Riay0+qIKU6X7mnAOwMeopORPLscR6JXKji8hroTo4X0UuekDYx+PzPFq2Vz NsVAAkL8HUWMw/eTA4bOAAqJEOTIKEO34p9tEmF0wxaBc1syUwhdDzMRLzQ+CrhHi4+X mj1g== X-Gm-Message-State: AOJu0YxlRnCdTNUx7u+wYLSIpnVtqOuogg0J4tC/9a0rwBGEZnv0C2RL XMsjEetNRutf191Og9Hz88H0H5rYyzpnwxbsI+Q= X-Google-Smtp-Source: AGHT+IFcIlU0S4fkluh8TUF6nmbd3M6B/7WfiZsJ5hhTPxeHU3IzIM4DT/7XbJe865AelliKu3TAAfTzqXqvuFaIlHs= X-Received: by 2002:a17:906:f46:b0:a02:b538:172a with SMTP id h6-20020a1709060f4600b00a02b538172amr3734159ejj.56.1700749846231; Thu, 23 Nov 2023 06:30:46 -0800 (PST) MIME-Version: 1.0 References: <20231123022516.6757-1-liangchen.linux@gmail.com> <2198afb3-4eaf-f41b-d58d-a7585f308c8c@huawei.com> In-Reply-To: <2198afb3-4eaf-f41b-d58d-a7585f308c8c@huawei.com> From: Liang Chen Date: Thu, 23 Nov 2023 22:30:33 +0800 Message-ID: Subject: Re: [PATCH net-next v2 1/3] page_pool: Rename pp_frag_count to pp_ref_count To: Yunsheng Lin Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, hawk@kernel.org, ilias.apalodimas@linaro.org, netdev@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 104B0C0014 X-Stat-Signature: 1eeeoxfy51fgiq698n6kb9api9s14ozz X-Rspam-User: X-HE-Tag: 1700749847-518075 X-HE-Meta: U2FsdGVkX1/KWjVtcrJd5eLgFMKkKQ7Rohk238x3EMBufd16qGmxIdiqH6tlngdvWOT2QnlrzhAdVwlEkZqje7/m3ZPXw1WT4Uty/VpbLsWy3RpGhemvQKFfaK+3DxiKoZ3Sx//AJJB6CMTplYutJUcVJgNQraBfEX9GoJaldr8anto7j6n+/H/4bi3J6e4muA53TiMpSxYMxhR4t9ZcFlURJ5F+F0Zk/aJvVRNkccVBwtJXFilecHkkgSgXMr3nCUz9vmy3hHFTH5umc/02nHw3W5C97MFc+1exnXlXny3QAKHVUJWZ/Eo7WE6zvj2iJHMGEXHRigziiOOSG9meEzb16Yilg3jtLjkuCPIXD2BcwoPl3MtFSWdwANZ+X56a2DSqFjuCEKq7kHvebk2ZuIf4comvGjXMCCsxRj+x0pmetJHM2X5G7zueWNu9gLqhEj/Wf2gMvz4MzpHySy+33QFYlH1t82QETewRVkvVpcy9ROquTRjhbBVaARW0bDzTnTOePt6ukg+KZejD0FdZPrCLDHyl90ezHNUpga8dgRIUi0Zn5tKTjU8UFXg7ZAVKejt1zSuSCo9xUcS6bb/tCN0Q+10/p1l2695IghJ29SeASeJHUdVGBgzZbtt2DDAfJjg3scbQXbtzEM9UiNbMIChlCEnu113fqzExaS8SWp6P2QAlKbJr9B+bGK38sT9jci3dYofsMMJKARaEPta8knQ+2rd8nq7dCffGUTEQpPZ+NUdqe4fFwYNOgCCjEGqwjdSMI6EmbghPQk/WcOOXU2UyuXaPNsVvU8X+6NeGS6/PikW4S83BAWGKue+bCRADc57cqG6QOva4E4mjRqWpkv4Ab0yu7QWaE7HQOFg5w39s28r9114hMvpIyTNbYgYNFQLnEKLA74VbJnh96jWnW+zwocEfrVmrVMkzzU1hXnxbmrErkmw9E81QnClpCToSXmywvXtiruace0K93v2 czj4E+53 NBBpSY/O0IypRYu37jSARd8GjLXnI9eHhRBb8623MvT8DyvT4ofhsNve1Xe+sonkiC4D2yXj08FjjgO7THHbtovopbyyv+t7IUFDTXJ9w63EgFv8MH0gL5WltnswkwZpu+rI7RvnPhFen819qUxMfcRb25eu2mR0TjHX1Dp9Dg5BPphLh+OduVmrI3TiLfQW79LAqcKktfjLHvTGRbNXv0yysak+0+don6FXigRnhl5t+gIkokadCtcGv3j1YqAAv6jJsh51WB3Qq/p8z4qs2EorLsCaTtjvZ3vXiVsn54j85cWYi8hgI6ikMs7QqNxThUoTTMZ8rOw9VbHMhMDHiKyvSHwc/Eg7Cy1EAMfzO2/cGunDPw4dFy870ox+7PniD/Kj9JLZQyw/j+PJyWC+TmxVxFV00qDPMZfG3CsTLLDWdvhtm3zRIg/KnCOriAFsOIcZvfCEZRO7Ja2a8QAjT6URUfSSAUXjLu/S1N7nzLjvMCJgy3N85IzFI6A== 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: On Thu, Nov 23, 2023 at 2:18=E2=80=AFPM Yunsheng Lin wrote: > > On 2023/11/23 10:25, 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 t= he > > suggestion from [1]. > > The renaming looks good to me, some minor nit. > > It is good to add a cover-letter using 'git format-patch --cover-letter' > to explain the overall background or modifications this patchset make whe= n > there is more than one patch. > Thanks for the suggestion. A cover-letter will be provided for the next ver= sion. > > > > [1] > > http://lore.kernel.org/netdev/f71d9448-70c8-8793-dc9a-0eb48a570300@huaw= ei.com > > > > Signed-off-by: Liang Chen > > --- > > include/linux/mm_types.h | 2 +- > > include/net/page_pool/helpers.h | 31 ++++++++++++++++++------------- > > 2 files changed, 19 insertions(+), 14 deletions(-) > > > > 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; > > It seems that we may have 4 bytes available for 64 bit arch if we change > the 'atomic_long_t' to 'refcount_t':) > > > }; > > struct { /* Tail pages of compound page */ > > unsigned long compound_head; /* Bit zero is se= t */ > > diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/he= lpers.h > > index 4ebd544ae977..a6dc9412c9ae 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 k= now when > > * it is safe to free a page_pool object, the API users must call > > @@ -214,61 +214,66 @@ 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 p= age > > +/* pp_ref_count represents the number of writers who can update the pa= ge > > * 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 migh= t be > > * holding page references and we can't reliably destroy or sync DMA m= appings > > * 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. Howe= ver, > > + * when multiple users start to reference a single fragment, for examp= le in > > + * skb_try_coalesce, the pp_ref_count will become greater than the num= ber of > > + * fragments. > > + * > > + * When pp_ref_count reaches 0 we can either recycle the page if the p= age > > * refcnt is 1 or return it back to the memory allocator and destroy a= ny > > * 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) > > { > > long ret; > > > > - /* If nr =3D=3D pp_frag_count then we have cleared all remaining > > + /* If nr =3D=3D pp_ref_count then we have cleared all remaining > > * references to the page: > > * 1. 'n =3D=3D 1': no need to actually overwrite it. > > * 2. 'n !=3D 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 a= tomic > > * update, as an atomic_read is generally a much cheaper operatio= n 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_fra= g_count > > + * partitioned into only 2 or 3 pieces; but also unify the pp_ref= _count > > Maybe "referenced by only 2 or 3 users" is more appropriate now? > Sure. > > * handling by ensuring all pages have partitioned into only 1 pi= ece > > * initially, and only overwrite it when the page is partitioned = into > > * more than one piece. > > */ > > - if (atomic_long_read(&page->pp_frag_count) =3D=3D nr) { > > + if (atomic_long_read(&page->pp_ref_count) =3D=3D nr) { > > /* As we have ensured nr is always one for constant case = using > > * the BUILD_BUG_ON(), only need to handle the non-consta= nt 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 !=3D 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 =3D atomic_long_sub_return(nr, &page->pp_frag_count); > > + ret =3D 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 t= o > > + /* 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. > > Do we need to rename the page_pool_defrag_page() and page_pool_is_last_fr= ag() > too? > Yeah, I think so. Once a pp page is drained, its management shifts to being primarily governed by pp_ref_count, and there's no longer a need to consider fragmenting. will be done in the next iteration. > > */ > > if (unlikely(!ret)) > > - atomic_long_set(&page->pp_frag_count, 1); > > + atomic_long_set(&page->pp_ref_count, 1); > > > > return ret; > > } > >