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=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 9320FC432BE for ; Tue, 31 Aug 2021 13:43:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7305D60FED for ; Tue, 31 Aug 2021 13:43:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239257AbhHaNoR (ORCPT ); Tue, 31 Aug 2021 09:44:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239555AbhHaNoK (ORCPT ); Tue, 31 Aug 2021 09:44:10 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3970FC061575; Tue, 31 Aug 2021 06:43:15 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id i21so38896911ejd.2; Tue, 31 Aug 2021 06:43:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=VH/yKqNAe9e3PUm35v8kdpwIp0mhzflq9zZXa4MIE80=; b=cQmZ8fYs6ynPoVomOUgSSwIFWfEsgdikbjEQfS8VdxK9y/dBxVlm1S/6vWtaU6kWJo LOE5xjRT/QezIFQuTT+RSzP+aVt7mb3v18K55fLa9W9cFmLBeAvg6Jjg4rMRuhwClE9b wKwfgP96LheuO7HofYhnV4heAXQbJGMrbqvdz7fAw7uC2lgu8bOBgNv8uGO0p4M53Ezh vGgpT/yCEN18qbFmqEa1/ibKnU1xn5xOe97sa+hkU5ykMP9nyMkodys6tIQwpmVLzptR du+hDUgMln/KWWWhy4qvrN/UGdkyQ2LIRgbOdxZcH3jALQvIcEDUJ4T4mQjuCheEC+79 Ox8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=VH/yKqNAe9e3PUm35v8kdpwIp0mhzflq9zZXa4MIE80=; b=Li7DLtisoCF8ULtbLYde1U63HagsZiR8q8GJomGiejNblwIxp/eZF1tj+QVR8YM6gp fQKziozBh2nULS7YS4gTc/RiDCqRP/TUHMuk19/Jz0XPZFyaWSiJe/b71j1JrYkY9fGS p8YrmW/3mSXouMP2tDXgxdo9mXBUgAN1hjTHYPK68JmwggamQQwzcxitNBG2wxeXUE/b +vPLG9EHF1xDlfOSSd/TwP8Kqkb1Y0IFVo7FyqL4G5oY5nKeiIo97ZtwCRMEpadgMERz Rzj0g4aQteP+1N4b+p2NmSKqHyjaJCoDguDDDTMo+ujRsVEdMxDok5l9q9KAno3YgNAx B+4w== X-Gm-Message-State: AOAM531vee1ZWlCX3t+aCqruLO1YtLMrKpJLjDTgg+75Ju2a0mNax//A 1CG58zR72P4uIKzsJ772FPTsB5i0ekPqKpIHF/8= X-Google-Smtp-Source: ABdhPJzF4TqghotOb9gsyWAEqZ8d+Z807qcLYjslQQfjFeb/w2NC7K8Rss2nKk5fvcsj5hCbQobCQTmDne5hJC7dpew= X-Received: by 2002:a17:907:2d9f:: with SMTP id gt31mr30503364ejc.489.1630417393590; Tue, 31 Aug 2021 06:43:13 -0700 (PDT) MIME-Version: 1.0 References: <1630286290-43714-1-git-send-email-linyunsheng@huawei.com> <1630286290-43714-2-git-send-email-linyunsheng@huawei.com> In-Reply-To: From: Alexander Duyck Date: Tue, 31 Aug 2021 06:43:02 -0700 Message-ID: Subject: Re: [PATCH net-next 1/2] page_pool: support non-split page with PP_FLAG_PAGE_FRAG To: Yunsheng Lin Cc: David Miller , Jakub Kicinski , Netdev , LKML , linuxarm@openeuler.org, hawk@kernel.org, Ilias Apalodimas , Jonathan Lemon , Alexander Lobakin , Willem de Bruijn , Cong Wang , Paolo Abeni , Kevin Hao , nogikh@google.com, Marco Elver , memxor@gmail.com, Eric Dumazet , David Ahern Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 30, 2021 at 11:14 PM Yunsheng Lin wrote: > > On 2021/8/30 23:05, Alexander Duyck wrote: > > On Sun, Aug 29, 2021 at 6:19 PM Yunsheng Lin wrote: > >> > >> Currently when PP_FLAG_PAGE_FRAG is set, the caller is not > >> expected to call page_pool_alloc_pages() directly because of > >> the PP_FLAG_PAGE_FRAG checking in __page_pool_put_page(). > >> > >> The patch removes the above checking to enable non-split page > >> support when PP_FLAG_PAGE_FRAG is set. > >> > >> Signed-off-by: Yunsheng Lin > >> --- > >> include/net/page_pool.h | 6 ++++++ > >> net/core/page_pool.c | 12 +++++++----- > >> 2 files changed, 13 insertions(+), 5 deletions(-) > >> > >> diff --git a/include/net/page_pool.h b/include/net/page_pool.h > >> index a408240..2ad0706 100644 > >> --- a/include/net/page_pool.h > >> +++ b/include/net/page_pool.h > >> @@ -238,6 +238,9 @@ static inline void page_pool_set_dma_addr(struct page *page, dma_addr_t addr) > >> > >> static inline void page_pool_set_frag_count(struct page *page, long nr) > >> { > >> + if (PAGE_POOL_DMA_USE_PP_FRAG_COUNT) > >> + return; > >> + > >> atomic_long_set(&page->pp_frag_count, nr); > >> } > >> > >> @@ -246,6 +249,9 @@ static inline long page_pool_atomic_sub_frag_count_return(struct page *page, > >> { > >> long ret; > >> > >> + if (PAGE_POOL_DMA_USE_PP_FRAG_COUNT) > >> + return 0; > >> + > >> /* As suggested by Alexander, atomic_long_read() may cover up the > >> * reference count errors, so avoid calling atomic_long_read() in > >> * the cases of freeing or draining the page_frags, where we would > >> diff --git a/net/core/page_pool.c b/net/core/page_pool.c > >> index 1a69784..ba9f14d 100644 > >> --- a/net/core/page_pool.c > >> +++ b/net/core/page_pool.c > >> @@ -313,11 +313,14 @@ struct page *page_pool_alloc_pages(struct page_pool *pool, gfp_t gfp) > >> > >> /* Fast-path: Get a page from cache */ > >> page = __page_pool_get_cached(pool); > >> - if (page) > >> - return page; > >> > >> /* Slow-path: cache empty, do real allocation */ > >> - page = __page_pool_alloc_pages_slow(pool, gfp); > >> + if (!page) > >> + page = __page_pool_alloc_pages_slow(pool, gfp); > >> + > >> + if (likely(page)) > >> + page_pool_set_frag_count(page, 1); > >> + > >> return page; > >> } > >> EXPORT_SYMBOL(page_pool_alloc_pages); > >> @@ -426,8 +429,7 @@ __page_pool_put_page(struct page_pool *pool, struct page *page, > >> unsigned int dma_sync_size, bool allow_direct) > >> { > >> /* It is not the last user for the page frag case */ > >> - if (pool->p.flags & PP_FLAG_PAGE_FRAG && > >> - page_pool_atomic_sub_frag_count_return(page, 1)) > >> + if (page_pool_atomic_sub_frag_count_return(page, 1)) > >> return NULL; > > > > Isn't this going to have a negative performance impact on page pool > > pages in general? Essentially you are adding an extra atomic operation > > for all the non-frag pages. > > > > It would work better if this was doing a check against 1 to determine > > if it is okay for this page to be freed here and only if the check > > fails then you perform the atomic sub_return. > > The page_pool_atomic_sub_frag_count_return() has added the optimization > to not do the atomic sub_return when the caller is the last user of the > page, see page_pool_atomic_sub_frag_count_return(): > > /* As suggested by Alexander, atomic_long_read() may cover up the > * reference count errors, so avoid calling atomic_long_read() in > * the cases of freeing or draining the page_frags, where we would > * not expect it to match or that are slowpath anyway. > */ > if (__builtin_constant_p(nr) && > atomic_long_read(&page->pp_frag_count) == nr) > return 0; > > So the check against 1 is not needed here? Ah, okay. I hadn't seen that part. So yeah, then this should be mostly harmless since 1 falls into the category of a builtin constant and would result in the standard case being the frag count being set to 1 and then being read which should be minimal overhead. Reviewed-by: Alexander Duyck