Skip to content

Commit 9c94ae6

Browse files
edumazetPaolo Abeni
authored andcommitted
net: make softnet_data.defer_count an atomic
This is preparation work to remove the softnet_data.defer_lock, as it is contended on hosts with large number of cores. Signed-off-by: Eric Dumazet <[email protected]> Reviewed-by: Jason Xing <[email protected]> Reviewed-by: Kuniyuki Iwashima <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 2c0592b commit 9c94ae6

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

include/linux/netdevice.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3538,7 +3538,7 @@ struct softnet_data {
35383538

35393539
/* Another possibly contended cache line */
35403540
spinlock_t defer_lock ____cacheline_aligned_in_smp;
3541-
int defer_count;
3541+
atomic_t defer_count;
35423542
int defer_ipi_scheduled;
35433543
struct sk_buff *defer_list;
35443544
call_single_data_t defer_csd;

net/core/dev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6726,7 +6726,7 @@ static void skb_defer_free_flush(struct softnet_data *sd)
67266726
spin_lock(&sd->defer_lock);
67276727
skb = sd->defer_list;
67286728
sd->defer_list = NULL;
6729-
sd->defer_count = 0;
6729+
atomic_set(&sd->defer_count, 0);
67306730
spin_unlock(&sd->defer_lock);
67316731

67326732
while (skb != NULL) {

net/core/skbuff.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7202,14 +7202,12 @@ nodefer: kfree_skb_napi_cache(skb);
72027202

72037203
sd = &per_cpu(softnet_data, cpu);
72047204
defer_max = READ_ONCE(net_hotdata.sysctl_skb_defer_max);
7205-
if (READ_ONCE(sd->defer_count) >= defer_max)
7205+
if (atomic_read(&sd->defer_count) >= defer_max)
72067206
goto nodefer;
72077207

72087208
spin_lock_bh(&sd->defer_lock);
72097209
/* Send an IPI every time queue reaches half capacity. */
7210-
kick = sd->defer_count == (defer_max >> 1);
7211-
/* Paired with the READ_ONCE() few lines above */
7212-
WRITE_ONCE(sd->defer_count, sd->defer_count + 1);
7210+
kick = (atomic_inc_return(&sd->defer_count) - 1) == (defer_max >> 1);
72137211

72147212
skb->next = sd->defer_list;
72157213
/* Paired with READ_ONCE() in skb_defer_free_flush() */

0 commit comments

Comments
 (0)