From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E50741427C; Fri, 16 Jun 2023 11:57:25 +0000 (UTC) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED28030EA; Fri, 16 Jun 2023 04:57:16 -0700 (PDT) Received: from dggpemm500005.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4QjHcx0gb6zMpB5; Fri, 16 Jun 2023 19:54:09 +0800 (CST) Received: from [10.69.30.204] (10.69.30.204) 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, 16 Jun 2023 19:57:14 +0800 Subject: Re: [PATCH net-next v3 3/4] page_pool: introduce page_pool_alloc() API To: Jesper Dangaard Brouer , Alexander Duyck CC: , , , , , , Lorenzo Bianconi , Jesper Dangaard Brouer , Ilias Apalodimas , Eric Dumazet , Maryam Tahhan , bpf References: <20230609131740.7496-1-linyunsheng@huawei.com> <20230609131740.7496-4-linyunsheng@huawei.com> <36366741-8df2-1137-0dd9-d498d0f770e4@huawei.com> <0ba1bf9c-2e45-cd44-60d3-66feeb3268f3@redhat.com> From: Yunsheng Lin Message-ID: Date: Fri, 16 Jun 2023 19:57:14 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <0ba1bf9c-2e45-cd44-60d3-66feeb3268f3@redhat.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.69.30.204] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500005.china.huawei.com (7.185.36.74) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net On 2023/6/16 0:19, Jesper Dangaard Brouer wrote: ... > You have mentioned veth as the use-case. I know I acked adding page_pool > use-case to veth, for when we need to convert an SKB into an > xdp_buff/xdp-frame, but maybe it was the wrong hammer(?). > In this case in veth, the size is known at the page allocation time. > Thus, using the page_pool API is wasting memory. We did this for > performance reasons, but we are not using PP for what is was intended > for. We mostly use page_pool, because it an existing recycle return > path, and we were too lazy to add another alloc-type (see enum > xdp_mem_type). > > Maybe you/we can extend veth to use this dynamic size API, to show us > that this is API is a better approach. I will signup for benchmarking > this (and coordinating with CC Maryam as she came with use-case we > improved on). Thanks, let's find out if page pool is the right hammer for the veth XDP case. Below is the change for veth using the new api in this patch. Only compile test as I am not familiar enough with veth XDP and testing environment for it. Please try it if it is helpful. diff --git a/drivers/net/veth.c b/drivers/net/veth.c index 614f3e3efab0..8850394f1d29 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -736,7 +736,7 @@ static int veth_convert_skb_to_xdp_buff(struct veth_rq *rq, if (skb_shared(skb) || skb_head_is_locked(skb) || skb_shinfo(skb)->nr_frags || skb_headroom(skb) < XDP_PACKET_HEADROOM) { - u32 size, len, max_head_size, off; + u32 size, len, max_head_size, off, truesize, page_offset; struct sk_buff *nskb; struct page *page; int i, head_off; @@ -752,12 +752,15 @@ static int veth_convert_skb_to_xdp_buff(struct veth_rq *rq, if (skb->len > PAGE_SIZE * MAX_SKB_FRAGS + max_head_size) goto drop; + size = min_t(u32, skb->len, max_head_size); + truesize = size; + /* Allocate skb head */ - page = page_pool_dev_alloc_pages(rq->page_pool); + page = page_pool_dev_alloc(rq->page_pool, &page_offset, &truesize); if (!page) goto drop; - nskb = napi_build_skb(page_address(page), PAGE_SIZE); + nskb = napi_build_skb(page_address(page) + page_offset, truesize); if (!nskb) { page_pool_put_full_page(rq->page_pool, page, true); goto drop; @@ -767,7 +770,6 @@ static int veth_convert_skb_to_xdp_buff(struct veth_rq *rq, skb_copy_header(nskb, skb); skb_mark_for_recycle(nskb); - size = min_t(u32, skb->len, max_head_size); if (skb_copy_bits(skb, 0, nskb->data, size)) { consume_skb(nskb); goto drop; @@ -782,14 +784,17 @@ static int veth_convert_skb_to_xdp_buff(struct veth_rq *rq, len = skb->len - off; for (i = 0; i < MAX_SKB_FRAGS && off < skb->len; i++) { - page = page_pool_dev_alloc_pages(rq->page_pool); + size = min_t(u32, len, PAGE_SIZE); + truesize = size; + + page = page_pool_dev_alloc(rq->page_pool, &page_offset, + &truesize); if (!page) { consume_skb(nskb); goto drop; } - size = min_t(u32, len, PAGE_SIZE); - skb_add_rx_frag(nskb, i, page, 0, size, PAGE_SIZE); + skb_add_rx_frag(nskb, i, page, page_offset, size, truesize); if (skb_copy_bits(skb, off, page_address(page), size)) { consume_skb(nskb); > > --Jesper > > . >