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 X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12F67C47082 for ; Mon, 7 Jun 2021 04:52:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 95B7B61244 for ; Mon, 7 Jun 2021 04:52:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 95B7B61244 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3720E6B006E; Mon, 7 Jun 2021 00:52:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3215A6B0070; Mon, 7 Jun 2021 00:52:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 14D886B0071; Mon, 7 Jun 2021 00:52:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0254.hostedemail.com [216.40.44.254]) by kanga.kvack.org (Postfix) with ESMTP id D62BD6B006E for ; Mon, 7 Jun 2021 00:52:03 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 697DBB795 for ; Mon, 7 Jun 2021 04:52:03 +0000 (UTC) X-FDA: 78225705726.29.B80771E Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) by imf05.hostedemail.com (Postfix) with ESMTP id 9B743E000253 for ; Mon, 7 Jun 2021 04:52:00 +0000 (UTC) Received: by mail-wr1-f53.google.com with SMTP id a20so16025809wrc.0 for ; Sun, 06 Jun 2021 21:52:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=GSrkzkz7xM597OmtYCnt2HUmLY0/0lkG7FOWLrVNAms=; b=FHl4f2ZMNz83wbOOximW+hD3upYQGy1AuGocMMiFVdvqnDQaqr0v5s4QckDZNIRw+G fXR/saqHsOXCJX/B+NJqEvCwCHsZUFAQa5eTqGBit32iZWBABoWo9dW9UGuHlucHyYEn Hv/YFYR54d5IddJbd2vEnZ28MlHEQG6/RAJpJgohGxMDsGtPLO6DPPu3sBlJqBszMErr tSpH4uoPeh5eTTm1tOJPWyRY/0yc9Ls3NRMfQDSUJqd0qrFQ8SZ6S88tIO44S4HPIaoh RZmcqSUQpMJ+YHXuDmOVZ8XvROg5CDwAO3rVuqJ1a/LEtaMI8DY45It6NF9hG71vJu0h F3rQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=GSrkzkz7xM597OmtYCnt2HUmLY0/0lkG7FOWLrVNAms=; b=cMmpfH6Rkw3AF3UVpzKYn2BKiJZaimrSdgf9mxGrjLGTJ0vrb824eTdNxFutjDHebz 9VYW5LHXn90tEhT2UEIzLKzVNqN4SsupCHNZnlSNf+6Nbbjt2feRO4jRGWJwo+A80axJ h0sYBGKIxm5uc4oZiBq53g+IchwMrRJJZKVIBwVrGlnC/BxVbv1MdtZrI18lNMkLSflO 6qmes6bLFBcWJAIwT2ElaEKtnHo4kZYPP3R+D9KXQPozBb5FZx6PduPT5NYX+5uFwbnc lLJVm77q5OgzzxZuxcCQykFBpV0TdWPJLU7vYd341SbBcZ8zu59oNfQcowqqFUWj06fm FgVQ== X-Gm-Message-State: AOAM5332I1gNHXgob3wv5eayK1hqZL9Zo3aQ2wUsTiI1CFor+s6ZdFRV i/gBHmTLNgcKmiPFL02WsF/h3Q== X-Google-Smtp-Source: ABdhPJyH2kD08IkD4rO54NrYaJ6NqrZO0rrFvYt+XutsC9lnfAjdURf0mdSoSNbTp3YUeEf2+VNTpg== X-Received: by 2002:a5d:6b09:: with SMTP id v9mr15195054wrw.297.1623041521972; Sun, 06 Jun 2021 21:52:01 -0700 (PDT) Received: from Iliass-MBP (ppp-94-66-57-185.home.otenet.gr. [94.66.57.185]) by smtp.gmail.com with ESMTPSA id n2sm15303342wmb.32.2021.06.06.21.51.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Jun 2021 21:52:01 -0700 (PDT) Date: Mon, 7 Jun 2021 07:51:56 +0300 From: Ilias Apalodimas To: Matthew Wilcox Cc: Matteo Croce , netdev@vger.kernel.org, linux-mm@kvack.org, Ayush Sawal , Vinay Kumar Yadav , Rohit Maheshwari , "David S. Miller" , Jakub Kicinski , Thomas Petazzoni , Marcin Wojtas , Russell King , Mirko Lindner , Stephen Hemminger , Tariq Toukan , Jesper Dangaard Brouer , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Boris Pismenny , Arnd Bergmann , Andrew Morton , "Peter Zijlstra (Intel)" , Vlastimil Babka , Yu Zhao , Will Deacon , Fenghua Yu , Roman Gushchin , Hugh Dickins , Peter Xu , Jason Gunthorpe , Jonathan Lemon , Alexander Lobakin , Cong Wang , wenxu , Kevin Hao , Jakub Sitnicki , Marco Elver , Willem de Bruijn , Miaohe Lin , Yunsheng Lin , Guillaume Nault , linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, bpf@vger.kernel.org, Eric Dumazet , David Ahern , Lorenzo Bianconi , Saeed Mahameed , Andrew Lunn , Paolo Abeni , Sven Auhagen Subject: Re: [PATCH net-next v7 3/5] page_pool: Allow drivers to hint on SKB recycling Message-ID: References: <20210604183349.30040-1-mcroce@linux.microsoft.com> <20210604183349.30040-4-mcroce@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 9B743E000253 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=linaro.org header.s=google header.b=FHl4f2ZM; dmarc=pass (policy=none) header.from=linaro.org; spf=pass (imf05.hostedemail.com: domain of ilias.apalodimas@linaro.org designates 209.85.221.53 as permitted sender) smtp.mailfrom=ilias.apalodimas@linaro.org X-Stat-Signature: ii8d3c336oqko47ryhis4aqonp9dp57k X-HE-Tag: 1623041520-933270 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 Fri, Jun 04, 2021 at 08:41:52PM +0100, Matthew Wilcox wrote: > On Fri, Jun 04, 2021 at 08:33:47PM +0200, Matteo Croce wrote: > > diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h > > index 7fcfea7e7b21..057b40ad29bd 100644 > > --- a/include/linux/skbuff.h > > +++ b/include/linux/skbuff.h > > @@ -40,6 +40,9 @@ > > #if IS_ENABLED(CONFIG_NF_CONNTRACK) > > #include > > #endif > > +#ifdef CONFIG_PAGE_POOL > > +#include > > +#endif > > I'm not a huge fan of conditional includes ... any reason to not include > it always? I think we can. I'll check and change it. > > > @@ -3088,7 +3095,13 @@ static inline void skb_frag_ref(struct sk_buff *skb, int f) > > */ > > static inline void __skb_frag_unref(skb_frag_t *frag, bool recycle) > > { > > - put_page(skb_frag_page(frag)); > > + struct page *page = skb_frag_page(frag); > > + > > +#ifdef CONFIG_PAGE_POOL > > + if (recycle && page_pool_return_skb_page(page_address(page))) > > + return; > > It feels weird to have a page here, convert it back to an address, > then convert it back to a head page in page_pool_return_skb_page(). > How about passing 'page' here, calling compound_head() in > page_pool_return_skb_page() and calling virt_to_page() in skb_free_head()? > Sure, sounds reasonable. > > @@ -251,4 +253,11 @@ static inline void page_pool_ring_unlock(struct page_pool *pool) > > spin_unlock_bh(&pool->ring.producer_lock); > > } > > > > +/* Store mem_info on struct page and use it while recycling skb frags */ > > +static inline > > +void page_pool_store_mem_info(struct page *page, struct page_pool *pp) > > +{ > > + page->pp = pp; > > I'm not sure this wrapper needs to exist. > > > +} > > + > > #endif /* _NET_PAGE_POOL_H */ > > diff --git a/net/core/page_pool.c b/net/core/page_pool.c > > index e1321bc9d316..a03f48f45696 100644 > > --- a/net/core/page_pool.c > > +++ b/net/core/page_pool.c > > @@ -628,3 +628,26 @@ void page_pool_update_nid(struct page_pool *pool, int new_nid) > > } > > } > > EXPORT_SYMBOL(page_pool_update_nid); > > + > > +bool page_pool_return_skb_page(void *data) > > +{ > > + struct page_pool *pp; > > + struct page *page; > > + > > + page = virt_to_head_page(data); > > + if (unlikely(page->pp_magic != PP_SIGNATURE)) > > + return false; > > + > > + pp = (struct page_pool *)page->pp; > > You don't need the cast any more. > True > > + /* Driver set this to memory recycling info. Reset it on recycle. > > + * This will *not* work for NIC using a split-page memory model. > > + * The page will be returned to the pool here regardless of the > > + * 'flipped' fragment being in use or not. > > + */ > > + page->pp = NULL; > > + page_pool_put_full_page(pp, page, false); > > + > > + return true; > > +} > > +EXPORT_SYMBOL(page_pool_return_skb_page); > > diff --git a/net/core/skbuff.c b/net/core/skbuff.c > > index 12b7e90dd2b5..f769f08e7b32 100644 > > --- a/net/core/skbuff.c > > +++ b/net/core/skbuff.c > > @@ -70,6 +70,9 @@ > > #include > > #include > > #include > > +#ifdef CONFIG_PAGE_POOL > > +#include > > +#endif > > > > #include > > #include > > @@ -645,10 +648,15 @@ static void skb_free_head(struct sk_buff *skb) > > { > > unsigned char *head = skb->head; > > > > - if (skb->head_frag) > > + if (skb->head_frag) { > > +#ifdef CONFIG_PAGE_POOL > > + if (skb->pp_recycle && page_pool_return_skb_page(head)) > > + return; > > +#endif > > put this in a header file: > > static inline bool skb_pp_recycle(struct sk_buff *skb, void *data) > { > if (!IS_ENABLED(CONFIG_PAGE_POOL) || !skb->pp_recycle) > return false; > return page_pool_return_skb_page(virt_to_page(data)); > } > > then this becomes: > > if (skb->head_frag) { > if (skb_pp_recycle(skb, head)) > return; > > skb_free_frag(head); > > - else > > + } else { > > kfree(head); > > + } > > } > > ok Thanks for having a look Cheers /Ilias