Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2646818pxb; Thu, 11 Feb 2021 19:21:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJwr8I4V+XgScPqV5uCvfhz5bbXZSvapk6gUJWVQb7T5Bo/jH/7SZYGsHTaEtr9vg1SO7yht X-Received: by 2002:a05:6402:104e:: with SMTP id e14mr1281005edu.316.1613100111259; Thu, 11 Feb 2021 19:21:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613100111; cv=none; d=google.com; s=arc-20160816; b=mzQHNcN9qmC8812u9tbauyKgs1tylDC513guc5I5UxpSyo+DlgKqmGS0qf0GLAJ0zp S14AawMuaMcK/T23liG/7BCn4QjoAIZcEhiGL+yjcSeUPK9/IzjkLjqvXUqTjmqTwQ7M eK/cwN8s20sSOW8VWlOqVoVPh0EhlbHqlPQ2gQTl8q6XYoYyIJ9D6r47sJ2zXNutQ8ld OHsYseRf7xYGAr2THfc37QdPaxt4jf64JdN/YNzGMNDrPcNOtlbre97DfJDo7I8B5aB9 G3rEnc6riapKZFTy4Ah2zDcFx5lb0nv+wzrNePrwdSMwyyR9iQbrHW/eL9hRA9tD8zJ9 lx/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=gC9STVbE2ob8taGqJ2B3Q5LeUbYPwP+eNdSIa6spCUM=; b=vRlstz4/KCuM3FQZNhWoSZfgHPKobjQajWsyFsADNeJdSeaYRxWW7/rvno/btBM8GD UsZi84CRk1QTVT7S9eympTV1gOzMSOjl1sM2Vqms8IA2zxDtZEwOd+lqSPmLVuauRbBc 4QjcViV/57tvCAmkqMZZf98qzr9gQgm+dj5ypxA9Xy/rn1xPQVogr0TJSAWmzg96Ym8s as1Hn1mvQ+uDzMd66o06F8bbk0BpsDVXZttE/CVjs+gPjtjAUKSEPyw5191fuADu3vuf sRD2cIvd5M8TOfMN7HYI98CGRSFbnBdHTMoYHFO01lnUl5rC5q4FtheBJwVpg/cwuPRU wheQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZEzsEWpP; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y9si5079558edm.453.2021.02.11.19.21.28; Thu, 11 Feb 2021 19:21:51 -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=@gmail.com header.s=20161025 header.b=ZEzsEWpP; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229608AbhBLDTi (ORCPT + 99 others); Thu, 11 Feb 2021 22:19:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229457AbhBLDTh (ORCPT ); Thu, 11 Feb 2021 22:19:37 -0500 Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47D48C061574; Thu, 11 Feb 2021 19:18:57 -0800 (PST) Received: by mail-io1-xd30.google.com with SMTP id e133so7938646iof.8; Thu, 11 Feb 2021 19:18:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=gC9STVbE2ob8taGqJ2B3Q5LeUbYPwP+eNdSIa6spCUM=; b=ZEzsEWpPR2rbQ/c2UL8vEy2CL3CFEoUUQbesWOu8YYUGQq6GxgsJNHxxC8xsHeoaoO SjGIH6pSEGa4AurfM3zAoRjBViezGTJkyGYCQRaGYW0jAcJsRJ0q76H8EFddgGxlH6wQ MnsP+7rYdacYXQi3PWDpFbd2RW9qV1tLvUn4WNy+pldFW6fEUt9eMX8XtnwFBEPaw+2y xE69CwXIe1e7bp16lZQWA9ETxUx8ZV8/++SYpsjcobmpuMtliwnDm+q9wQ5y7Z8gmWBf /ZnVSeLs8wRvS1iQ7Z5p4AiBn2Jc4Oizte1PLsQ+hB8Ccx94dA571Ze6uH/XuGuiyUmX oDJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=gC9STVbE2ob8taGqJ2B3Q5LeUbYPwP+eNdSIa6spCUM=; b=ECnRNuq4/zHU0nVyM7nmWIBmTWO2s+ORwgpgJTjTq6yXRTyVhVWA3Kio26DXWinOpN FC0RUU/MATHzUSpNBJwYT9rmF+liOgG59C2llKyZdegUbiAwP/psgbHDV5jxUsXgFStJ rDojx00rLVBGBAlKMPRHDB5q/aul+xONdOwsU9DG4vQQTKg5C0d0kl00VGxurcOgB3wm /TqXOFlwuloHqimyjsuRHrLxDjXMNkESUwZqOsdAgSc36x3UrytFa6k73gy5Wcnnontt HFhBXH0TFxz5tEKLDXSMzlA8m7SPATz2J5NumVyBVb+8vthAFwYFxPpXLE3JBOlZVDAn 46LA== X-Gm-Message-State: AOAM530ZMgGrksLzuRkzK7HjZyqbEjOdz58wSepcdm1yHr3GZO64gyvl cymqnu4yYRiL8acRTc3vDCiWLOuBs95H+JTIA8s= X-Received: by 2002:a05:6638:11a:: with SMTP id x26mr858514jao.121.1613099936449; Thu, 11 Feb 2021 19:18:56 -0800 (PST) MIME-Version: 1.0 References: <20210211185220.9753-1-alobakin@pm.me> <20210211185220.9753-10-alobakin@pm.me> In-Reply-To: <20210211185220.9753-10-alobakin@pm.me> From: Alexander Duyck Date: Thu, 11 Feb 2021 19:18:45 -0800 Message-ID: Subject: Re: [PATCH v5 net-next 09/11] skbuff: allow to optionally use NAPI cache from __alloc_skb() To: Alexander Lobakin Cc: "David S. Miller" , Jakub Kicinski , Jonathan Lemon , Eric Dumazet , Dmitry Vyukov , Willem de Bruijn , 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?B?QmrDtnJuIFTDtnBlbA==?= , Miaohe Lin , Guillaume Nault , Yonghong Song , zhudi , Michal Kubecek , Marcelo Ricardo Leitner , Dmitry Safonov <0x7f454c46@gmail.com>, Yang Yingliang , Florian Westphal , Edward Cree , LKML , Netdev Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 11, 2021 at 11:00 AM Alexander Lobakin wrote: > > 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, > struct sk_buff *skb; > u8 *data; > bool pfmemalloc; > + bool clone; > > - cache = (flags & SKB_ALLOC_FCLONE) > - ? skbuff_fclone_cache : skbuff_head_cache; > + clone = !!(flags & SKB_ALLOC_FCLONE); The boolean conversion here is probably unnecessary. I would make clone an int like flags and work with that. I suspect the compiler is doing it already, but it is better to be explicit. > + cache = clone ? skbuff_fclone_cache : skbuff_head_cache; > > if (sk_memalloc_socks() && (flags & SKB_ALLOC_RX)) > gfp_mask |= __GFP_MEMALLOC; > > /* Get the HEAD */ > - skb = kmem_cache_alloc_node(cache, gfp_mask & ~__GFP_DMA, node); > + if ((flags & SKB_ALLOC_NAPI) && !clone && Rather than having to do two checks you could just check for SKB_ALLOC_NAPI and SKB_ALLOC_FCLONE in a single check. You could just do something like: if ((flags & (SKB_ALLOC_FCLONE | SKB_ALLOC_NAPI) == SKB_ALLOC_NAPI) That way you can avoid the extra conditional jumps and can start computing the flags value sooner. > + likely(node == NUMA_NO_NODE || node == numa_mem_id())) > + skb = napi_skb_cache_get(); > + else > + skb = kmem_cache_alloc_node(cache, gfp_mask & ~GFP_DMA, node); > if (unlikely(!skb)) > return NULL; > prefetchw(skb); > @@ -436,7 +441,7 @@ struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask, > __build_skb_around(skb, data, 0); > skb->pfmemalloc = pfmemalloc; > > - if (flags & SKB_ALLOC_FCLONE) { > + if (clone) { > struct sk_buff_fclones *fclones; > > fclones = container_of(skb, struct sk_buff_fclones, skb1); > -- > 2.30.1 > >