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, netcons_skb_pop), so the data can move alongside its only consumer. Add skb_pool and refill_wq to struct netconsole_target, drop them from struct netpoll. This will save 48-bytes for every netpoll user instance (except netconsole that will have it in netconsole target struct). Signed-off-by: Breno Leitao --- drivers/net/netconsole.c | 53 +++++++++++++++++++++++++++--------------------- include/linux/netpoll.h | 2 -- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 3e1b8ece7032e..bfa5fdac9600b 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; @@ -208,6 +213,8 @@ struct netconsole_target { */ char buf[MAX_PRINT_CHUNK + 1]; struct work_struct resume_wq; + struct sk_buff_head skb_pool; + struct work_struct refill_wq; }; #ifdef CONFIG_NETCONSOLE_DYNAMIC @@ -305,13 +312,11 @@ static void netcons_release_dev(struct netconsole_target *nt) memset(&nt->np.dev_name, 0, IFNAMSIZ); } -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 | __GFP_NOWARN); if (!skb) @@ -323,10 +328,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 @@ -335,17 +340,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. */ @@ -1784,7 +1787,7 @@ static struct notifier_block netconsole_netdev_notifier = { * pool locks and is therefore not NMI-safe. Skip the refill when called * from NMI context; the next non-NMI caller will top the pool back up. */ -static struct sk_buff *netcons_skb_pop(struct netpoll *np, int len) +static struct sk_buff *netcons_skb_pop(struct netconsole_target *nt, int len) { struct sk_buff *skb; @@ -1796,19 +1799,21 @@ static struct sk_buff *netcons_skb_pop(struct netpoll *np, int len) if (!in_nmi()) net_warn_ratelimited("netconsole: dropping message, requested skb len %d exceeds pool buffer size %zu on %s\n", len, (size_t)MAX_SKB_SIZE, - np->dev->name); + nt->np.dev->name); return NULL; } - skb = skb_dequeue(&np->skb_pool); + skb = skb_dequeue(&nt->skb_pool); if (!in_nmi()) - schedule_work(&np->refill_wq); + schedule_work(&nt->refill_wq); return skb; } -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; @@ -1817,7 +1822,7 @@ static struct sk_buff *find_skb(struct netpoll *np, int len, int reserve) skb = alloc_skb(len, GFP_ATOMIC | __GFP_NOWARN); if (!skb) - skb = netcons_skb_pop(np, len); + skb = netcons_skb_pop(nt, len); if (!skb) { if (++count < 10) { @@ -1939,8 +1944,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; @@ -1955,7 +1962,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; @@ -1986,7 +1993,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 1216b5c237ce4..f377fdf7839ca 100644 --- a/include/linux/netpoll.h +++ b/include/linux/netpoll.h @@ -37,8 +37,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.53.0-Meta