From nobody Fri Dec 19 20:26:50 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BAE77C77B7C for ; Fri, 26 May 2023 09:28:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242722AbjEZJ2k (ORCPT ); Fri, 26 May 2023 05:28:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242732AbjEZJ23 (ORCPT ); Fri, 26 May 2023 05:28:29 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96524195; Fri, 26 May 2023 02:28:23 -0700 (PDT) Received: from dggpemm500005.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4QSKNL70jZzTjvF; Fri, 26 May 2023 17:28:18 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by dggpemm500005.china.huawei.com (7.185.36.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Fri, 26 May 2023 17:28:21 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Lorenzo Bianconi , Alexander Duyck , Jesper Dangaard Brouer , Ilias Apalodimas , Eric Dumazet Subject: [PATCH net-next 2/2] page_pool: support non-frag page for page_pool_alloc_frag() Date: Fri, 26 May 2023 17:26:15 +0800 Message-ID: <20230526092616.40355-3-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230526092616.40355-1-linyunsheng@huawei.com> References: <20230526092616.40355-1-linyunsheng@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500005.china.huawei.com (7.185.36.74) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" There is performance penalty with using page frag support when user requests a larger frag size and a page only supports one frag user, see [1]. It seems like user may request different frag size depending on the mtu and packet size, provide an option to allocate non-frag page when a whole page is not able to hold two frags, so that user has a unified interface for the memory allocation with least memory utilization and performance penalty. 1. https://lore.kernel.org/netdev/ZEU+vospFdm08IeE@localhost.localdomain/ Signed-off-by: Yunsheng Lin CC: Lorenzo Bianconi CC: Alexander Duyck --- net/core/page_pool.c | 47 +++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/net/core/page_pool.c b/net/core/page_pool.c index 0868aa8f6323..e84ec6eabefd 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -699,14 +699,27 @@ struct page *page_pool_alloc_frag(struct page_pool *p= ool, unsigned int max_size =3D PAGE_SIZE << pool->p.order; struct page *page =3D pool->frag_page; =20 - if (WARN_ON(!(pool->p.flags & PP_FLAG_PAGE_FRAG) || - size > max_size)) + if (unlikely(size > max_size)) return NULL; =20 + if (PAGE_POOL_DMA_USE_PP_FRAG_COUNT) { + *offset =3D 0; + return page_pool_alloc_pages(pool, gfp); + } + size =3D ALIGN(size, dma_get_cache_alignment()); - *offset =3D pool->frag_offset; =20 - if (page && *offset + size > max_size) { + if (page) { + *offset =3D pool->frag_offset; + + if (*offset + size <=3D max_size) { + pool->frag_users++; + pool->frag_offset =3D *offset + size; + alloc_stat_inc(pool, fast); + return page; + } + + pool->frag_page =3D NULL; page =3D page_pool_drain_frag(pool, page); if (page) { alloc_stat_inc(pool, fast); @@ -714,26 +727,24 @@ struct page *page_pool_alloc_frag(struct page_pool *p= ool, } } =20 - if (!page) { - page =3D page_pool_alloc_pages(pool, gfp); - if (unlikely(!page)) { - pool->frag_page =3D NULL; - return NULL; - } - - pool->frag_page =3D page; + page =3D page_pool_alloc_pages(pool, gfp); + if (unlikely(!page)) + return NULL; =20 frag_reset: - pool->frag_users =3D 1; + /* return page as non-frag page if a page is not able to + * hold two frags for the current requested size. + */ + if (unlikely(size << 1 > max_size)) { *offset =3D 0; - pool->frag_offset =3D size; - page_pool_fragment_page(page, BIAS_MAX); return page; } =20 - pool->frag_users++; - pool->frag_offset =3D *offset + size; - alloc_stat_inc(pool, fast); + pool->frag_page =3D page; + pool->frag_users =3D 1; + *offset =3D 0; + pool->frag_offset =3D size; + page_pool_fragment_page(page, BIAS_MAX); return page; } EXPORT_SYMBOL(page_pool_alloc_frag); --=20 2.33.0