Skip to content

Commit 237c6c0

Browse files
leitaoopsiff
authored andcommitted
net: netpoll: flush skb pool during cleanup
[ Upstream commit 6c59f16 ] 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 <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Stable-dep-of: 49c8d2c ("net: netpoll: fix incorrect refcount handling causing incorrect cleanup") Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit f3c824361452fef1f810592bce33e4f64c48e377) Signed-off-by: Wentao Guan <[email protected]>
1 parent 4adb465 commit 237c6c0

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

net/core/netpoll.c

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

539+
static void skb_pool_flush(struct netpoll *np)
540+
{
541+
struct sk_buff_head *skb_pool;
542+
543+
skb_pool = &np->skb_pool;
544+
skb_queue_purge_reason(skb_pool, SKB_CONSUMED);
545+
}
546+
539547
int netpoll_parse_options(struct netpoll *np, char *opt)
540548
{
541549
char *cur=opt, *delim;
@@ -784,7 +792,7 @@ int netpoll_setup(struct netpoll *np)
784792

785793
err = __netpoll_setup(np, ndev);
786794
if (err)
787-
goto put;
795+
goto flush;
788796
rtnl_unlock();
789797

790798
/* Make sure all NAPI polls which started before dev->npinfo
@@ -795,6 +803,8 @@ int netpoll_setup(struct netpoll *np)
795803

796804
return 0;
797805

806+
flush:
807+
skb_pool_flush(np);
798808
put:
799809
DEBUG_NET_WARN_ON_ONCE(np->dev);
800810
if (ip_overwritten)
@@ -842,6 +852,8 @@ void __netpoll_cleanup(struct netpoll *np)
842852
call_rcu(&npinfo->rcu, rcu_cleanup_netpoll_info);
843853
} else
844854
RCU_INIT_POINTER(np->dev->npinfo, NULL);
855+
856+
skb_pool_flush(np);
845857
}
846858
EXPORT_SYMBOL_GPL(__netpoll_cleanup);
847859

0 commit comments

Comments
 (0)