From patchwork Mon Jan 11 18:28:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 12011379 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08929C433E6 for ; Mon, 11 Jan 2021 18:29:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B3FBC2222F for ; Mon, 11 Jan 2021 18:29:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390495AbhAKS3c (ORCPT ); Mon, 11 Jan 2021 13:29:32 -0500 Received: from mail2.protonmail.ch ([185.70.40.22]:28794 "EHLO mail2.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726668AbhAKS3b (ORCPT ); Mon, 11 Jan 2021 13:29:31 -0500 Date: Mon, 11 Jan 2021 18:28:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail; t=1610389728; bh=wgAyaFE6+C7VTIm9g+ku7OzpbV9LwSqwPAVdcpq7pZ8=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=AhjGxmKQHyvF2E4xiqqIqCFUsuLzpVSXaHzJEzzRAa58Jh4jWuPX31RmZrVuRqCkt l0mN5G7wsjERejFECaBZOIQqkw0vIlB4cGIuOoCJ4mlnSDUfcEJ3FLlhsL581K+KQz d8bKmziPh85KIOGiDBwm5/xKmG0mNBaY0ISJr1eWF3EYC9ibKJ+0mN3KOpAZdOKJZ6 YYEIfyk5KE6gRqpD1RIkBzY80e9f1uS2QUI8MBHYimYpYU+omq1YiryVZZdyCGBSyp w16VtEW4hCyc977oeRFIiKodw+mdH6PP0sLrW4UnSmxPW92pe54bGS7nlkWoPnk278 8zmPQD8injf5w== 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 net-next 2/5] skbuff: open-code __build_skb() inside __napi_alloc_skb() Message-ID: <20210111182801.12609-2-alobakin@pm.me> In-Reply-To: <20210111182801.12609-1-alobakin@pm.me> References: <20210111182655.12159-1-alobakin@pm.me> <20210111182801.12609-1-alobakin@pm.me> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org In preparation for skbuff_heads caching and reusing, open-code __build_skb() inside __napi_alloc_skb() with factoring out the skbbuff_head allocation itself. Note that the return value of __build_skb_around() is not checked since it never returns anything except the given skb. Signed-off-by: Alexander Lobakin --- net/core/skbuff.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 17ae5e90f103..3c904c29efbb 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -485,6 +485,11 @@ struct sk_buff *__netdev_alloc_skb(struct net_device *dev, unsigned int len, } EXPORT_SYMBOL(__netdev_alloc_skb); +static struct sk_buff *__napi_decache_skb(struct napi_alloc_cache *nc) +{ + return kmem_cache_alloc(skbuff_head_cache, GFP_ATOMIC); +} + /** * __napi_alloc_skb - allocate skbuff for rx in a specific NAPI instance * @napi: napi instance this buffer was allocated for @@ -525,12 +530,15 @@ struct sk_buff *__napi_alloc_skb(struct napi_struct *napi, unsigned int len, if (unlikely(!data)) return NULL; - skb = __build_skb(data, len); + skb = __napi_decache_skb(nc); if (unlikely(!skb)) { skb_free_frag(data); return NULL; } + memset(skb, 0, offsetof(struct sk_buff, tail)); + __build_skb_around(skb, data, len); + if (nc->page.pfmemalloc) skb->pfmemalloc = 1; skb->head_frag = 1;