Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3300318lqp; Tue, 26 Mar 2024 05:47:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW5Arp1mpfTD1H0v2dbl8K6tpu5+3iizp0/H7TkUcpVLwBARnXQXXcAfzMWyvrk6ZIddwhZAugJD2/pQH1BeqsoM/Ryab6/9uiswDGQOw== X-Google-Smtp-Source: AGHT+IGRy5KGqdrtdUF6OuMx8O95ZTdHihrLRaSbB5mnXFGjCmXYYkv3Mi6s/9/e9WJjf/nv7HBJ X-Received: by 2002:a17:902:9a07:b0:1de:fbc2:99f0 with SMTP id v7-20020a1709029a0700b001defbc299f0mr835479plp.2.1711457272703; Tue, 26 Mar 2024 05:47:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711457272; cv=pass; d=google.com; s=arc-20160816; b=O2YjkXR3Pe3TXucxYWxrkR7aCBgRUq6bFfqXfa8RUkbOfes8NTTVjcgNJic1Vssgyu 4c9pibwFKpUtjGy3Q94v4MbX3UAJfWuEBd+4OgWHYSuuaqirAT6aaGJMdm2B2XsZrCkL 190lQja25sjtI/kxn2/w49O2rED9Su4d9ZV0YkHag/I5UMnK56qhphK2DiO4Rfvy4FwP RuUFZlUktsyz4CsxhRNuKEec5OE2cxEAlTPfnbf1f7VxmpuQ9KvuhcYPnMyfczqJSa+t /KuCIX2KdN4ytTNCuXyRo39rqWQS+WnzuDNQSaiU0H8texTVSe2hKDr74Q3XEmvxTTm9 ej9Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:in-reply-to:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:user-agent:date :message-id:from:references:cc:to:subject; bh=mbOrrKJJgQEVFURqXBrL3ewbgB99hCrLnQmE0ZZB2+w=; fh=Jc5yh+JjOZYlkaBIwuaw4eTcQO6tOxG8CSFCf+d81JM=; b=mwqu/n6dT4sl8lRZXa9ZimmFY+6l2GTHfXaDD31qN0DZoViCqbeZ25agE41wl28xCk ywKbGlvlLNFxw6qyiKr2nUesJYM3J3lhFRZ3KFTgi8qgJ5FU42ciJIJzqZa8+Z/tX0U0 KSUW0x2nbPloJq18QZJ+v6sLuqPJJWZUt1rhzghLZAv3R4i5T1CnTFnelgJsfaa+U7L0 Ico5T4WuSJDu0dgyrxGFLGHGnNyHU/oXS3v1F7sFdFWX0OPX/KB0D07eB8/aFYgQoZo0 SLCa9ctTDThs2YtpegoSxZskKq6GSb74/skpSMo39f2qFiNtBD0+zqMDR69WOMkD46QU XaHw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-119006-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119006-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=QUARANTINE) header.from=huawei.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id m16-20020a170902f65000b001e0a5db2e57si7013614plg.54.2024.03.26.05.47.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 05:47:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-119006-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-119006-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119006-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=QUARANTINE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 44A7B304BC0 for ; Tue, 26 Mar 2024 12:47:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 100CC71756; Tue, 26 Mar 2024 12:47:26 +0000 (UTC) Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (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 0826D139E; Tue, 26 Mar 2024 12:47:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711457245; cv=none; b=IBTf+jFr+Ryz/oWCtPW+jwPzqOtRqqzL3t+Hby9L56GTsbtUXyk8J6rmEIkyS74tGB6jhSByQaeG83hz8efzzJnTJUqYuZTxeOtWxQhVRAupG+ihckYmZK50kkpSGLeIheqyZvzwC0otJuc+tftsxAgvO6NAkvc5SqJHQHJaKy4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711457245; c=relaxed/simple; bh=sGJsi5QL5OEY3rakPIBQalfrmkZhP62VUd/1rO/Tex0=; h=Subject:To:CC:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=DfJ3VN04r+4INdHxV48V0lQz7d8EB/2PUJWx4xT/AyraDzO1NeWNm5TTs4gNneBDn5ZyU0L1WgouB7fI+dbSciSGO++epSeV5V4pkSLMGKO2QxZBCzrx3syGdYVbPsKWz5GEmA2DiywhOEv3/abWddIsQNVDlfidgA0bjAM2jq4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4V3qJ843l4z2BhYv; Tue, 26 Mar 2024 20:44:40 +0800 (CST) Received: from dggpemm500005.china.huawei.com (unknown [7.185.36.74]) by mail.maildlp.com (Postfix) with ESMTPS id 4E2C9140120; Tue, 26 Mar 2024 20:47:19 +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_256_GCM_SHA384) id 15.1.2507.35; Tue, 26 Mar 2024 20:47:18 +0800 Subject: Re: [RFC PATCH net-next v6 00/15] Device Memory TCP To: Mina Almasry , YiFei Zhu CC: , , , , , , , , , , , , , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Richard Henderson , Ivan Kokshaysky , Matt Turner , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Andreas Larsson , Jesper Dangaard Brouer , Ilias Apalodimas , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Arnd Bergmann , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , David Ahern , Willem de Bruijn , Shuah Khan , Sumit Semwal , =?UTF-8?Q?Christian_K=c3=b6nig?= , Pavel Begunkov , David Wei , Jason Gunthorpe , Shailend Chand , Harshitha Ramamurthy , Shakeel Butt , Jeroen de Borst , Praveen Kaligineedi References: <20240305020153.2787423-1-almasrymina@google.com> <6208950d-6453-e797-7fc3-1dcf15b49dbe@huawei.com> From: Yunsheng Lin Message-ID: Date: Tue, 26 Mar 2024 20:47:18 +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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500005.china.huawei.com (7.185.36.74) On 2024/3/26 8:28, Mina Almasry wrote: > On Tue, Mar 5, 2024 at 11:38 AM Mina Almasry wrote: >> >> On Tue, Mar 5, 2024 at 4:54 AM Yunsheng Lin wrote: >>> >>> On 2024/3/5 10:01, Mina Almasry wrote: >>> >>> ... >>> >>>> >>>> Perf - page-pool benchmark: >>>> --------------------------- >>>> >>>> bench_page_pool_simple.ko tests with and without these changes: >>>> https://pastebin.com/raw/ncHDwAbn >>>> >>>> AFAIK the number that really matters in the perf tests is the >>>> 'tasklet_page_pool01_fast_path Per elem'. This one measures at about 8 >>>> cycles without the changes but there is some 1 cycle noise in some >>>> results. >>>> >>>> With the patches this regresses to 9 cycles with the changes but there >>>> is 1 cycle noise occasionally running this test repeatedly. >>>> >>>> Lastly I tried disable the static_branch_unlikely() in >>>> netmem_is_net_iov() check. To my surprise disabling the >>>> static_branch_unlikely() check reduces the fast path back to 8 cycles, >>>> but the 1 cycle noise remains. >>>> >>> >>> The last sentence seems to be suggesting the above 1 ns regresses is caused >>> by the static_branch_unlikely() checking? >> >> Note it's not a 1ns regression, it's looks like maybe a 1 cycle >> regression (slightly less than 1ns if I'm reading the output of the >> test correctly): >> >> # clean net-next >> time_bench: Type:tasklet_page_pool01_fast_path Per elem: 8 cycles(tsc) >> 2.993 ns (step:0) >> >> # with patches >> time_bench: Type:tasklet_page_pool01_fast_path Per elem: 9 cycles(tsc) >> 3.679 ns (step:0) >> >> # with patches and with diff that disables static branching: >> time_bench: Type:tasklet_page_pool01_fast_path Per elem: 8 cycles(tsc) >> 3.248 ns (step:0) >> >> I do see noise in the test results between run and run, and any >> regression (if any) is slightly obfuscated by the noise, so it's a bit >> hard to make confident statements. So far it looks like a ~0.25ns >> regression without static branch and about ~0.65ns with static branch. >> >> Honestly when I saw all 3 results were within some noise I did not >> investigate more, but if this looks concerning to you I can dig >> further. I likely need to gather a few test runs to filter out the >> noise and maybe investigate the assembly my compiler is generating to >> maybe narrow down what changes there. >> > > I did some more investigation here to gather more data to filter out > the noise, and recorded the summary here: > > https://pastebin.com/raw/v5dYRg8L > > Long story short, the page_pool benchmark results are consistent with > some outlier noise results that I'm discounting here. Currently > page_pool fast path is at 8 cycles > > [ 2115.724510] time_bench: Type:tasklet_page_pool01_fast_path Per > elem: 8 cycles(tsc) 3.187 ns (step:0) - (measurement period > time:0.031870585 sec time_interval:31870585) - (invoke count:10000000 > tsc_interval:86043192) > > and with this patch series it degrades to 10 cycles, or about a 0.7ns > degradation or so: Even if the absolute value for the overhead is small, we seems have a degradation of about 20% for tasklet_page_pool01_fast_path testcase, which seems scary. I am assuming that every page is recyclable for tasklet_page_pool01_fast_path testcase, and that code path matters for page_pool, it would be good to remove any additional checking for that code path. And we already have pool->has_init_callback checking when we have to use a new page, it may make sense to refactor that to share the same checking for provider to avoid the overhead as much as possible. Also, I am not sure if it really matter that much, as with the introducing of netmem_is_net_iov() checking spreading in the networking, the overhead might add up for other case too. > > [ 498.226127] time_bench: Type:tasklet_page_pool01_fast_path Per > elem: 10 cycles(tsc) 3.944 ns (step:0) - (measurement period > time:0.039442539 sec time_interval:39442539) - (invoke count:10000000 > tsc_interval:106485268) > > I took the time to dig into where the degradation comes from, and to > my surprise we can shave off 1 cycle in perf by removing the > static_branch_unlikely check in netmem_is_net_iov() like so: > > diff --git a/include/net/netmem.h b/include/net/netmem.h > index fe354d11a421..2b4310ac1115 100644 > --- a/include/net/netmem.h > +++ b/include/net/netmem.h > @@ -122,8 +122,7 @@ typedef unsigned long __bitwise netmem_ref; > static inline bool netmem_is_net_iov(const netmem_ref netmem) > { > #ifdef CONFIG_PAGE_POOL > - return static_branch_unlikely(&page_pool_mem_providers) && > - (__force unsigned long)netmem & NET_IOV; > + return (__force unsigned long)netmem & NET_IOV; > #else > return false; > #endif > > With this change, the fast path is 9 cycles, only a 1 cycle (~0.35ns) > regression: > > [ 199.184429] time_bench: Type:tasklet_page_pool01_fast_path Per > elem: 9 cycles(tsc) 3.552 ns (step:0) - (measurement period > time:0.035524013 sec time_interval:35524013) - (invoke count:10000000 > tsc_interval:95907775) > > I did some digging with YiFei on why the static_branch_unlikely > appears to be causing a 1 cycle regression, but could not get an > answer that makes sense. The # of instructions in > page_pool_return_page() with the static_branch_unlikely and without is > about the same in the compiled .o file, and my understanding is that > static_branch will cause code re-writing anyway so looking at the > compiled code may not be representative. > > Worthy of note is that I get ~95% line rate of devmem TCP regardless > of the static_branch_unlikely() or not, so impact of the static_branch > is not large enough to be measurable end-to-end. I'm thinking I want > to drop the static_branch_unlikely() in the next RFC since it doesn't > improve the end-to-end throughput number and is resulting in a > measurable improvement in the page pool benchmark. >