Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp361346pxb; Wed, 13 Jan 2021 05:41:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJynh0EOUc5M3tP9L8Dq/sXqGTHlDcUHr6ePEaDynUVpB9eOch22gfp94zrRV/l/0jSjtZEy X-Received: by 2002:a50:cd8c:: with SMTP id p12mr1818999edi.380.1610545304891; Wed, 13 Jan 2021 05:41:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610545304; cv=none; d=google.com; s=arc-20160816; b=IM+DkaIpRjCNONCRAUNTi4RK+6YL79AZ0RuRtGg3ZgPJodqJw+WFF5t5cbQnR4SlIO Hw6vI5datbxNTt9tt7AwPNyIieAuoly2LVKTsmw8KvOrx6Wx8+lCbauhPbZczkXOgkw7 1rUOaDFnqg++nHM5OgDVK+lRv/fcd5S+Tv6fDmxPgFHfQPlo3viLsp5mPY6H4XhjAcbZ lI8DbJoErqeI47rfkpME6xCbJm5uE1c9TfRFqn3KOSA4nth8eS8IpZHYvjwLfSBsEa0s CN1BlI3/CWb4IxXrbzHInYvTBukYoLWmm0J6qtujyk/AXNqxHR63XOaYsgtIf+nSMqvY vscQ== 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=q+0EE369dr2h9X/gAhh7q0i4CdC3yGGoUz33tMS3zRg=; b=xs5okyk0uvOPh/csjRWZEqpTLassOBJ3V/A7CtrhOYBVlAvJ1iHnpO2IP4vxIJlSzn 5vjgjj7B85iLwlOziFKFQmhn5e3Jbwlesgfkvrks+8FYmT/LbfH0mRWAIDkkbgte3Nv4 XcW08MBxU6BPYCTq+LCjddDdmoVxlrLH/e1lYaL3ZqdGGlMO4yecY63wB7W0OWZJ3PYL TFteDvujQmgBSZdX8V4noOCYe9EFzaddrB17DwpMjqpAF70R6Gphv7/UjWWhLVjAdbin rTKbgni9rNf6Sj0t+2H9Ey7GfivlotsQhm67YoJMHDY/BJB6jgxCdSpydkJKECiSZx1H aCiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail header.b=JjOso4hK; 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 no7si907448ejb.586.2021.01.13.05.41.17; Wed, 13 Jan 2021 05:41:44 -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=JjOso4hK; 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 S1726812AbhAMNiP (ORCPT + 99 others); Wed, 13 Jan 2021 08:38:15 -0500 Received: from mail2.protonmail.ch ([185.70.40.22]:57076 "EHLO mail2.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726011AbhAMNiP (ORCPT ); Wed, 13 Jan 2021 08:38:15 -0500 Date: Wed, 13 Jan 2021 13:37:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail; t=1610545052; bh=q+0EE369dr2h9X/gAhh7q0i4CdC3yGGoUz33tMS3zRg=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=JjOso4hKWYW+3zksOpVBtrjglv3v/DlT8/WAyovGt1tf1EJjVeijNX1S/CfhBuD/e OJDuZqLkG/A7KLlO6ow4Y5t7c0Mwi9F6xTiXNIb+NdQ5+VnF5OnUfLOMNmB59HASx3 lPoBCyuexpmXAgFCBSiYWHGv7KgZfXML0y1V0+GYw0GsLJYW4fGc8zuRFwCualGcjE f57n8B9UApeLSxcPtRPTukeI4hk8w4D9Ij3zvAywLUALGvt4Z5jXYfDNwohYX6IjxT 2Rn+3JomIlO+vT//HHaI7z6ilgZCLSh6vKmViO6AKP19vHjclnyJmLIPit+nqi73gN O8oJBJccyVaqQ== To: "David S. Miller" , Jakub Kicinski From: Alexander Lobakin Cc: Eric Dumazet , Edward Cree , Jonathan Lemon , Willem de Bruijn , Miaohe Lin , Alexander Lobakin , Steffen Klassert , Guillaume Nault , Yadu Kishore , Al Viro , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Reply-To: Alexander Lobakin Subject: [PATCH v2 net-next 3/3] skbuff: recycle GRO_MERGED_FREE skbs into NAPI skb cache Message-ID: <20210113133635.39402-3-alobakin@pm.me> In-Reply-To: <20210113133635.39402-1-alobakin@pm.me> References: <20210113133523.39205-1-alobakin@pm.me> <20210113133635.39402-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 Instead of immediate freeing, recycle GRO_MERGED_FREE skbs into NAPI skb cache. This is safe, because napi_gro_receive() and napi_gro_frags() are called only inside NAPI softirq context. As many drivers call napi_alloc_skb()/napi_get_frags() on their receive path, this becomes especially useful. Signed-off-by: Alexander Lobakin --- include/linux/skbuff.h | 1 + net/core/dev.c | 9 +-------- net/core/skbuff.c | 12 +++++++++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 7a057b1f1eb8..507f1598e446 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -2888,6 +2888,7 @@ void napi_consume_skb(struct sk_buff *skb, int budget= ); =20 void __kfree_skb_flush(void); void __kfree_skb_defer(struct sk_buff *skb); +void napi_skb_free_stolen_head(struct sk_buff *skb); =20 /** * __dev_alloc_pages - allocate page for network Rx diff --git a/net/core/dev.c b/net/core/dev.c index e4d77c8abe76..c28f0d601378 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6054,13 +6054,6 @@ struct packet_offload *gro_find_complete_by_type(__b= e16 type) } EXPORT_SYMBOL(gro_find_complete_by_type); =20 -static void napi_skb_free_stolen_head(struct sk_buff *skb) -{ -=09skb_dst_drop(skb); -=09skb_ext_put(skb); -=09kmem_cache_free(skbuff_head_cache, skb); -} - static gro_result_t napi_skb_finish(struct napi_struct *napi, =09=09=09=09 struct sk_buff *skb, =09=09=09=09 gro_result_t ret) @@ -6074,7 +6067,7 @@ static gro_result_t napi_skb_finish(struct napi_struc= t *napi, =09=09if (NAPI_GRO_CB(skb)->free =3D=3D NAPI_GRO_FREE_STOLEN_HEAD) =09=09=09napi_skb_free_stolen_head(skb); =09=09else -=09=09=09__kfree_skb(skb); +=09=09=09__kfree_skb_defer(skb); =09=09break; =20 =09case GRO_HELD: diff --git a/net/core/skbuff.c b/net/core/skbuff.c index f42a3a04b918..bf6f92f1f4c7 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -902,9 +902,6 @@ static void napi_skb_cache_put(struct sk_buff *skb) { =09struct napi_alloc_cache *nc =3D this_cpu_ptr(&napi_alloc_cache); =20 -=09/* drop skb->head and call any destructors for packet */ -=09skb_release_all(skb); - =09nc->skb_cache[nc->skb_count++] =3D skb; =20 =09if (unlikely(nc->skb_count =3D=3D NAPI_SKB_CACHE_SIZE)) { @@ -916,6 +913,14 @@ static void napi_skb_cache_put(struct sk_buff *skb) =20 void __kfree_skb_defer(struct sk_buff *skb) { +=09skb_release_all(skb); +=09napi_skb_cache_put(skb); +} + +void napi_skb_free_stolen_head(struct sk_buff *skb) +{ +=09skb_dst_drop(skb); +=09skb_ext_put(skb); =09napi_skb_cache_put(skb); } =20 @@ -941,6 +946,7 @@ void napi_consume_skb(struct sk_buff *skb, int budget) =09=09return; =09} =20 +=09skb_release_all(skb); =09napi_skb_cache_put(skb); } EXPORT_SYMBOL(napi_consume_skb); --=20 2.30.0