Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp911644pxb; Tue, 9 Feb 2021 16:26:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJxIFJY5qTHSJfxs3O99KqhqxYiTqAatpIjm7sfVYIWRUL6fCU4uefGWrjwayo+kWIPd5l9X X-Received: by 2002:a17:906:27d8:: with SMTP id k24mr263852ejc.339.1612916767444; Tue, 09 Feb 2021 16:26:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612916767; cv=none; d=google.com; s=arc-20160816; b=y1KDP43wAxe06N6gC5pCBjl3tQO9T9DBt4XcGMybbfGW9C8JmGgUlJcEJ2Uqiefnd8 iJJ5ldwvzLNZLxmwjoxbjM0VpO1gvD7F7MRsH2jWVB5CKiFHY4fVE/FZuuTUQVt+U+rZ x4N0KDitQ7JGTKdlgCbNHcsuMHxJausFUNqQk04wSPWIFN1XB0c1KYm5nzexmaotngzA IkUQT9cOvLpxI8Drz1a8G/YDA4601oaqpi4PKcJ8Zw33O6KVC9MEzYEQaoB++ZniWLUg hNrHKKNAy6qP8ZCXFh940yzfDHtm3JQx/L1mP2/s2CzKMExTD2ydXF1deANNX3HG306s j87A== 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=CJXPkGdmY5RiFBPMnrBdmPj6J9CQqoGZFly0kXKbtyw=; b=0Hn7JzZVamct3XsOFYyQ4zpXNIB/unR8YDGDx1LWHZWQ7dZp2m/po2nQas06VDNQ/S Mqa2pzZjK3vRBdqO645YZJYDaI2fxBGhUfVPPH3hnVO5sYeBmZnziHu4Wqcerlnac+vF XKZG/Lvi1lpOA3FwhR2OQU3ydT3o1v4l0m4v3wWjQbfEQZg27Wi+zkJx0RbrUkgbqPKC ONIxlnbJMn/9RQTXU7SrsPXeuaOAwLpgEqmsDTc0BCh9WNQaeMso2uqhxkH2mk0Td82Q 9TI8IzOkxKldQuefAh9Im2q3+uWf+edYaf3gt7y2n48RQCJaHHal0ts6VtUTtvSmMP3i /yeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail header.b=LBBLa5jH; 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 ji20si161936ejc.719.2021.02.09.16.25.44; Tue, 09 Feb 2021 16:26:07 -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=LBBLa5jH; 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 S234814AbhBJAXn (ORCPT + 99 others); Tue, 9 Feb 2021 19:23:43 -0500 Received: from mail-40133.protonmail.ch ([185.70.40.133]:56060 "EHLO mail-40133.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233861AbhBIUuF (ORCPT ); Tue, 9 Feb 2021 15:50:05 -0500 Date: Tue, 09 Feb 2021 20:49:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail; t=1612903762; bh=CJXPkGdmY5RiFBPMnrBdmPj6J9CQqoGZFly0kXKbtyw=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=LBBLa5jHOXunOIAbx1jOTy6WCs9mzG8gehuj6+j9+Ssi6RHGUbkSBOywMviBEwCQu lda9a7LCxOO7zb5vCmPtWdQZgRedj4QRYcs0q7fq1MpyHfK2kbnNc2y3/wKF+gP0SN 0mOUjWozbuoWUmtEYhXVKu+iqba5NkBBowwTil2osat0R/LaHA6hQHZ9AbSQtnLa5Z wulmrHPn2qAn8TKsxIwF4jcuwmiwnMJinduz+ihs8vbj4VH02CdFsEaWNf7ejHVprp rzzYXuB3ZA0scy0lRt0M08SlYRNW1MM2XPkdJV0RTCt9F5fQCXSe8A4/kgvOLWWpNn rXq8yG7HImKTw== 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 , 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 , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Reply-To: Alexander Lobakin Subject: [v3 net-next 09/10] skbuff: reuse NAPI skb cache on allocation path (__alloc_skb()) Message-ID: <20210209204533.327360-10-alobakin@pm.me> In-Reply-To: <20210209204533.327360-1-alobakin@pm.me> References: <20210209204533.327360-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 Try to use the same technique for obtaining skbuff_head from NAPI cache in {,__}alloc_skb(). Two points here: - __alloc_skb() can be used for allocating clones or allocating skbs for distant nodes. Try to grab head from the cache only for non-clones and for local nodes; - can be called from any context, so napi_safe =3D=3D false. Signed-off-by: Alexander Lobakin --- net/core/skbuff.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 8747566a8136..8850086f8605 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -354,15 +354,19 @@ 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 (clone || unlikely(node !=3D NUMA_NO_NODE && node !=3D numa_mem_id()= )) +=09=09skb =3D kmem_cache_alloc_node(cache, gfp_mask & ~GFP_DMA, node); +=09else +=09=09skb =3D napi_skb_cache_get(false); =09if (unlikely(!skb)) =09=09return NULL; =09prefetchw(skb); @@ -393,7 +397,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.0