netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 net] skbuff: back tiny skbs with kmalloc() in __netdev_alloc_skb() too
@ 2021-01-15 15:04 Alexander Lobakin
  2021-01-17  3:10 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Lobakin @ 2021-01-15 15:04 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski
  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, linux-kernel

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>
---
 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,
 
 	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)
-- 
2.30.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2 net] skbuff: back tiny skbs with kmalloc() in __netdev_alloc_skb() too
  2021-01-15 15:04 [PATCH v2 net] skbuff: back tiny skbs with kmalloc() in __netdev_alloc_skb() too Alexander Lobakin
@ 2021-01-17  3:10 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-01-17  3:10 UTC (permalink / raw)
  To: Alexander Lobakin
  Cc: davem, kuba, willemb, linmiaohe, edumazet, fw, linyunsheng,
	steffen.klassert, gnault, dseok.yi, kyk.segfault, viro, elver,
	netdev, linux-kernel

Hello:

This patch was applied to netdev/net.git (refs/heads/master):

On Fri, 15 Jan 2021 15:04:40 +0000 you wrote:
> 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.
> 
> [...]

Here is the summary with links:
  - [v2,net] skbuff: back tiny skbs with kmalloc() in __netdev_alloc_skb() too
    https://git.kernel.org/netdev/net/c/66c556025d68

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-01-17  3:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-15 15:04 [PATCH v2 net] skbuff: back tiny skbs with kmalloc() in __netdev_alloc_skb() too Alexander Lobakin
2021-01-17  3:10 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).