Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1387540pxf; Fri, 12 Mar 2021 08:23:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJzLoxmUvxPscjGuN4cT+m8tUgMG7zlVnMSXCbcTsvHh7yqBpZdKXFLKhyFD7Nd1gL9KiW4h X-Received: by 2002:a17:906:2c0c:: with SMTP id e12mr9509623ejh.408.1615566220420; Fri, 12 Mar 2021 08:23:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615566220; cv=none; d=google.com; s=arc-20160816; b=bddfqf9j/YGr3w0BXf+Q0FqITrl/Zw/yHUxAGDre4alHVtzzsoN6eFrG1LeH6OEgGk ivtJHlG6xq/UR6F0vuRsJF/AGohgUiVuq1YFo1xSR+PM+eQmqgOQ1ey//SrsKBsT9Kfm LO+MOE6v94REvcQqt/uO+izIoHI+Nhtsh3QMyvUggfGu8kaq6YcVndH1HOTXc7w0ofsY DR6PmTSQIIkgvUO9cwyzBXpuJ/HI/SODFuEL8MFqlP7xGG9YIj+GKhu4cJ0aho4SX90j mz9BkuDSQrj6n0QtTQnZy8hWt38fw3ds8otXLAuqMWrYeVICBWuT0VgztJ9xSjlFr4BN QqYQ== 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=pYXdNgxXLm9jRXofMIKcS3j5jzWazEkuwrSWkfABQ9g=; b=vTTprtctN3bni4L9IxOa1to7LT9xufGBMNB8hYF0ytyTgZD9RyMHeIQWZVDuNtJWxv F1dGfs/uh69dvAkaebKCB887Wx0k6knoqL/TRyU+9OZY042NEiQOMMvWAhZKgblP5qew MIlFn47pfDI9GAxR1UQemgQxINX1NOIPlZHiCqlbHeNdwR2JbO+slkd+UMbQ3j0auFiB xj0/Jv9t3+0K3qPndlyrF9bzpPOHs+XW5j0hh4p4DKOPOSk/hvGBcWiqcX4Qpvk2qFf3 T60ThDsfxpBzb1bb0mzsqtjl6FX7GIqi3zmikfObpE1NadsC195Nvab7717ktOR02UZc oUGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail header.b=KVNUVCXh; 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 ay20si4365211ejb.414.2021.03.12.08.23.17; Fri, 12 Mar 2021 08:23:40 -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=KVNUVCXh; 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 S232506AbhCLQWW (ORCPT + 99 others); Fri, 12 Mar 2021 11:22:22 -0500 Received: from mail-40133.protonmail.ch ([185.70.40.133]:49986 "EHLO mail-40133.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231849AbhCLQWB (ORCPT ); Fri, 12 Mar 2021 11:22:01 -0500 Date: Fri, 12 Mar 2021 16:21:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail; t=1615566119; bh=pYXdNgxXLm9jRXofMIKcS3j5jzWazEkuwrSWkfABQ9g=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=KVNUVCXhng00EaJ920Tvs0q2twphNZCSQ9ASVAuEhst+KRNaP9DVlBsl5Hy5tYvRd 5iQbqrn2C7/5qQY9GdtYv8HEBXHZ59qPjNntmZbPU2sJZJfoDKzUIeWNEe2TmEVZmS EACJ8ZLlJNr3o3VGGd1JczA0c2Gk5Tp4C5EabU6p0li5HPIbaQpOWPIxu8tLfO1eqL tpSrl2ndnfZpXgQe6CDQvzptlvJsZXzAN3GekjqnWIu1RzPjnHYDhKsGcsuk/jJRdQ EzEi4F3aVhhtLVuA/CXPYOLeDkjpWewV5HCFCCMr6W6Pj6UQA21gdVXKBeluKUCCV/ CX2ULINCyKL5Q== To: "David S. Miller" , Jakub Kicinski From: Alexander Lobakin Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Alexander Lobakin , Eric Dumazet , Wei Wang , Cong Wang , Taehee Yoo , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Reply-To: Alexander Lobakin Subject: [PATCH net-next 2/4] gro: don't dereference napi->gro_hash[x] multiple times in dev_gro_receive() Message-ID: <20210312162127.239795-3-alobakin@pm.me> In-Reply-To: <20210312162127.239795-1-alobakin@pm.me> References: <20210312162127.239795-1-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 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, struct sk= _buff *skb) { =09u32 bucket =3D skb_get_hash_raw(skb) & (GRO_HASH_BUCKETS - 1); +=09struct gro_list *gro_list =3D &napi->gro_hash[bucket]; =09struct list_head *head =3D &offload_base; =09struct packet_offload *ptype; =09__be16 type =3D skb->protocol; @@ -6024,7 +6025,7 @@ static enum gro_result dev_gro_receive(struct napi_st= ruct *napi, struct sk_buff =09if (pp) { =09=09skb_list_del_init(pp); =09=09napi_gro_complete(napi, pp); -=09=09napi->gro_hash[bucket].count--; +=09=09gro_list->count--; =09} =09if (same_flow) @@ -6033,10 +6034,10 @@ static enum gro_result dev_gro_receive(struct napi_= struct *napi, struct sk_buff =09if (NAPI_GRO_CB(skb)->flush) =09=09goto normal; -=09if (unlikely(napi->gro_hash[bucket].count >=3D MAX_GRO_SKBS)) { +=09if (unlikely(gro_list->count >=3D MAX_GRO_SKBS)) { =09=09gro_flush_oldest(napi, gro_head); =09} else { -=09=09napi->gro_hash[bucket].count++; +=09=09gro_list->count++; =09} =09NAPI_GRO_CB(skb)->count =3D 1; =09NAPI_GRO_CB(skb)->age =3D jiffies; @@ -6050,7 +6051,7 @@ static enum gro_result dev_gro_receive(struct napi_st= ruct *napi, struct sk_buff =09if (grow > 0) =09=09gro_pull_from_frag0(skb, grow); ok: -=09if (napi->gro_hash[bucket].count) { +=09if (gro_list->count) { =09=09if (!test_bit(bucket, &napi->gro_bitmask)) =09=09=09__set_bit(bucket, &napi->gro_bitmask); =09} else if (test_bit(bucket, &napi->gro_bitmask)) { -- 2.30.2