diff mbox series

[net] veth: try harder when allocating queue memory

Message ID 20240223235908.693010-1-kuba@kernel.org (mailing list archive)
State Accepted
Commit 1ce7d306ea63f3e379557c79abd88052e0483813
Delegated to: Netdev Maintainers
Headers show
Series [net] veth: try harder when allocating queue memory | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 956 this patch: 956
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/build_clang success Errors and warnings before: 973 this patch: 973
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 973 this patch: 973
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 17 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-02-25--03-00 (tests: 1457)

Commit Message

Jakub Kicinski Feb. 23, 2024, 11:59 p.m. UTC
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 <shankerwangmiao@gmail.com>
Fixes: 9d3684c24a52 ("veth: create by default nr_possible_cpus queues")
Link: https://lore.kernel.org/all/5F52CAE2-2FB7-4712-95F1-3312FBBFA8DD@gmail.com/
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 drivers/net/veth.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Eric Dumazet Feb. 24, 2024, 8:25 a.m. UTC | #1
On Sat, Feb 24, 2024 at 12:59 AM Jakub Kicinski <kuba@kernel.org> 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.
>
> Reported-and-tested-by: Miao Wang <shankerwangmiao@gmail.com>
> Fixes: 9d3684c24a52 ("veth: create by default nr_possible_cpus queues")
> Link: https://lore.kernel.org/all/5F52CAE2-2FB7-4712-95F1-3312FBBFA8DD@gmail.com/
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>

Reviewed-by: Eric Dumazet <edumazet@google.com>

This reminds me a change that we should do in
netlink_alloc_large_skb(), using kvmalloc() instead of vmalloc().
patchwork-bot+netdevbpf@kernel.org Feb. 27, 2024, 2:20 p.m. UTC | #2
Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:

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!
diff mbox series

Patch

diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index a786be805709..cd4a6fe458f9 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -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)