Skip to content

Commit 6c59f16

Browse files
leitaokuba-moo
authored andcommitted
net: netpoll: flush skb pool during cleanup
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> Link: https://patch.msgid.link/20241114-skb_buffers_v2-v3-2-9be9f52a8b69@debian.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 221a9c1 commit 6c59f16

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

net/core/netpoll.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,14 @@ static int netpoll_parse_ip_addr(const char *str, union inet_addr *addr)
531531
return -1;
532532
}
533533

534+
static void skb_pool_flush(struct netpoll *np)
535+
{
536+
struct sk_buff_head *skb_pool;
537+
538+
skb_pool = &np->skb_pool;
539+
skb_queue_purge_reason(skb_pool, SKB_CONSUMED);
540+
}
541+
534542
int netpoll_parse_options(struct netpoll *np, char *opt)
535543
{
536544
char *cur=opt, *delim;
@@ -779,10 +787,12 @@ int netpoll_setup(struct netpoll *np)
779787

780788
err = __netpoll_setup(np, ndev);
781789
if (err)
782-
goto put;
790+
goto flush;
783791
rtnl_unlock();
784792
return 0;
785793

794+
flush:
795+
skb_pool_flush(np);
786796
put:
787797
DEBUG_NET_WARN_ON_ONCE(np->dev);
788798
if (ip_overwritten)
@@ -830,6 +840,8 @@ void __netpoll_cleanup(struct netpoll *np)
830840
call_rcu(&npinfo->rcu, rcu_cleanup_netpoll_info);
831841
} else
832842
RCU_INIT_POINTER(np->dev->npinfo, NULL);
843+
844+
skb_pool_flush(np);
833845
}
834846
EXPORT_SYMBOL_GPL(__netpoll_cleanup);
835847

0 commit comments

Comments
 (0)