summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Lobakin <alobakin@pm.me>2021-01-15 15:04:40 +0000
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2021-01-30 13:25:57 +0100
commitc29efd706d7c2b7c85c86ddf05b999b0ee8cda1d (patch)
tree3817fdfd661edbdd0e3e530d162ad9976c2642aa
parent17663f1a2fcfa47f82bba8363496733f065c3401 (diff)
downloadlinux-stable-c29efd706d7c2b7c85c86ddf05b999b0ee8cda1d.tar.gz
linux-stable-c29efd706d7c2b7c85c86ddf05b999b0ee8cda1d.tar.bz2
linux-stable-c29efd706d7c2b7c85c86ddf05b999b0ee8cda1d.zip
skbuff: back tiny skbs with kmalloc() in __netdev_alloc_skb() too
commit 66c556025d687dbdd0f748c5e1df89c977b6c02a upstream. 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 <alobakin@pm.me> Link: https://lore.kernel.org/r/20210115150354.85967-1-alobakin@pm.me Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--net/core/skbuff.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 011c2cf4d041..171f81ce81d0 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -419,7 +419,11 @@ struct sk_buff *__netdev_alloc_skb(struct net_device *dev, unsigned int len,
len += NET_SKB_PAD;
- if ((len > SKB_WITH_OVERHEAD(PAGE_SIZE)) ||
+ /* If requested length is either too small or too big,
+ * we use kmalloc() for skb->head allocation.
+ */
+ if (len <= SKB_WITH_OVERHEAD(1024) ||
+ len > SKB_WITH_OVERHEAD(PAGE_SIZE) ||
(gfp_mask & (__GFP_DIRECT_RECLAIM | GFP_DMA))) {
skb = __alloc_skb(len, gfp_mask, SKB_ALLOC_RX, NUMA_NO_NODE);
if (!skb)