Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1489083pxf; Fri, 12 Mar 2021 10:39:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJxyTL+9nGBkzzW0x1Ua6yiNffWq0pW65EVd+AArO7nP/Yc8aVVe57xUo0JApp4cJKzm8c6A X-Received: by 2002:a05:6402:38f:: with SMTP id o15mr15573340edv.361.1615574340869; Fri, 12 Mar 2021 10:39:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615574340; cv=none; d=google.com; s=arc-20160816; b=DLE3Ij5qBYsuGQ5cV8RWfKQ3IWwTT7MLH5tAVqVOGXFQSXBmUpPy3E/HZxsqTAopeO gzgO0dkglBsrAKD5HSmfNGHf2dQ+Kd2c3AtxUPXNdMzbEAGIVfvJj/E0OYL9HokA75qx giXGO+hi1f0qm4EiuxPlrSsRPJ+PcdPO3vLfykbcS8BRzMebE7RyycIGtsrvESNDXqg8 s4xGswLHi1521BRt98bTOo6Zfg94kU+0BjOZtOI1j3zCi/TalTESU76TTj9Fs0TdIQ+R XVN21ROS9KrwLfY0dc3aFj/tsVC1MdkyJfSSl4V2UZaz6QxsXwlkPuW3rOyD63d5rmXe KoKw== 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=C4flYNl55MhaTml/vQIThEyldeDzlRdNXoMAWOGH2ZU=; b=e+CUi6LBfTGUszm3BDaZ+LHgP5bo0AempLjn15qyXC85Yn6fYfNOneBwzMeKcGG/mL 7aEV6YDWeqGJqe8SQRU16bWDhHkU6fCdg/2mnMZI83MjTh8VbJ6dROwotMa+HfMhXylr lgRJNcGfE+vPNMn67oLe5P6/BUrFdn5lnLr9qqjEYzWHf/B4e18WLpOcBIoXWXlyxniH DuExtCiNBcDU3fQVtTomisjdbw2p7UjiPPS3uJ8h1ewHgKowWPF9MkA3Bic1Rq4uv5Gu scrJGCTVpaPTMDkeQ85g0gc0uuEQAe34s+T6LwxtGBAwEdFspYWXURW9qy2WHSCtzoBy Tngw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail header.b="Qz+2/NJc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 u10si4775496ejb.59.2021.03.12.10.38.37; Fri, 12 Mar 2021 10:39:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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="Qz+2/NJc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 S233600AbhCLShl (ORCPT + 99 others); Fri, 12 Mar 2021 13:37:41 -0500 Received: from mail1.protonmail.ch ([185.70.40.18]:62345 "EHLO mail1.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233517AbhCLShK (ORCPT ); Fri, 12 Mar 2021 13:37:10 -0500 Date: Fri, 12 Mar 2021 18:36:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail; t=1615574228; bh=C4flYNl55MhaTml/vQIThEyldeDzlRdNXoMAWOGH2ZU=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=Qz+2/NJcNf9bDM6PkSlnYsbqlAX12lI2+aZ/GiEqrund2o7VjfuoRcv6C6wXppBZ/ KoPhQqf2NMM85+XnHD+Sv6xkuWlX5SSbwdl6T4l4yWf4mtRCVVsO7iWk4U2aVAXp43 LUNM5aMMbaUXX38bZoM5qlBzvs5lq/eVz/SGkL9lHS0hEIiICmkGBLZoQ9yWrsOduv 0bQA82/45rbBgfWo9CvaD7ugphtytM/W6s36VLDdjddneMRTOYprNMapNNHbs6Oj3t y/AM2DzN3A4JY6ZNFY5qeHHylgDPhXAdIkdQcBCqjt4eICH/IVr31XnaONkSATSWNN +GbDLk+9HPuTQ== To: Eric Dumazet From: Alexander Lobakin Cc: Alexander Lobakin , "David S. Miller" , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Wei Wang , Cong Wang , Taehee Yoo , netdev , LKML Reply-To: Alexander Lobakin Subject: Re: [PATCH net-next 2/4] gro: don't dereference napi->gro_hash[x] multiple times in dev_gro_receive() Message-ID: <20210312183648.242117-1-alobakin@pm.me> In-Reply-To: References: <20210312162127.239795-1-alobakin@pm.me> <20210312162127.239795-3-alobakin@pm.me> 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-kernel@vger.kernel.org From: Eric Dumazet Date: Fri, 12 Mar 2021 17:47:04 +0100 > On Fri, Mar 12, 2021 at 5:22 PM Alexander Lobakin wrote: > > > > GRO bucket index doesn't change through the entire function. > > Store a pointer to the corresponding bucket on stack once and use > > it later instead of dereferencing again and again. > > > > Signed-off-by: Alexander Lobakin > > --- > > net/core/dev.c | 9 +++++---- > > 1 file changed, 5 insertions(+), 4 deletions(-) > > > > diff --git a/net/core/dev.c b/net/core/dev.c > > index adc42ba7ffd8..ee124aecb8a2 100644 > > --- a/net/core/dev.c > > +++ b/net/core/dev.c > > @@ -5957,6 +5957,7 @@ static void gro_flush_oldest(struct napi_struct *= napi, struct list_head *head) > > static enum gro_result dev_gro_receive(struct napi_struct *napi, struc= t sk_buff *skb) > > { > > u32 bucket =3D skb_get_hash_raw(skb) & (GRO_HASH_BUCKETS - 1); > > + struct gro_list *gro_list =3D &napi->gro_hash[bucket]; > > struct list_head *head =3D &offload_base; > > struct packet_offload *ptype; > > __be16 type =3D skb->protocol; > > @@ -6024,7 +6025,7 @@ static enum gro_result dev_gro_receive(struct nap= i_struct *napi, struct sk_buff > > if (pp) { > > skb_list_del_init(pp); > > napi_gro_complete(napi, pp); > > - napi->gro_hash[bucket].count--; > > + gro_list->count--; > > } > > > > if (same_flow) > > @@ -6033,10 +6034,10 @@ static enum gro_result dev_gro_receive(struct n= api_struct *napi, struct sk_buff > > if (NAPI_GRO_CB(skb)->flush) > > goto normal; > > > > - if (unlikely(napi->gro_hash[bucket].count >=3D MAX_GRO_SKBS)) { > > + if (unlikely(gro_list->count >=3D MAX_GRO_SKBS)) { > > gro_flush_oldest(napi, gro_head); > > } else { > > - napi->gro_hash[bucket].count++; > > + gro_list->count++; > > } > > NAPI_GRO_CB(skb)->count =3D 1; > > NAPI_GRO_CB(skb)->age =3D jiffies; > > @@ -6050,7 +6051,7 @@ static enum gro_result dev_gro_receive(struct nap= i_struct *napi, struct sk_buff > > if (grow > 0) > > gro_pull_from_frag0(skb, grow); > > ok: > > - if (napi->gro_hash[bucket].count) { > > + if (gro_list->count) { > > if (!test_bit(bucket, &napi->gro_bitmask)) > > __set_bit(bucket, &napi->gro_bitmask); > > } else if (test_bit(bucket, &napi->gro_bitmask)) { > > -- > > 2.30.2 > > > > > > This adds more register pressure, do you have precise measures to > confirm this change is a win ? > > Presumably the compiler should be able to optimize the code just fine, > it can see @bucket does not change. This is mostly (if not purely) cosmetic, I don't think it changes anything at all for the most of sane compilers. Regarding registers, since @gro_list and @gro_head are pretty the same, we could drop @gro_head in favour of @gro_list and just use @gro_list->list instead. Al