Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp390292pxf; Thu, 25 Mar 2021 06:35:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwcNJRc1daEdIk27e3fGG26s3/yr0+sFtrH8am6PJqWWFILY6l/eac222Cwd/USuqaA1/S1 X-Received: by 2002:a05:6402:510b:: with SMTP id m11mr9248666edd.103.1616679336839; Thu, 25 Mar 2021 06:35:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616679336; cv=none; d=google.com; s=arc-20160816; b=gTA/PCp8vt4NUhEGhM57zM85Sadx9/sAzSu+XIEvsmuvK6Y6hzpF2TivVwO08+z4pz GZSuYNHJ4UywNhjQIRT/U0cpswonsSu6Wi30hyP4379AHT/5BcurmUJs6qwKbzfECtai NAYNDAXtKjHY9ILgUoHamZC56Je0L90OWel9w6ADsDTmbjnKrWUSvZPaArXtDxa8B/q5 YkX5aV9Z8v8/aMFMu7BlHFfrdRrQVGqqXcCR5oJaq84fM9UTehfPlC5IHGq4M56l6Qn4 lByq7gly/424TOw5b6ezo0LrN5Q6yt48khcWEFnmw+KoD2gDkgcYSVC7V0nRnpLY4/NG yq/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:reply-to:cc:from:to :dkim-signature:date; bh=TNcqNIUGi5IWLeEp3KkdTlzXyUEpBuLEIC37/Wa1Bno=; b=nNbjQQSWMzRVRUE/LmtRbXhwTk9xaQsTyz0x64Rkb892km/CUyPdaRGeqnbatAtJIb A2nVvEWxcfHwL519O8hQ3hzfL6p3CbIiuBqVUxDjNh4n7839uBEl0rO8o0d4YXvfZ1yt qe376igAmlVXKZ2/wopHFc3b9iNBYoLsQ43JwlJDc+8AHlnNWqPg0IHuClfQluMQulmo UyOBjsV9st60VxQXkuIIeK5Smje2mjRcqEj4c/OxdHOeDTJzu0y8IMHYH4cKW65CiPvw c9cr8Xt+hMo/M7UrNN25ayB98Gx/eq7qdIVnBETfD9N9uJZYMA575TV3jJqHV83WlWIx iDmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail header.b=NlvHt1XO; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pm.me Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ku22si4306225ejc.704.2021.03.25.06.35.09; Thu, 25 Mar 2021 06:35:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail header.b=NlvHt1XO; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pm.me Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230478AbhCYNed (ORCPT + 99 others); Thu, 25 Mar 2021 09:34:33 -0400 Received: from mail2.protonmail.ch ([185.70.40.22]:23537 "EHLO mail2.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230140AbhCYNeH (ORCPT ); Thu, 25 Mar 2021 09:34:07 -0400 Date: Thu, 25 Mar 2021 13:33:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail; t=1616679243; bh=TNcqNIUGi5IWLeEp3KkdTlzXyUEpBuLEIC37/Wa1Bno=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=NlvHt1XOAsoKLYbRojzvQhEKl/dCwJH25h2fND3oo6JGcBeJOaQ6uOHTcrdu8bAWy YaxG6wwQ/wzjIFrsu1uc9DoU+oN8ML3ReRR0B0PrTwPA+/EBTBht46sonbfO+cS7WY /Dcm3VDXbNq5UeMyGdcsv75ryM+ofhL8VSXEiy/WFWx1nezNk3Gw0/Ehj3Zz3D6rZA 5INj5uRlIMIdBMMlu5kXDEuek6OnsdoUmCiYDAqcgfcVBCQDKCpPIBn43yfS+fXem2 4/eI/oTNgPa6rXbwupzm8d39KtK8sjR/o7nfkLkXqXlKtqIW0sqine4Fuzl5Akyheq Yk2KHi8rPXA7w== To: Mel Gorman From: Alexander Lobakin Cc: Alexander Lobakin , Andrew Morton , Chuck Lever , Jesper Dangaard Brouer , Christoph Hellwig , Alexander Duyck , Vlastimil Babka , Matthew Wilcox , Ilias Apalodimas , LKML , Linux-Net , Linux-MM , Linux-NFS Reply-To: Alexander Lobakin Subject: Re: [PATCH 9/9] net: page_pool: use alloc_pages_bulk in refill code path Message-ID: <20210325133340.14527-1-alobakin@pm.me> In-Reply-To: <20210325114228.27719-10-mgorman@techsingularity.net> References: <20210325114228.27719-1-mgorman@techsingularity.net> <20210325114228.27719-10-mgorman@techsingularity.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mailout.protonmail.ch Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Mel Gorman Date: Thu, 25 Mar 2021 11:42:28 +0000 > From: Jesper Dangaard Brouer > > There are cases where the page_pool need to refill with pages from the > page allocator. Some workloads cause the page_pool to release pages > instead of recycling these pages. > > For these workload it can improve performance to bulk alloc pages from > the page-allocator to refill the alloc cache. > > For XDP-redirect workload with 100G mlx5 driver (that use page_pool) > redirecting xdp_frame packets into a veth, that does XDP_PASS to create > an SKB from the xdp_frame, which then cannot return the page to the > page_pool. > > Performance results under GitHub xdp-project[1]: > [1] https://github.com/xdp-project/xdp-project/blob/master/areas/mem/pag= e_pool06_alloc_pages_bulk.org > > Mel: The patch "net: page_pool: convert to use alloc_pages_bulk_array > variant" was squashed with this patch. From the test page, the array > variant was superior with one of the test results as follows. > > =09Kernel=09=09XDP stats CPU pps Delta > =09Baseline=09XDP-RX CPU total 3,771,046 n/a > =09List=09=09XDP-RX CPU total 3,940,242 +4.49% > =09Array=09=09XDP-RX CPU total 4,249,224 +12.68% > > Signed-off-by: Jesper Dangaard Brouer > Signed-off-by: Mel Gorman I tested it a lot for past two weeks and I'm very satisfied with the results, especially the new array-based version. Haven't had a chance to test this particular set yet, but still. Reviewed-by: Alexander Lobakin Great work, thank you all guys! > --- > include/net/page_pool.h | 2 +- > net/core/page_pool.c | 82 ++++++++++++++++++++++++++++------------- > 2 files changed, 57 insertions(+), 27 deletions(-) > > diff --git a/include/net/page_pool.h b/include/net/page_pool.h > index b5b195305346..6d517a37c18b 100644 > --- a/include/net/page_pool.h > +++ b/include/net/page_pool.h > @@ -65,7 +65,7 @@ > #define PP_ALLOC_CACHE_REFILL=0964 > struct pp_alloc_cache { > =09u32 count; > -=09void *cache[PP_ALLOC_CACHE_SIZE]; > +=09struct page *cache[PP_ALLOC_CACHE_SIZE]; > }; > > struct page_pool_params { > diff --git a/net/core/page_pool.c b/net/core/page_pool.c > index 40e1b2beaa6c..9ec1aa9640ad 100644 > --- a/net/core/page_pool.c > +++ b/net/core/page_pool.c > @@ -203,38 +203,17 @@ static bool page_pool_dma_map(struct page_pool *poo= l, struct page *page) > =09return true; > } > > -/* slow path */ > -noinline > -static struct page *__page_pool_alloc_pages_slow(struct page_pool *pool, > -=09=09=09=09=09=09 gfp_t _gfp) > +static struct page *__page_pool_alloc_page_order(struct page_pool *pool, > +=09=09=09=09=09=09 gfp_t gfp) > { > -=09unsigned int pp_flags =3D pool->p.flags; > =09struct page *page; > -=09gfp_t gfp =3D _gfp; > - > -=09/* We could always set __GFP_COMP, and avoid this branch, as > -=09 * prep_new_page() can handle order-0 with __GFP_COMP. > -=09 */ > -=09if (pool->p.order) > -=09=09gfp |=3D __GFP_COMP; > - > -=09/* FUTURE development: > -=09 * > -=09 * Current slow-path essentially falls back to single page > -=09 * allocations, which doesn't improve performance. This code > -=09 * need bulk allocation support from the page allocator code. > -=09 */ > > -=09/* Cache was empty, do real allocation */ > -#ifdef CONFIG_NUMA > +=09gfp |=3D __GFP_COMP; > =09page =3D alloc_pages_node(pool->p.nid, gfp, pool->p.order); > -#else > -=09page =3D alloc_pages(gfp, pool->p.order); > -#endif > -=09if (!page) > +=09if (unlikely(!page)) > =09=09return NULL; > > -=09if ((pp_flags & PP_FLAG_DMA_MAP) && > +=09if ((pool->p.flags & PP_FLAG_DMA_MAP) && > =09 unlikely(!page_pool_dma_map(pool, page))) { > =09=09put_page(page); > =09=09return NULL; > @@ -243,6 +222,57 @@ static struct page *__page_pool_alloc_pages_slow(str= uct page_pool *pool, > =09/* Track how many pages are held 'in-flight' */ > =09pool->pages_state_hold_cnt++; > =09trace_page_pool_state_hold(pool, page, pool->pages_state_hold_cnt); > +=09return page; > +} > + > +/* slow path */ > +noinline > +static struct page *__page_pool_alloc_pages_slow(struct page_pool *pool, > +=09=09=09=09=09=09 gfp_t gfp) > +{ > +=09const int bulk =3D PP_ALLOC_CACHE_REFILL; > +=09unsigned int pp_flags =3D pool->p.flags; > +=09unsigned int pp_order =3D pool->p.order; > +=09struct page *page; > +=09int i, nr_pages; > + > +=09/* Don't support bulk alloc for high-order pages */ > +=09if (unlikely(pp_order)) > +=09=09return __page_pool_alloc_page_order(pool, gfp); > + > +=09/* Unnecessary as alloc cache is empty, but guarantees zero count */ > +=09if (unlikely(pool->alloc.count > 0)) > +=09=09return pool->alloc.cache[--pool->alloc.count]; > + > +=09/* Mark empty alloc.cache slots "empty" for alloc_pages_bulk_array */ > +=09memset(&pool->alloc.cache, 0, sizeof(void *) * bulk); > + > +=09nr_pages =3D alloc_pages_bulk_array(gfp, bulk, pool->alloc.cache); > +=09if (unlikely(!nr_pages)) > +=09=09return NULL; > + > +=09/* Pages have been filled into alloc.cache array, but count is zero a= nd > +=09 * page element have not been (possibly) DMA mapped. > +=09 */ > +=09for (i =3D 0; i < nr_pages; i++) { > +=09=09page =3D pool->alloc.cache[i]; > +=09=09if ((pp_flags & PP_FLAG_DMA_MAP) && > +=09=09 unlikely(!page_pool_dma_map(pool, page))) { > +=09=09=09put_page(page); > +=09=09=09continue; > +=09=09} > +=09=09pool->alloc.cache[pool->alloc.count++] =3D page; > +=09=09/* Track how many pages are held 'in-flight' */ > +=09=09pool->pages_state_hold_cnt++; > +=09=09trace_page_pool_state_hold(pool, page, > +=09=09=09=09=09 pool->pages_state_hold_cnt); > +=09} > + > +=09/* Return last page */ > +=09if (likely(pool->alloc.count > 0)) > +=09=09page =3D pool->alloc.cache[--pool->alloc.count]; > +=09else > +=09=09page =3D NULL; > > =09/* When page just alloc'ed is should/must have refcnt 1. */ > =09return page; > -- > 2.26.2 Al