OSDN Git Service

net: avoid dirtying sk->sk_napi_id
authorEric Dumazet <edumazet@google.com>
Mon, 25 Oct 2021 16:48:18 +0000 (09:48 -0700)
committerJakub Kicinski <kuba@kernel.org>
Tue, 26 Oct 2021 01:02:12 +0000 (18:02 -0700)
sk_napi_id is located in a cache line that can be kept read mostly.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Soheil Hassas Yeganeh <soheil@google.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/busy_poll.h

index 40296ed..4202c60 100644 (file)
@@ -130,7 +130,8 @@ static inline void skb_mark_napi_id(struct sk_buff *skb,
 static inline void sk_mark_napi_id(struct sock *sk, const struct sk_buff *skb)
 {
 #ifdef CONFIG_NET_RX_BUSY_POLL
-       WRITE_ONCE(sk->sk_napi_id, skb->napi_id);
+       if (unlikely(READ_ONCE(sk->sk_napi_id) != skb->napi_id))
+               WRITE_ONCE(sk->sk_napi_id, skb->napi_id);
 #endif
        sk_rx_queue_set(sk, skb);
 }