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

* Re: [PATCH net] skbuff: back tiny skbs with kmalloc() in __netdev_alloc_skb() too
  2021-01-14 23:54 [PATCH net] skbuff: back tiny skbs with kmalloc() in __netdev_alloc_skb() too Alexander Lobakin
@ 2021-01-15 14:28 ` Eric Dumazet
  2021-01-15 14:34   ` Alexander Lobakin
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Dumazet @ 2021-01-15 14:28 UTC (permalink / raw)
  To: Alexander Lobakin
  Cc: David S. Miller, Jakub Kicinski, Willem de Bruijn, Miaohe Lin,
	Guillaume Nault, Yunsheng Lin, Florian Westphal,
	Steffen Klassert, Dongseok Yi, Yadu Kishore, Al Viro,
	Marco Elver, Alexander Duyck, Michael S. Tsirkin, netdev, LKML

On Fri, Jan 15, 2021 at 12:55 AM Alexander Lobakin <alobakin@pm.me> 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 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 skbs")

No, this tag is wrong, if you fix a bug, bug is much older than linux-5.11

My fix was about GRO head and virtio_net heads, both using pre-sized
small buffers.

You want to fix something else, and this is fine, because some drivers
are unfortunately
doing copy break ( at the cost of additional copy, even for packets
that might be consumed right away)

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

* Re: [PATCH net] skbuff: back tiny skbs with kmalloc() in __netdev_alloc_skb() too
  2021-01-15 14:28 ` Eric Dumazet
@ 2021-01-15 14:34   ` Alexander Lobakin
  0 siblings, 0 replies; 3+ messages in thread
From: Alexander Lobakin @ 2021-01-15 14:34 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Alexander Lobakin, David S. Miller, Jakub Kicinski,
	Willem de Bruijn, Miaohe Lin, Guillaume Nault, Yunsheng Lin,
	Florian Westphal, Steffen Klassert, Dongseok Yi, Yadu Kishore,
	Al Viro, Marco Elver, Alexander Duyck, Michael S. Tsirkin,
	netdev, LKML

From: Eric Dumazet <edumazet@google.com>
Date: Fri, 15 Jan 2021 15:28:37 +0100

> On Fri, Jan 15, 2021 at 12:55 AM Alexander Lobakin <alobakin@pm.me> 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 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 skbs")
>
> No, this tag is wrong, if you fix a bug, bug is much older than linux-5.11
>
> My fix was about GRO head and virtio_net heads, both using pre-sized
> small buffers.
>
> You want to fix something else, and this is fine, because some drivers
> are unfortunately
> doing copy break ( at the cost of additional copy, even for packets
> that might be consumed right away)

You're right, it's about copybreak. I thought about wrong "Fixes"
right after sending, but... Sorry.
Will send v2 soon.

Thanks,
Al


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

end of thread, other threads:[~2021-01-15 14:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-14 23:54 [PATCH net] skbuff: back tiny skbs with kmalloc() in __netdev_alloc_skb() too Alexander Lobakin
2021-01-15 14:28 ` Eric Dumazet
2021-01-15 14:34   ` Alexander Lobakin

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).