Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp668982pxb; Thu, 14 Jan 2021 15:58:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJyuqzBegS6t3p+Yzi8kfpGJly0IMoJSwmX/UipKBYfwY8fwd7QtX6oPl1mnANb+Haptohmo X-Received: by 2002:a17:907:7255:: with SMTP id ds21mr6842557ejc.258.1610668683621; Thu, 14 Jan 2021 15:58:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610668683; cv=none; d=google.com; s=arc-20160816; b=yntmhXWUYGf/ye5T+SCXr2ooDvQZdBO6P0/tN3Roe2MPUlbip68nNlFE/7f3JZGWGe IgxrYkEel5q0ke7JmH0QIF590jjFip12TSbMXKkKekYxL5MKyLX4GOGMfEctT5DjxbwT arSGzCsRBkeMOxBwjZSb2mRD6UTjMpVyFon1WRUVtfZvwK9KdIeExOjqaJmHUgu294+S E4GHCeEsZpdNZSbsGAnOM9d0dvUE5xmJdhD8nvb9MzrulZfjO/BjwJCnW6HR09Ez0wMe piNNn/DAIiof0i2QZsNbTKWUTbfFWKN9qWXis2IWCf034jBsjjGSsJVJ8nr8LKzeL/ig Ipow== 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=fkj15JFInAacwkcXWADIVGKRGYKKKaLvXr53v7A5jGA=; b=uD2ZJziAk5LhSEI6GPXFtL/X1CetEyng6xHsXHwihQ28Tw5bYGNmipf8k+OOk/BYKB I7jnGemBj0E+p76vuqLE1prVGMLBPIOWj6TdrLuxz9vKLxmFPZaKZ5MT/c5SqrwK6/6o KbKy55njlMotUh0kpkP8W3L2Nrh/FlKJjky4WaD77dTu4jrfWajztb7q+wxUfI7RPxe6 XwlBmf0SCvf359Tu+M67YH9oDJmLg5XRuTThRhnJ3xUn+rAvPUzkp4xT8t+tXzgkqLbk PcsAn8x5Trow/v5zbGcc47PdPWkXSKDj8974prOKp1D699EFLH8MS8Skqlsk3+xtJ5mA Rwjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail header.b=AxpLtlAd; 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 v17si3039519eds.561.2021.01.14.15.57.33; Thu, 14 Jan 2021 15:58:03 -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=AxpLtlAd; 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 S1731063AbhANXzq (ORCPT + 99 others); Thu, 14 Jan 2021 18:55:46 -0500 Received: from mail-40134.protonmail.ch ([185.70.40.134]:35906 "EHLO mail-40134.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728545AbhANXzq (ORCPT ); Thu, 14 Jan 2021 18:55:46 -0500 Date: Thu, 14 Jan 2021 23:54:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail; t=1610668503; bh=fkj15JFInAacwkcXWADIVGKRGYKKKaLvXr53v7A5jGA=; h=Date:To:From:Cc:Reply-To:Subject:From; b=AxpLtlAd9rxvfz1UeO9vM5UmufvzQ2aYxgRQVfTNt0hZaAwHMemLnVvS7bSZQDhaG bQeSbycH5J9BL7Q8gB/CkH7fXTHdcme+sT/OScqfEKwqscsnaANhcLkz8LVD/mLFGr GUsvJ5KCAx667B/64+HcbI1Mqh9FD0jKFPbobNeBV0ttXRZ6zdl7dSN7HlvwyVPpuF esE9drroF13bRyzZdjpuiHpUFNGmT43nWD4c0cgEr5TuKvjWupcaS1o/l/n/ExAvH0 T7Dv5zgBx7bAO0wZAcs4HN+6kNyKGzI++b4ahBGwMphGWO/gcQXlT2iYzqWtxB4v0K Hu8JBdt2YjXFw== To: "David S. Miller" , Jakub Kicinski From: Alexander Lobakin Cc: Willem de Bruijn , Miaohe Lin , Eric Dumazet , Alexander Lobakin , Guillaume Nault , Yunsheng Lin , Florian Westphal , Steffen Klassert , Dongseok Yi , Yadu Kishore , Al Viro , Marco Elver , Alexander Duyck , "Michael S. Tsirkin" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Reply-To: Alexander Lobakin Subject: [PATCH net] skbuff: back tiny skbs with kmalloc() in __netdev_alloc_skb() too Message-ID: <20210114235423.232737-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 same issue can still be achieved manually via __netdev_alloc_skb(), where the check for size hasn't been changed. Mirror the condition from __napi_alloc_skb() to prevent from that. Fixes: 3226b158e67c ("net: avoid 32 x truesize under-estimation for tiny sk= bs") 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