* [PATCH net-next] sock: avoid dirtying incoming_cpu if not needed
@ 2017-06-21 9:45 Paolo Abeni
2017-06-21 15:44 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Paolo Abeni @ 2017-06-21 9:45 UTC (permalink / raw)
To: netdev; +Cc: David S. Miller, Eric Dumazet
for connected socket, the incoming_cpu field in the sock struct
is not going to change frequently, but we are setting it
unconditionally for each packet.
Since sk_incoming_cpu and sk_flags share the same cacheline,
and the latter is access by udp_recvmsg(), this cause a cache
miss for each packet for UDP connected socket.
With this patch, we set the incoming cpu field only when the
ingress cpu really changes.
This gives a small but measurable performance improvement for
connected UDP socket.
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
include/net/sock.h | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/include/net/sock.h b/include/net/sock.h
index 858891c..00d0914 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -907,7 +907,10 @@ static inline int sk_backlog_rcv(struct sock *sk, struct sk_buff *skb)
static inline void sk_incoming_cpu_update(struct sock *sk)
{
- sk->sk_incoming_cpu = raw_smp_processor_id();
+ int cpu = raw_smp_processor_id();
+
+ if (unlikely(sk->sk_incoming_cpu != cpu))
+ sk->sk_incoming_cpu = cpu;
}
static inline void sock_rps_record_flow_hash(__u32 hash)
--
2.9.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next] sock: avoid dirtying incoming_cpu if not needed
2017-06-21 9:45 [PATCH net-next] sock: avoid dirtying incoming_cpu if not needed Paolo Abeni
@ 2017-06-21 15:44 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2017-06-21 15:44 UTC (permalink / raw)
To: pabeni; +Cc: netdev, edumazet
From: Paolo Abeni <pabeni@redhat.com>
Date: Wed, 21 Jun 2017 11:45:31 +0200
> for connected socket, the incoming_cpu field in the sock struct
> is not going to change frequently, but we are setting it
> unconditionally for each packet.
>
> Since sk_incoming_cpu and sk_flags share the same cacheline,
> and the latter is access by udp_recvmsg(), this cause a cache
> miss for each packet for UDP connected socket.
>
> With this patch, we set the incoming cpu field only when the
> ingress cpu really changes.
>
> This gives a small but measurable performance improvement for
> connected UDP socket.
>
> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Applied.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-06-21 16:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-21 9:45 [PATCH net-next] sock: avoid dirtying incoming_cpu if not needed Paolo Abeni
2017-06-21 15:44 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).