Skip to content

Commit 1200097

Browse files
edumazetkuba-moo
authored andcommitted
net: call skb_defer_free_flush() from __napi_busy_loop()
skb_defer_free_flush() is currently called from net_rx_action() and napi_threaded_poll(). We should also call it from __napi_busy_loop() otherwise there is the risk the percpu queue can grow until an IPI is forced from skb_attempt_defer_free() adding a latency spike. Signed-off-by: Eric Dumazet <[email protected]> Cc: Samiullah Khawaja <[email protected]> Acked-by: Stanislav Fomichev <[email protected]> Reviewed-by: Jiri Pirko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 9912362 commit 1200097

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

net/core/dev.c

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6173,6 +6173,27 @@ struct napi_struct *napi_by_id(unsigned int napi_id)
61736173
return NULL;
61746174
}
61756175

6176+
static void skb_defer_free_flush(struct softnet_data *sd)
6177+
{
6178+
struct sk_buff *skb, *next;
6179+
6180+
/* Paired with WRITE_ONCE() in skb_attempt_defer_free() */
6181+
if (!READ_ONCE(sd->defer_list))
6182+
return;
6183+
6184+
spin_lock(&sd->defer_lock);
6185+
skb = sd->defer_list;
6186+
sd->defer_list = NULL;
6187+
sd->defer_count = 0;
6188+
spin_unlock(&sd->defer_lock);
6189+
6190+
while (skb != NULL) {
6191+
next = skb->next;
6192+
napi_consume_skb(skb, 1);
6193+
skb = next;
6194+
}
6195+
}
6196+
61766197
#if defined(CONFIG_NET_RX_BUSY_POLL)
61776198

61786199
static void __busy_poll_stop(struct napi_struct *napi, bool skip_schedule)
@@ -6297,6 +6318,7 @@ static void __napi_busy_loop(unsigned int napi_id,
62976318
if (work > 0)
62986319
__NET_ADD_STATS(dev_net(napi->dev),
62996320
LINUX_MIB_BUSYPOLLRXPACKETS, work);
6321+
skb_defer_free_flush(this_cpu_ptr(&softnet_data));
63006322
local_bh_enable();
63016323

63026324
if (!loop_end || loop_end(loop_end_arg, start_time))
@@ -6726,27 +6748,6 @@ static int napi_thread_wait(struct napi_struct *napi)
67266748
return -1;
67276749
}
67286750

6729-
static void skb_defer_free_flush(struct softnet_data *sd)
6730-
{
6731-
struct sk_buff *skb, *next;
6732-
6733-
/* Paired with WRITE_ONCE() in skb_attempt_defer_free() */
6734-
if (!READ_ONCE(sd->defer_list))
6735-
return;
6736-
6737-
spin_lock(&sd->defer_lock);
6738-
skb = sd->defer_list;
6739-
sd->defer_list = NULL;
6740-
sd->defer_count = 0;
6741-
spin_unlock(&sd->defer_lock);
6742-
6743-
while (skb != NULL) {
6744-
next = skb->next;
6745-
napi_consume_skb(skb, 1);
6746-
skb = next;
6747-
}
6748-
}
6749-
67506751
static int napi_threaded_poll(void *data)
67516752
{
67526753
struct napi_struct *napi = data;

0 commit comments

Comments
 (0)