Skip to contentSkip to conversation

veth: try harder when allocating queue memory

PATCH Applied Jakub Kicinski 3 participants 3 messages Feb 23, 2024 – Feb 27, 2024

Subsystems (2)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 veth: try harder when allocating queue memory

struct veth_rq is pretty large, 832B total without debug options enabled. Since commit under Fixes we try to pre-allocate enough queues for every possible CPU. Miao Wang reports that this may lead to order-5 allocations which will fail in production.

Let the allocation fallback to vmalloc() and try harder. These are the same flags we pass to netdev queue allocation.

Reported-and-tested-by Miao Wang <[email protected]>
Fixes 9d3684c24a52 ("veth: create by default nr_possible_cpus queues")
---
 drivers/net/veth.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/veth.c +3 -2
index a786be805709..cd4a6fe458f9 100644
@@ -1461,7 +1461,8 @@ static int veth_alloc_queues(struct net_device *dev)
 	struct veth_priv *priv = netdev_priv(dev);
 	int i;
 
-	priv->rq = kcalloc(dev->num_rx_queues, sizeof(*priv->rq), GFP_KERNEL_ACCOUNT);
+	priv->rq = kvcalloc(dev->num_rx_queues, sizeof(*priv->rq),
+			    GFP_KERNEL_ACCOUNT | __GFP_RETRY_MAYFAIL);
 	if (!priv->rq)
 		return -ENOMEM;
 
@@ -1477,7 +1478,7 @@ static void veth_free_queues(struct net_device *dev)
 {
 	struct veth_priv *priv = netdev_priv(dev);
 
-	kfree(priv->rq);
+	kvfree(priv->rq);
 }
 
 static int veth_dev_init(struct net_device *dev)
Signature · 1 line
2.43.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Jakub Kicinski

struct veth_rq is pretty large, 832B total without debug options enabled. Since commit under Fixes we try to pre-allocate enough queues for every possible CPU. Miao Wang reports that this may lead to order-5 allocations which will fail in production.

Quoted 7 lines

Let the allocation fallback to vmalloc() and try harder. These are the same flags we pass to netdev queue allocation.

Reported-and-tested-by Miao Wang <[email protected]>
Fixes 9d3684c24a52 ("veth: create by default nr_possible_cpus queues")

This reminds me a change that we should do in netlink_alloc_large_skb(), using kvmalloc() instead of vmalloc().

#2 lore raw
In reply to Jakub Kicinski
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:

Quoted 9 lines · On Fri, 23 Feb 2024 15:59:08 -0800 you wrote:

struct veth_rq is pretty large, 832B total without debug options enabled. Since commit under Fixes we try to pre-allocate enough queues for every possible CPU. Miao Wang reports that this may lead to order-5 allocations which will fail in production.

Let the allocation fallback to vmalloc() and try harder. These are the same flags we pass to netdev queue allocation.

[...]

Here is the summary with links:
- [net] veth: try harder when allocating queue memory

    https://git.kernel.org/netdev/net/c/1ce7d306ea63

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html