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 337C7C46467 for ; Tue, 10 Jan 2023 10:04:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A2EBF8E0002; Tue, 10 Jan 2023 05:04:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B7F18E0001; Tue, 10 Jan 2023 05:04:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80AC58E0002; Tue, 10 Jan 2023 05:04:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 6B6508E0001 for ; Tue, 10 Jan 2023 05:04:40 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 25DC0123656 for ; Tue, 10 Jan 2023 10:04:40 +0000 (UTC) X-FDA: 80338455120.16.1ED4176 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf05.hostedemail.com (Postfix) with ESMTP id 01B85100002 for ; Tue, 10 Jan 2023 10:04:37 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dqBctDP1; spf=pass (imf05.hostedemail.com: domain of jbrouer@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=jbrouer@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673345078; 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=1oSeVU9ewoRTMDNTtzATyBMRUBuwdDAzXDzbPyCwHOU=; b=Jta09al6YRU2JOUDAsr3J+U+kylsnJq6yLNCbwM3k0OaoofjEq46rZew25IwbEsICjBsb6 /HzeGGmqK7ygqb1zn3gRC1BztMXYnxEU1kRxuxjguft2VKBbzR5spKFpQjoP8hfI2EI8JJ cKXCbHOFmopfTus49ppzBOmREaBTvCg= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dqBctDP1; spf=pass (imf05.hostedemail.com: domain of jbrouer@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=jbrouer@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673345078; a=rsa-sha256; cv=none; b=xdKseZa11fi1RjCOD9peSceTrFaRcolm+6ww+ssTCcRhU4/PJwlnzmAYoismddeadCDqsu UHe3397e08CFOUDpOR/gXRPpJoJ4Z/oqUas/F8Ck/eNYNV3zdv9lNGFimU51Gx/Od1wacP rQ8Y2PcInVHoDltsCWVRaTXAp+HXRjg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673345077; h=from:from: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; bh=1oSeVU9ewoRTMDNTtzATyBMRUBuwdDAzXDzbPyCwHOU=; b=dqBctDP1KQkq+U2n7P6XHOUOBtkRmodnXSyANcDF9oHhCHm/qFuvZW6+H4tRL95i2NlHI7 l/JU/zWyxWOWFuxi0IXUPhOKwBv+m5S9vk3badr8tcA3SUxktJ+Zt+SDIp+jFeGk8N4Nbl 9umsk1QnfVatmwbsb79OAEB9y5MXv+c= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-497-itQVjQfxMSq26ADd-hGQNg-1; Tue, 10 Jan 2023 05:04:36 -0500 X-MC-Unique: itQVjQfxMSq26ADd-hGQNg-1 Received: by mail-ej1-f72.google.com with SMTP id sa32-20020a1709076d2000b0084d4593797eso3896331ejc.16 for ; Tue, 10 Jan 2023 02:04:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:references:to :content-language:subject:cc:user-agent:mime-version:date:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1oSeVU9ewoRTMDNTtzATyBMRUBuwdDAzXDzbPyCwHOU=; b=p83KT52rlMYkMdFLoVEtMyqmNntw2LjohRsDwjDZNkIHPpdI8d8lr3M5K7Goz10dUs dF02wuU12x+QqIo9mM9po+d6m+rG0jIjGOFcqHPclBhpocbZJmNa1T6AHf4EB3pgBh9b dyPzjCRnA126fTmOwbmQJezlzcbo9kHX2pxYDOb/Yv3GNrTDmNyVubtaIkrgUNvCwHF0 d2JCq6hNtbRAzO8slK44sEkCnIwPql/2neQpccTiMMLEdyu+FZ4vQhI7+KeVAnmhprjb +Vg1H8E7mlZ/YjrRcbNwqNGfCTvgmmqWddduZcBua21ozYnfxOtUOTWbO/3IfDvFadG9 ovow== X-Gm-Message-State: AFqh2kpl2PHg305SOR96NaJc1rJVMYE346PxWwX+Y0PrrJnQ30DaVnN6 ypB/iivgAaqiDQuhhZnGb+putaZRDQ5DYmEz95bXQ+/BFvPIaYpvH+OF0rujaTAWfDl8V7FyqmL oNhj/ZnAf2XA= X-Received: by 2002:a05:6402:e87:b0:461:b8bf:ce1b with SMTP id h7-20020a0564020e8700b00461b8bfce1bmr61960022eda.34.1673345074919; Tue, 10 Jan 2023 02:04:34 -0800 (PST) X-Google-Smtp-Source: AMrXdXtVgVLvkT9o6+p8kfSEIwPVyyh/Hb4X1vxs6dffku0/UNnpLb5Ve+IZOnsSLuA3pZtYGaakBw== X-Received: by 2002:a05:6402:e87:b0:461:b8bf:ce1b with SMTP id h7-20020a0564020e8700b00461b8bfce1bmr61960006eda.34.1673345074676; Tue, 10 Jan 2023 02:04:34 -0800 (PST) Received: from [192.168.42.222] (nat-cgn9-185-107-15-52.static.kviknet.net. [185.107.15.52]) by smtp.gmail.com with ESMTPSA id b2-20020a0564021f0200b0048c85c5ad30sm4691745edb.83.2023.01.10.02.04.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 10 Jan 2023 02:04:34 -0800 (PST) From: Jesper Dangaard Brouer X-Google-Original-From: Jesper Dangaard Brouer Message-ID: <67d60543-2f3c-b0ff-b7fb-e44518cf325b@redhat.com> Date: Tue, 10 Jan 2023 11:04:32 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Cc: brouer@redhat.com, Jesper Dangaard Brouer , Ilias Apalodimas , netdev@vger.kernel.org, linux-mm@kvack.org, Shakeel Butt Subject: Re: [PATCH v2 17/24] page_pool: Convert page_pool_return_skb_page() to use netmem To: Matthew Wilcox , Jesper Dangaard Brouer References: <20230105214631.3939268-1-willy@infradead.org> <20230105214631.3939268-18-willy@infradead.org> <1545f7e7-3c2c-435a-b597-0824decf571c@redhat.com> In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 01B85100002 X-Stat-Signature: s1r9f88qyu1z4b4gnr4zyzucz5wimq55 X-HE-Tag: 1673345077-803248 X-HE-Meta: U2FsdGVkX1+NV0aLdEixJr1MB8ojBFshGRpxSOa7vdxoh/x3W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+imQCjEClX9n41wmcud 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: On 09/01/2023 19.36, Matthew Wilcox wrote: > On Fri, Jan 06, 2023 at 09:16:25PM +0100, Jesper Dangaard Brouer wrote: >> >> >> On 06/01/2023 17.53, Matthew Wilcox wrote: >>> On Fri, Jan 06, 2023 at 04:49:12PM +0100, Jesper Dangaard Brouer wrote: >>>> On 05/01/2023 22.46, Matthew Wilcox (Oracle) wrote: >>>>> This function accesses the pagepool members of struct page directly, >>>>> so it needs to become netmem. Add page_pool_put_full_netmem() and >>>>> page_pool_recycle_netmem(). >>>>> >>>>> Signed-off-by: Matthew Wilcox (Oracle) >>>>> --- >>>>> include/net/page_pool.h | 14 +++++++++++++- >>>>> net/core/page_pool.c | 13 ++++++------- >>>>> 2 files changed, 19 insertions(+), 8 deletions(-) >>>>> >>>>> diff --git a/include/net/page_pool.h b/include/net/page_pool.h >>>>> index fbb653c9f1da..126c04315929 100644 >>>>> --- a/include/net/page_pool.h >>>>> +++ b/include/net/page_pool.h >>>>> @@ -464,10 +464,16 @@ static inline void page_pool_put_page(struct page_pool *pool, >>>>> } >>>>> /* Same as above but will try to sync the entire area pool->max_len */ >>>>> +static inline void page_pool_put_full_netmem(struct page_pool *pool, >>>>> + struct netmem *nmem, bool allow_direct) >>>>> +{ >>>>> + page_pool_put_netmem(pool, nmem, -1, allow_direct); >>>>> +} >>>>> + >>>>> static inline void page_pool_put_full_page(struct page_pool *pool, >>>>> struct page *page, bool allow_direct) >>>>> { >>>>> - page_pool_put_page(pool, page, -1, allow_direct); >>>>> + page_pool_put_full_netmem(pool, page_netmem(page), allow_direct); >>>>> } >>>>> /* Same as above but the caller must guarantee safe context. e.g NAPI */ >>>>> @@ -477,6 +483,12 @@ static inline void page_pool_recycle_direct(struct page_pool *pool, >>>>> page_pool_put_full_page(pool, page, true); >>>>> } >>>>> +static inline void page_pool_recycle_netmem(struct page_pool *pool, >>>>> + struct netmem *nmem) >>>>> +{ >>>>> + page_pool_put_full_netmem(pool, nmem, true); >>>> ^^^^ >>>> >>>> It is not clear in what context page_pool_recycle_netmem() will be used, >>>> but I think the 'true' (allow_direct=true) might be wrong here. >>>> >>>> It is only in limited special cases (RX-NAPI context) we can allow >>>> direct return to the RX-alloc-cache. >>> >>> Mmm. It's a c'n'p of the previous function: >>> >>> static inline void page_pool_recycle_direct(struct page_pool *pool, >>> struct page *page) >>> { >>> page_pool_put_full_page(pool, page, true); >>> } >>> >>> so perhaps it's just badly named? >> >> Yes, I think so. >> >> Can we name it: >> page_pool_recycle_netmem_direct >> >> And perhaps add a comment with a warning like: >> /* Caller must guarantee safe context. e.g NAPI */ >> >> Like the page_pool_recycle_direct() function has a comment. > > I don't really like the new name you're proposing here. Really, > page_pool_recycle_direct() is the perfect name, it just has the wrong > type. > > I considered the attached megapatch, but I don't think that's a great > idea. > > So here's what I'm planning instead: I do like below patch. I must admit I had to lookup _Generic() when I started reviewing this patchset. I think it makes a lot of sense to use here as it allow us to easier convert drivers over. We have 22 call spots in drivers: $ git grep page_pool_recycle_direct drivers/net/ethernet/ | wc -l 22 But approx 9 drivers doing this (as each driver calls it in multiple places). > > page_pool: Allow page_pool_recycle_direct() to take a netmem or a page > > With no better name for a variant of page_pool_recycle_direct() which > takes a netmem instead of a page, use _Generic() to allow it to take > either a page or a netmem argument. It's a bit ugly, but maybe not > the worst alternative? > > Signed-off-by: Matthew Wilcox (Oracle) > > diff --git a/include/net/page_pool.h b/include/net/page_pool.h > index abe3822a1125..1eed8ed2dcc1 100644 > --- a/include/net/page_pool.h > +++ b/include/net/page_pool.h > @@ -477,12 +477,22 @@ static inline void page_pool_put_full_page(struct page_pool *pool, > } > > /* Same as above but the caller must guarantee safe context. e.g NAPI */ > -static inline void page_pool_recycle_direct(struct page_pool *pool, > +static inline void __page_pool_recycle_direct(struct page_pool *pool, > + struct netmem *nmem) > +{ > + page_pool_put_full_netmem(pool, nmem, true); > +} > + > +static inline void __page_pool_recycle_page_direct(struct page_pool *pool, > struct page *page) > { > - page_pool_put_full_page(pool, page, true); > + page_pool_put_full_netmem(pool, page_netmem(page), true); > } > > +#define page_pool_recycle_direct(pool, mem) _Generic((mem), \ > + struct netmem *: __page_pool_recycle_direct(pool, (struct netmem *)mem), \ > + struct page *: __page_pool_recycle_page_direct(pool, (struct page *)mem)) > + > #define PAGE_POOL_DMA_USE_PP_FRAG_COUNT \ > (sizeof(dma_addr_t) > sizeof(unsigned long)) > >