[PATCH 6/9] netconsole: move skb_pool / refill_wq from struct netpoll to netconsole_target
From: Breno Leitao
Date: Sun May 24 2026 - 12:14:14 EST
These two fields back the fallback skb pool that find_skb() uses.
Every helper that touches them lives in netconsole now (refill_skbs,
refill_skbs_work_handler, netconsole_skb_pool_init,
netconsole_skb_pool_flush, find_skb), so the data can move alongside
its only consumer.
Add skb_pool and refill_wq to struct netconsole_target, drop them
from struct netpoll, and update the helpers and find_skb() to take
a struct netconsole_target * and reach the pool through nt-> rather
than np->. Thread nt through netpoll_send_udp() so its only caller
in send_udp() can pass nt directly.
struct netpoll shrinks by sizeof(sk_buff_head) + sizeof(work_struct)
for every consumer, including bonding, bridge, team, vlan, macvlan
and dsa, which carried the fields as dead weight.
Signed-off-by: Breno Leitao <leitao@xxxxxxxxxx>
---
drivers/net/netconsole.c | 47 +++++++++++++++++++++++++++--------------------
include/linux/netpoll.h | 2 --
2 files changed, 27 insertions(+), 22 deletions(-)
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index a8ced60bef7a..b8b1608d09e9 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -183,6 +183,11 @@ enum target_state {
* remote_mac (read-write)
* @buf: The buffer used to send the full msg to the network stack
* @resume_wq: Workqueue to resume deactivated target
+ * @skb_pool: Per-target fallback skb pool consulted by find_skb() when
+ * its GFP_ATOMIC allocation fails. Lifetime brackets a
+ * successful netpoll_setup() / netpoll_cleanup() pair on @np.
+ * @refill_wq: Work item that asynchronously tops @skb_pool back up to
+ * MAX_SKBS after find_skb() drains an entry.
*/
struct netconsole_target {
struct list_head list;
@@ -206,6 +211,8 @@ struct netconsole_target {
/* protected by target_list_lock */
char buf[MAX_PRINT_CHUNK];
struct work_struct resume_wq;
+ struct sk_buff_head skb_pool;
+ struct work_struct refill_wq;
};
#ifdef CONFIG_NETCONSOLE_DYNAMIC
@@ -296,13 +303,11 @@ static bool bound_by_mac(struct netconsole_target *nt)
return is_valid_ether_addr(nt->np.dev_mac);
}
-static void refill_skbs(struct netpoll *np)
+static void refill_skbs(struct netconsole_target *nt)
{
- struct sk_buff_head *skb_pool;
+ struct sk_buff_head *skb_pool = &nt->skb_pool;
struct sk_buff *skb;
- skb_pool = &np->skb_pool;
-
while (READ_ONCE(skb_pool->qlen) < MAX_SKBS) {
skb = alloc_skb(MAX_SKB_SIZE, GFP_ATOMIC);
if (!skb)
@@ -314,10 +319,10 @@ static void refill_skbs(struct netpoll *np)
static void refill_skbs_work_handler(struct work_struct *work)
{
- struct netpoll *np =
- container_of(work, struct netpoll, refill_wq);
+ struct netconsole_target *nt =
+ container_of(work, struct netconsole_target, refill_wq);
- refill_skbs(np);
+ refill_skbs(nt);
}
/* Initialise the per-target skb pool that find_skb() falls back to and
@@ -326,17 +331,15 @@ static void refill_skbs_work_handler(struct work_struct *work)
*/
static void netconsole_skb_pool_init(struct netconsole_target *nt)
{
- skb_queue_head_init(&nt->np.skb_pool);
- INIT_WORK(&nt->np.refill_wq, refill_skbs_work_handler);
- refill_skbs(&nt->np);
+ skb_queue_head_init(&nt->skb_pool);
+ INIT_WORK(&nt->refill_wq, refill_skbs_work_handler);
+ refill_skbs(nt);
}
static void netconsole_skb_pool_flush(struct netconsole_target *nt)
{
- struct netpoll *np = &nt->np;
-
- cancel_work_sync(&np->refill_wq);
- skb_queue_purge_reason(&np->skb_pool, SKB_CONSUMED);
+ cancel_work_sync(&nt->refill_wq);
+ skb_queue_purge_reason(&nt->skb_pool, SKB_CONSUMED);
}
/* Attempts to resume logging to a deactivated target. */
@@ -1731,8 +1734,10 @@ static struct notifier_block netconsole_netdev_notifier = {
.notifier_call = netconsole_netdev_event,
};
-static struct sk_buff *find_skb(struct netpoll *np, int len, int reserve)
+static struct sk_buff *find_skb(struct netconsole_target *nt, int len,
+ int reserve)
{
+ struct netpoll *np = &nt->np;
int count = 0;
struct sk_buff *skb;
@@ -1741,8 +1746,8 @@ static struct sk_buff *find_skb(struct netpoll *np, int len, int reserve)
skb = alloc_skb(len, GFP_ATOMIC);
if (!skb) {
- skb = skb_dequeue(&np->skb_pool);
- schedule_work(&np->refill_wq);
+ skb = skb_dequeue(&nt->skb_pool);
+ schedule_work(&nt->refill_wq);
}
if (!skb) {
@@ -1865,8 +1870,10 @@ static void push_ipv6(struct netpoll *np, struct sk_buff *skb, int len)
skb->protocol = htons(ETH_P_IPV6);
}
-static int netpoll_send_udp(struct netpoll *np, const char *msg, int len)
+static int netpoll_send_udp(struct netconsole_target *nt, const char *msg,
+ int len)
{
+ struct netpoll *np = &nt->np;
int total_len, ip_len, udp_len;
struct sk_buff *skb;
@@ -1881,7 +1888,7 @@ static int netpoll_send_udp(struct netpoll *np, const char *msg, int len)
total_len = ip_len + LL_RESERVED_SPACE(np->dev);
- skb = find_skb(np, total_len + np->dev->needed_tailroom,
+ skb = find_skb(nt, total_len + np->dev->needed_tailroom,
total_len - len);
if (!skb)
return -ENOMEM;
@@ -1912,7 +1919,7 @@ static int netpoll_send_udp(struct netpoll *np, const char *msg, int len)
*/
static void send_udp(struct netconsole_target *nt, const char *msg, int len)
{
- int result = netpoll_send_udp(&nt->np, msg, len);
+ int result = netpoll_send_udp(nt, msg, len);
if (IS_ENABLED(CONFIG_NETCONSOLE_DYNAMIC)) {
if (result == NET_XMIT_DROP) {
diff --git a/include/linux/netpoll.h b/include/linux/netpoll.h
index e4b8f1f91e54..8344454df05d 100644
--- a/include/linux/netpoll.h
+++ b/include/linux/netpoll.h
@@ -35,8 +35,6 @@ struct netpoll {
bool ipv6;
u16 local_port, remote_port;
u8 remote_mac[ETH_ALEN];
- struct sk_buff_head skb_pool;
- struct work_struct refill_wq;
};
#define np_info(np, fmt, ...) \
--
2.54.0