From patchwork Wed Jan 13 13:36:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 12016817 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=unavailable 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 F33A6C433E0 for ; Wed, 13 Jan 2021 13:38:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A5541233FB for ; Wed, 13 Jan 2021 13:38:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726674AbhAMNhp (ORCPT ); Wed, 13 Jan 2021 08:37:45 -0500 Received: from mail-40134.protonmail.ch ([185.70.40.134]:34210 "EHLO mail-40134.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725770AbhAMNho (ORCPT ); Wed, 13 Jan 2021 08:37:44 -0500 Date: Wed, 13 Jan 2021 13:36:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail; t=1610545022; bh=Wxlzuo0a4dl7vh+BrgTHx6uBHCVOGXVNozBxr9mFN2Q=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=Wx4+MmnLUv7niL6jpu4x8NgcUVxpCedUpf2G7Die60hRiBHBYW7TJZc6f49knbxc7 j+T8zI+kcDE+xNf163xH0m8LL7M8jLY1PQR6Q/WPuBa4rNUS4U4Ir+LfMU0RxiSiix IvHCcTXLujUw+fgn7WH+hCVLrVPfdl3kxRT1fU1J39JKUUZ1GHozTITOJEzDdPfyQ2 xRwNhQB74LcBdu//REEbDKZ0MQvy7RJ6RHTzDNHdkha8UbkMN9u2YyBo/2xZkXmEFN 3TYZLFyVPZCGDTccc7djvGnngSiuMgUGadbFBaAWVfLUAX5hMcfkZHEspa+oO83v5n Dvur77vAI5Ykw== 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 1/3] skbuff: open-code __build_skb() inside __napi_alloc_skb() Message-ID: <20210113133635.39402-1-alobakin@pm.me> In-Reply-To: <20210113133523.39205-1-alobakin@pm.me> References: <20210113133523.39205-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 7626a33cce59..dc3300dc2ac4 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_skb_cache_get(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_skb_cache_get(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;