Skip to content

Commit 4adb465

Browse files
leitaoopsiff
authored andcommitted
net: netpoll: Individualize the skb pool
[ Upstream commit 221a9c1 ] The current implementation of the netpoll system uses a global skb pool, which can lead to inefficient memory usage and waste when targets are disabled or no longer in use. This can result in a significant amount of memory being unnecessarily allocated and retained, potentially causing performance issues and limiting the availability of resources for other system components. Modify the netpoll system to assign a skb pool to each target instead of using a global one. This approach allows for more fine-grained control over memory allocation and deallocation, ensuring that resources are only allocated and retained as needed. 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 1652fbe448029e8628011f17ebb367b2b96c6d28) Signed-off-by: Wentao Guan <[email protected]>
1 parent 380a3bc commit 4adb465

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

include/linux/netpoll.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct netpoll {
3232
bool ipv6;
3333
u16 local_port, remote_port;
3434
u8 remote_mac[ETH_ALEN];
35+
struct sk_buff_head skb_pool;
3536
};
3637

3738
struct netpoll_info {

net/core/netpoll.c

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@
4545

4646
#define MAX_UDP_CHUNK 1460
4747
#define MAX_SKBS 32
48-
49-
static struct sk_buff_head skb_pool;
50-
5148
#define USEC_PER_POLL 50
5249

5350
#define MAX_SKB_SIZE \
@@ -234,20 +231,23 @@ void netpoll_poll_enable(struct net_device *dev)
234231
up(&ni->dev_lock);
235232
}
236233

237-
static void refill_skbs(void)
234+
static void refill_skbs(struct netpoll *np)
238235
{
236+
struct sk_buff_head *skb_pool;
239237
struct sk_buff *skb;
240238
unsigned long flags;
241239

242-
spin_lock_irqsave(&skb_pool.lock, flags);
243-
while (skb_pool.qlen < MAX_SKBS) {
240+
skb_pool = &np->skb_pool;
241+
242+
spin_lock_irqsave(&skb_pool->lock, flags);
243+
while (skb_pool->qlen < MAX_SKBS) {
244244
skb = alloc_skb(MAX_SKB_SIZE, GFP_ATOMIC);
245245
if (!skb)
246246
break;
247247

248-
__skb_queue_tail(&skb_pool, skb);
248+
__skb_queue_tail(skb_pool, skb);
249249
}
250-
spin_unlock_irqrestore(&skb_pool.lock, flags);
250+
spin_unlock_irqrestore(&skb_pool->lock, flags);
251251
}
252252

253253
static void zap_completion_queue(void)
@@ -284,12 +284,12 @@ static struct sk_buff *find_skb(struct netpoll *np, int len, int reserve)
284284
struct sk_buff *skb;
285285

286286
zap_completion_queue();
287-
refill_skbs();
287+
refill_skbs(np);
288288
repeat:
289289

290290
skb = alloc_skb(len, GFP_ATOMIC);
291291
if (!skb)
292-
skb = skb_dequeue(&skb_pool);
292+
skb = skb_dequeue(&np->skb_pool);
293293

294294
if (!skb) {
295295
if (++count < 10) {
@@ -678,6 +678,8 @@ int netpoll_setup(struct netpoll *np)
678678
struct in_device *in_dev;
679679
int err;
680680

681+
skb_queue_head_init(&np->skb_pool);
682+
681683
rtnl_lock();
682684
if (np->dev_name[0]) {
683685
struct net *net = current->nsproxy->net_ns;
@@ -778,7 +780,7 @@ int netpoll_setup(struct netpoll *np)
778780
}
779781

780782
/* fill up the skb queue */
781-
refill_skbs();
783+
refill_skbs(np);
782784

783785
err = __netpoll_setup(np, ndev);
784786
if (err)
@@ -804,13 +806,6 @@ int netpoll_setup(struct netpoll *np)
804806
}
805807
EXPORT_SYMBOL(netpoll_setup);
806808

807-
static int __init netpoll_init(void)
808-
{
809-
skb_queue_head_init(&skb_pool);
810-
return 0;
811-
}
812-
core_initcall(netpoll_init);
813-
814809
static void rcu_cleanup_netpoll_info(struct rcu_head *rcu_head)
815810
{
816811
struct netpoll_info *npinfo =

0 commit comments

Comments
 (0)