diff mbox series

[net-next,3/3] net: netpoll: flush skb pool during cleanup

Message ID 20241025142025.3558051-4-leitao@debian.org (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: netpoll: Improve SKB pool management | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5 this patch: 5
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 3 this patch: 3
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 No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 5 this patch: 5
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 37 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-10-31--09-00 (tests: 779)

Commit Message

Breno Leitao Oct. 25, 2024, 2:20 p.m. UTC
The netpoll subsystem maintains a pool of 32 pre-allocated SKBs per
instance, but these SKBs are not freed when the netpoll user is brought
down. This leads to memory waste as these buffers remain allocated but
unused.

Add skb_pool_flush() to properly clean up these SKBs when netconsole is
terminated, improving memory efficiency.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 net/core/netpoll.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

Comments

Jakub Kicinski Nov. 1, 2024, 1:29 a.m. UTC | #1
On Fri, 25 Oct 2024 07:20:20 -0700 Breno Leitao wrote:
> +	skb_queue_head_init(&np->skb_pool);

This belongs in the previous patch
Breno Leitao Nov. 1, 2024, 11:57 a.m. UTC | #2
On Thu, Oct 31, 2024 at 06:29:27PM -0700, Jakub Kicinski wrote:
> On Fri, 25 Oct 2024 07:20:20 -0700 Breno Leitao wrote:
> > +	skb_queue_head_init(&np->skb_pool);
> 
> This belongs in the previous patch

Agree. Good catch. I will update.
diff mbox series

Patch

diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index c9a9e37e2d74..bf2064d689d5 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -656,6 +656,7 @@  int __netpoll_setup(struct netpoll *np, struct net_device *ndev)
 
 	/* last thing to do is link it to the net device structure */
 	rcu_assign_pointer(ndev->npinfo, npinfo);
+	skb_queue_head_init(&np->skb_pool);
 
 	return 0;
 
@@ -809,6 +810,22 @@  static void rcu_cleanup_netpoll_info(struct rcu_head *rcu_head)
 	kfree(npinfo);
 }
 
+static void skb_pool_flush(struct netpoll *np)
+{
+	struct sk_buff_head *skb_pool;
+	struct sk_buff *skb;
+	unsigned long flags;
+
+	skb_pool = &np->skb_pool;
+
+	spin_lock_irqsave(&skb_pool->lock, flags);
+	while (skb_pool->qlen > 0) {
+		skb = __skb_dequeue(skb_pool);
+		kfree_skb(skb);
+	}
+	spin_unlock_irqrestore(&skb_pool->lock, flags);
+}
+
 void __netpoll_cleanup(struct netpoll *np)
 {
 	struct netpoll_info *npinfo;
@@ -828,6 +845,8 @@  void __netpoll_cleanup(struct netpoll *np)
 		call_rcu(&npinfo->rcu, rcu_cleanup_netpoll_info);
 	} else
 		RCU_INIT_POINTER(np->dev->npinfo, NULL);
+
+	skb_pool_flush(np);
 }
 EXPORT_SYMBOL_GPL(__netpoll_cleanup);