Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2387180pxb; Thu, 11 Feb 2021 11:01:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJzBdUwgGSXcxp+NO9vQRQoqi6g2AviZSUx7B6Qyp8zoPfIz7KXBrkuixZO7iuNBZ/gj6ppI X-Received: by 2002:a05:6402:d09:: with SMTP id eb9mr9792011edb.285.1613070074913; Thu, 11 Feb 2021 11:01:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613070074; cv=none; d=google.com; s=arc-20160816; b=hUgy2TIyMbVuB29Rk0+HosR0504EqSr4wydvWuKA6P5YPEqr2U0jBDzAEhEf/cjOC7 pjMuikbFVH8YJdT+qxwJ3tzJ1OYiigKPJTq+9iAWAEv5JjqD26sqyw42IL85MU2jIMtA 4PsqFyYyuuu877Swbqaf/Yn4/HqnWMNdTHua8O0Ak5tdlauNle3kXo1IFls8Z3WBe3La vs/GbwM2Jh2sP96+lnKu8ENsrArcqFb5/pNlFK6A27dU/lz8G6VMnbv9CUQmCZsAOp3i Iiio4gb962wUWH5RUPvPn49CPQru5l6e1dCJnG5xHEvVOHaXZxSJ7vBvgz1QWSrEjZfi F3yg== 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=qPQcxPN1Q43SY2WoV1Q6WuT37zpt1UbANMJCgrZmA8M=; b=j4qg6SmNYXooClDGaNp6mQY+rdzMUjzzrWI76s5H166Va+DFx3S4cjTafY3M9rKgPe XNyKeY2ssGBnI/s5gtaF9EV3DWryfU+jSQ1yLVtZEnHMOx2JmzWR+XmxF/FvE6TLdq5s QoZzVAoj+CjHqMbA3WGw+fr1i84Gnw60Avh7+ptACDLy0nUwryL8sU75nrfoTx2fH+YL FAwAusAcs+M3xGZWxHy37Moq2YIf15RB28C6IWsck9XMhS2EEtVBC3CCTgR4OMokri5A p4htWPsh5j7YsnqpcgIDX2T/G6eTwOCJlO1gpgxjTf6M6xT4SG2XE8kWm95KnWv5N67L LyVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail header.b=mFZGK9Dq; 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 j16si4059176ejm.573.2021.02.11.11.00.48; Thu, 11 Feb 2021 11:01:14 -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=mFZGK9Dq; 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 S229700AbhBKS7t (ORCPT + 99 others); Thu, 11 Feb 2021 13:59:49 -0500 Received: from mail2.protonmail.ch ([185.70.40.22]:55819 "EHLO mail2.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229918AbhBKSzr (ORCPT ); Thu, 11 Feb 2021 13:55:47 -0500 Date: Thu, 11 Feb 2021 18:54:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail; t=1613069704; bh=qPQcxPN1Q43SY2WoV1Q6WuT37zpt1UbANMJCgrZmA8M=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=mFZGK9DqkMzDxBvGEhde2DTkEr1oebfk3zuZk4wy9nGQJ++vDr2MfT//zJDpO2fIg kyHcmbdskJfgW9hvxcIhVMyYgZRfJajM+cdnHzUPUgn+cymioddjITy8K+CTMhMh/p dBAzoess7TsA7HtxsqT2+JxrNgdihQo80CAvN4uSHWUScuvQfrrJSY2nPq5wQMMEyY EbIQ70RouwDCrNjdMm+kfINatpt8bA2h5n53pgjGK+StIUD4fRaLtcOJZdzFB+FZjf FkdhqYk8A7VYS0T3j1Il0LgrfEDnIS2zayx1gunpuplpXkTyXEy+F5nLPwBhlqVpfa NrwADqks2dBOg== To: "David S. Miller" , Jakub Kicinski From: Alexander Lobakin Cc: Jonathan Lemon , Eric Dumazet , Dmitry Vyukov , Willem de Bruijn , Alexander Lobakin , Randy Dunlap , Kevin Hao , Pablo Neira Ayuso , Jakub Sitnicki , Marco Elver , Dexuan Cui , Paolo Abeni , Jesper Dangaard Brouer , Alexander Duyck , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Taehee Yoo , Cong Wang , =?utf-8?Q?Bj=C3=B6rn_T=C3=B6pel?= , Miaohe Lin , Guillaume Nault , Yonghong Song , zhudi , Michal Kubecek , Marcelo Ricardo Leitner , Dmitry Safonov <0x7f454c46@gmail.com>, Yang Yingliang , Florian Westphal , Edward Cree , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Reply-To: Alexander Lobakin Subject: [PATCH v5 net-next 09/11] skbuff: allow to optionally use NAPI cache from __alloc_skb() Message-ID: <20210211185220.9753-10-alobakin@pm.me> In-Reply-To: <20210211185220.9753-1-alobakin@pm.me> References: <20210211185220.9753-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 Reuse the old and forgotten SKB_ALLOC_NAPI to add an option to get an skbuff_head from the NAPI cache instead of inplace allocation inside __alloc_skb(). This implies that the function is called from softirq or BH-off context, not for allocating a clone or from a distant node. Signed-off-by: Alexander Lobakin --- net/core/skbuff.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 9e1a8ded4acc..a0b457ae87c2 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -397,15 +397,20 @@ struct sk_buff *__alloc_skb(unsigned int size, gfp_t = gfp_mask, =09struct sk_buff *skb; =09u8 *data; =09bool pfmemalloc; +=09bool clone; =20 -=09cache =3D (flags & SKB_ALLOC_FCLONE) -=09=09? skbuff_fclone_cache : skbuff_head_cache; +=09clone =3D !!(flags & SKB_ALLOC_FCLONE); +=09cache =3D clone ? skbuff_fclone_cache : skbuff_head_cache; =20 =09if (sk_memalloc_socks() && (flags & SKB_ALLOC_RX)) =09=09gfp_mask |=3D __GFP_MEMALLOC; =20 =09/* Get the HEAD */ -=09skb =3D kmem_cache_alloc_node(cache, gfp_mask & ~__GFP_DMA, node); +=09if ((flags & SKB_ALLOC_NAPI) && !clone && +=09 likely(node =3D=3D NUMA_NO_NODE || node =3D=3D numa_mem_id())) +=09=09skb =3D napi_skb_cache_get(); +=09else +=09=09skb =3D kmem_cache_alloc_node(cache, gfp_mask & ~GFP_DMA, node); =09if (unlikely(!skb)) =09=09return NULL; =09prefetchw(skb); @@ -436,7 +441,7 @@ struct sk_buff *__alloc_skb(unsigned int size, gfp_t gf= p_mask, =09__build_skb_around(skb, data, 0); =09skb->pfmemalloc =3D pfmemalloc; =20 -=09if (flags & SKB_ALLOC_FCLONE) { +=09if (clone) { =09=09struct sk_buff_fclones *fclones; =20 =09=09fclones =3D container_of(skb, struct sk_buff_fclones, skb1); --=20 2.30.1