Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp36507pxb; Fri, 15 Jan 2021 07:07:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJwqvLhQ9PXQiuv5VovZGg83mZLYQhn/4W4411srQRye632xt5ijTwWxP37y/jfEbuU/dOqh X-Received: by 2002:a17:906:a951:: with SMTP id hh17mr9601618ejb.388.1610723238041; Fri, 15 Jan 2021 07:07:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610723238; cv=none; d=google.com; s=arc-20160816; b=AhAw5nK1U0BXiOBOvJYKpKW9kduIpmdsVn3Q0Zx7enaTDkjLt29N/KDwI++yB96dZn A01l9EBWdcI2ab6OSR3JPY4yhsEstqyUGoz0jHyjY2P3YHB/N+/dzTLjCDdJxnP5qiqN x3T1w8lo/XHYZV4Q118tgY+jO/I86Hwh1k026aah3KZ5pMxAynXU5tHvptEgS+xXk1sW OPv80jezLN3UFqgFs0ejjEMC5Gi1bgZKfeyMRT/bKlHll6iieDdBWKsXI3fMk5Ilulpw uCdmJdbCrupX67MiLBarz5T1T1Ls5sKMlFYB9E8XPCrlIWOIRfrzYPSkFl9aVgDaOJzK QEdw== 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 :message-id:subject:reply-to:cc:from:to:dkim-signature:date; bh=2oo8j0bPGH6PgdbONPcPCL6akNQMZOzVlG5AWg81tgk=; b=t84U4521xyk1tnjtAn+gOTkWGdyX6C8Cvc2RVeaFBN+vp75uyl/5Qt0NwsBPdTqTUJ TXEFAQDAxM96ahTY1l0xOHoM7WHCGK+K3pbzuhEsEXNiXQgxv1uDhHYmF48rRlM+9nbV cZms0Yhz99rue9OiA3Bl1/sFjhqyNmeyKl38jVaCM1Q0swR5xFFS/ak1NmfMIkxllwks ItfJXl29g47hY4+165HDoVGFYDcvbu4Omj5KKxF8iw/QKeosAIlZwglBZzL9/BGxIQlx GuAeNxOQEQoUS2B75PVGbahdn7oWRR/ifPArtMtffg2a4iMkPrqOZabbUqaNKig+e1nW 1p7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail header.b=OiMHZ41B; 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 d9si4217967edt.564.2021.01.15.07.06.52; Fri, 15 Jan 2021 07:07:18 -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=OiMHZ41B; 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 S1732877AbhAOPFc (ORCPT + 99 others); Fri, 15 Jan 2021 10:05:32 -0500 Received: from mail-40131.protonmail.ch ([185.70.40.131]:33531 "EHLO mail-40131.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728020AbhAOPFb (ORCPT ); Fri, 15 Jan 2021 10:05:31 -0500 Date: Fri, 15 Jan 2021 15:04:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail; t=1610723089; bh=2oo8j0bPGH6PgdbONPcPCL6akNQMZOzVlG5AWg81tgk=; h=Date:To:From:Cc:Reply-To:Subject:From; b=OiMHZ41B2gEwXP7zksVL6ZWiLD7JE9eEaMjy5SRPNRNd+4lAn74xloZaOpVF5BGmy cuus3rCgP739fKqxfgEJFUCP+nIgmukJRktNV7pBt2i57jyb//uRmYUurQT6fGn0Sk oCx079r0SNkM1DezSGILFfLW542kOOimgSNh7ICMwYxev0iHPjmoCZ6zOBhbuy+SHW nKr2ILfUgk7vKYEQktoWQAaQoP7NQfflCI52+m9Z1K8gpxOsJw8dztOhIvneGy/KHI jqBGXKH14jrW34XZzpoPVP3SHKUjvgPNqhIEUA858KNFiD8rxciuWVYoftaty0VSmT rHJh6i5d3Z/dg== To: "David S. Miller" , Jakub Kicinski From: Alexander Lobakin Cc: Willem de Bruijn , Miaohe Lin , Eric Dumazet , Alexander Lobakin , Florian Westphal , Yunsheng Lin , Steffen Klassert , Guillaume Nault , Dongseok Yi , Yadu Kishore , Al Viro , Marco Elver , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Reply-To: Alexander Lobakin Subject: [PATCH v2 net] skbuff: back tiny skbs with kmalloc() in __netdev_alloc_skb() too Message-ID: <20210115150354.85967-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 Commit 3226b158e67c ("net: avoid 32 x truesize under-estimation for tiny skbs") ensured that skbs with data size lower than 1025 bytes will be kmalloc'ed to avoid excessive page cache fragmentation and memory consumption. However, the fix adressed only __napi_alloc_skb() (primarily for virtio_net and napi_get_frags()), but the issue can still be achieved through __netdev_alloc_skb(), which is still used by several drivers. Drivers often allocate a tiny skb for headers and place the rest of the frame to frags (so-called copybreak). Mirror the condition to __netdev_alloc_skb() to handle this case too. Since v1 [0]: - fix "Fixes:" tag; - refine commit message (mention copybreak usecase). [0] https://lore.kernel.org/netdev/20210114235423.232737-1-alobakin@pm.me Fixes: a1c7fff7e18f ("net: netdev_alloc_skb() use build_skb()") Signed-off-by: Alexander Lobakin --- net/core/skbuff.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index c1a6f262636a..785daff48030 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -437,7 +437,11 @@ struct sk_buff *__netdev_alloc_skb(struct net_device *= dev, unsigned int len, =20 =09len +=3D NET_SKB_PAD; =20 -=09if ((len > SKB_WITH_OVERHEAD(PAGE_SIZE)) || +=09/* If requested length is either too small or too big, +=09 * we use kmalloc() for skb->head allocation. +=09 */ +=09if (len <=3D SKB_WITH_OVERHEAD(1024) || +=09 len > SKB_WITH_OVERHEAD(PAGE_SIZE) || =09 (gfp_mask & (__GFP_DIRECT_RECLAIM | GFP_DMA))) { =09=09skb =3D __alloc_skb(len, gfp_mask, SKB_ALLOC_RX, NUMA_NO_NODE); =09=09if (!skb) --=20 2.30.0