Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp6587991rwl; Wed, 22 Mar 2023 12:35:57 -0700 (PDT) X-Google-Smtp-Source: AK7set+tguwpSLcSnmevIfD/9mzq1wWKTKzVvJrXoPPuZWO3mMJZLc9NhxLPr0eY0CyJaAzXbuVE X-Received: by 2002:a17:903:790:b0:19e:73a9:c21b with SMTP id kn16-20020a170903079000b0019e73a9c21bmr2908174plb.45.1679513756841; Wed, 22 Mar 2023 12:35:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679513756; cv=none; d=google.com; s=arc-20160816; b=uNPYn110ed+zAluuFbsYc/JfewAjxoO0hyv8e0E87TQSfT09DX5thtdbhMW9wxEbKX rVaaEah1cnwiWHDUvi9mP6FfbH/gOQrv3umRW4pVnLp9YyUuKpIO+z5TT8zJv7zoUL7w DWEvCfPe7xFOUFpwMVjocThF3YsfFI9gF3ClpFmCwjybTcG/CvCZGUPo9HJHxTcKv8Ne 9TcsLYmi4go9A7ays4c0K2r6aZCn9vvhGcxZCBIura6cs/bCr+VfcmvwdmVVAzOjcNrd uHpkb5Uh7nydEwz4/45jN/y9nvbM5DsQ7PIG0jfgcFhSO50RdBPHMFkVoNOAcAmafuvx pGdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=u9pF4ToPrhXz8nASGFtExWuFKKF7EZCz4E+qL2ZPQrw=; b=lj6Y1/gtNU71JHVo4LoPEElPzvMPTOCEfjP2yjztLHdgm4iBaq/ig1+7jj+Z/ICt9G M4oXMm9ZDH6ctRMS8y9YvoUnUI9dlVYX6VFb1cWLOqDdgSISD3dS4Run2ksnbgje/t51 DdAC4Nm1rJv1A+EduDk3KnrQeNBKGI+lSNasoQIMwbyzzKswV0gIe69Vet0m2+ck6izS 7m8DZaRw4N9JcCJFOXB4QfRG7z0DyqRhpYfiLpbEebOCxC4FZ0DvOOCYVV9lT7+kENav 7MFTOWZAUnniBO9711SGrARyn1DzLeLnEysdL+kU/KtehkCZO+VCvpWLjh2MT4LQu6r4 5iXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="g21z0Z/s"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d19-20020a170903209300b0019e95180a08si15279095plc.59.2023.03.22.12.35.45; Wed, 22 Mar 2023 12:35:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="g21z0Z/s"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229676AbjCVTdx (ORCPT + 99 others); Wed, 22 Mar 2023 15:33:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229484AbjCVTdv (ORCPT ); Wed, 22 Mar 2023 15:33:51 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF6F762334; Wed, 22 Mar 2023 12:33:49 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id r11so1453706wrr.12; Wed, 22 Mar 2023 12:33:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679513628; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=u9pF4ToPrhXz8nASGFtExWuFKKF7EZCz4E+qL2ZPQrw=; b=g21z0Z/sMeKPHMgN5MtC55qXIz+3VQdqTooalkDlZeAb85RwoOmwtq7S4cekg7vlI3 mRDMgRk5loZs8mJkyjcs6LkB+tMf/PNs0LJuuyDXcqwJ1QOTjaOxoxSvDqP0Xi1N5jNP YhsEXsYry/GyKssOrZwm/ciLijiIm6Oo6QQF+tJ6ytQcontx5yIEElJqx3DaBeHsABOF VYh0q20v5WEDpv753pZswQg6qIJXKh1X7bA5aiwRHlqX5rfUkEOzxhwdhaJjUctUnf6P cmo0+uDHlFREko0wSY54Mf1jwIoBbfaEICuOeL74wX1wYJdu7b7dRYKCmPzoUi6+VrzB mJJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679513628; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u9pF4ToPrhXz8nASGFtExWuFKKF7EZCz4E+qL2ZPQrw=; b=xqJL/rjadH45DVz6sLJnbx98omu96I51+SmtfSW4UhNUqeL91nd/J+Mw1r0nX5zPh2 iAzuP3eWlixPpVhesF7KXUiIx0gn6VTcDugEcWOuBxZ/dFeW0yL7XX31edcqjtTsoC4d JdeDKXwAWmIQic1rmUH7bMqnyFA5VJD1CuIrqeCuZz17uCThJLdvD8wXxvAiDKaVZL/p q33Q4ZKfdDEhBlmYEHEo746i5Hf948CnMo6nReGpcTqHGh9QLPczf9qYKFe7x23vRkCj iPXdLmCHKNge3JexnvqLsczi1BUChB6Ois6WB9s2VobGHNFgT1ApOIO8qQ3iyOF+S/0B TCZQ== X-Gm-Message-State: AAQBX9fWunsD1eSWrRTdEd9pbWInFRxsiw3vn/GR85/XeX9WAyDXjDBh vBx32gcLHFZ69rKjwwA1WBI= X-Received: by 2002:adf:f50f:0:b0:2ce:fd37:938c with SMTP id q15-20020adff50f000000b002cefd37938cmr707319wro.50.1679513628179; Wed, 22 Mar 2023 12:33:48 -0700 (PDT) Received: from debian ([89.238.191.199]) by smtp.gmail.com with ESMTPSA id h6-20020adfe986000000b002d09cba6beasm14646181wrm.72.2023.03.22.12.33.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 12:33:47 -0700 (PDT) Date: Wed, 22 Mar 2023 20:33:11 +0100 From: Richard Gobert To: Eric Dumazet , pabeni@redhat.com Cc: Paolo Abeni , davem@davemloft.net, kuba@kernel.org, dsahern@kernel.org, alexanderduyck@fb.com, lucien.xin@gmail.com, lixiaoyan@google.com, iwienand@redhat.com, leon@kernel.org, ye.xingchen@zte.com.cn, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 2/2] gro: optimise redundant parsing of packets Message-ID: <20230322193309.GA32681@debian> References: <20230320163703.GA27712@debian> <20230320170009.GA27961@debian> <889f2dc5e646992033e0d9b0951d5a42f1907e07.camel@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Wed, Mar 22, 2023 at 2:59 AM Paolo Abeni wrote: > > > > On Mon, 2023-03-20 at 18:00 +0100, Richard Gobert wrote: > > > Currently the IPv6 extension headers are parsed twice: first in > > > ipv6_gro_receive, and then again in ipv6_gro_complete. > > > > > > By using the new ->transport_proto field, and also storing the size of the > > > network header, we can avoid parsing extension headers a second time in > > > ipv6_gro_complete (which saves multiple memory dereferences and conditional > > > checks inside ipv6_exthdrs_len for a varying amount of extension headers in > > > IPv6 packets). > > > > > > The implementation had to handle both inner and outer layers in case of > > > encapsulation (as they can't use the same field). I've applied a similar > > > optimisation to Ethernet. > > > > > > Performance tests for TCP stream over IPv6 with a varying amount of > > > extension headers demonstrate throughput improvement of ~0.7%. > > > > I'm surprised that the improvement is measurable: for large aggregate > > packets a single ipv6_exthdrs_len() call is avoided out of tens calls > > for the individual pkts. Additionally such figure is comparable to > > noise level in my tests. It's not simple but I made an effort to make a quiet environment. Correct configuration allows for this kind of measurements to be made as the test is CPU bound and noise is a variance that can be reduced with enough samples. Environment example: (100Gbit NIC (mlx5), physical machine, i9 12th gen) # power-management and hyperthreading disabled in BIOS # sysctl preallocate net mem echo 0 > /sys/devices/system/cpu/cpufreq/boost # disable turboboost ethtool -A enp1s0f0np0 rx off tx off autoneg off # no PAUSE frames # Single core performance for x in /sys/devices/system/cpu/cpu[1-9]*/online; do echo 0 >"$x"; done ./network-testing-master/bin/netfilter_unload_modules.sh 2>/dev/null # unload netfilter tuned-adm profile latency-performance cpupower frequency-set -f 2200MHz # Set core to specific frequency systemctl isolate rescue-ssh.target # and kill all processes besides init > > This adds a couple of additional branches for the common (no extensions > > header) case. The additional branch in ipv6_gro_receive would be negligible or even non-existent for a branch predictor in the common case (non-encapsulated packets). I could wrap it with a likely macro if you wish. Inside ipv6_gro_complete a couple of branches are saved for the common case as demonstrated below. original code ipv6_gro_complete (ipv6_exthdrs_len is inlined): // if (skb->encapsulation) ffffffff81c4962b: f6 87 81 00 00 00 20 testb $0x20,0x81(%rdi) ffffffff81c49632: 74 2a je ffffffff81c4965e ... // nhoff += sizeof(*iph) + ipv6_exthdrs_len(iph, &ops); ffffffff81c4969c: eb 1b jmp ffffffff81c496b9 <-- jump to beginning of for loop ffffffff81c4968e: b8 28 00 00 00 mov $0x28,%eax ffffffff81c49693: 31 f6 xor %esi,%esi ffffffff81c49695: 48 c7 c7 c0 28 aa 82 mov $0xffffffff82aa28c0,%rdi ffffffff81c4969c: eb 1b jmp ffffffff81c496b9 ffffffff81c4969e: f6 41 18 01 testb $0x1,0x18(%rcx) ffffffff81c496a2: 74 34 je ffffffff81c496d8 <--- 3rd conditional check: !((*opps)->flags & INET6_PROTO_GSO_EXTHDR) ffffffff81c496a4: 48 98 cltq ffffffff81c496a6: 48 01 c2 add %rax,%rdx ffffffff81c496a9: 0f b6 42 01 movzbl 0x1(%rdx),%eax ffffffff81c496ad: 0f b6 0a movzbl (%rdx),%ecx ffffffff81c496b0: 8d 04 c5 08 00 00 00 lea 0x8(,%rax,8),%eax ffffffff81c496b7: 01 c6 add %eax,%esi ffffffff81c496b9: 85 c9 test %ecx,%ecx <--- for loop starts here ffffffff81c496bb: 74 e7 je ffffffff81c496a4 <--- 1st conditional check: proto != NEXTHDR_HOP ffffffff81c496bd: 48 8b 0c cf mov (%rdi,%rcx,8),%rcx ffffffff81c496c1: 48 85 c9 test %rcx,%rcx ffffffff81c496c4: 75 d8 jne ffffffff81c4969e <--- 2nd conditional check: unlikely(!(*opps)) ... (indirect call ops->callbacks.gro_complete) ipv6_exthdrs_len contains a loop which has 3 conditional checks. For the common (no extensions header) case, in the new code, *all 3 branches are completely avoided* patched code ipv6_gro_complete: // if (skb->encapsulation) ffffffff81befe58: f6 83 81 00 00 00 20 testb $0x20,0x81(%rbx) ffffffff81befe5f: 74 78 je ffffffff81befed9 ... // else ffffffff81befed9: 0f b6 43 50 movzbl 0x50(%rbx),%eax ffffffff81befedd: 0f b7 73 4c movzwl 0x4c(%rbx),%esi ffffffff81befee1: 48 8b 0c c5 c0 3f a9 mov -0x7d56c040(,%rax,8),%rcx ... (indirect call ops->callbacks.gro_complete) Thus, the patch is beneficial for both the common case and the ext hdr case. I would appreciate a second consideration :) > > while patch 1/2 could be useful, patch 2/2 overall looks not worthy to > > me. > > > > I suggest to re-post for inclusion only patch 1, unless others have > > strong different opinions. > > > > +2 > > I have the same feeling/opinion. > > > Cheers, > > > > Paolo > >