Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sock: avoid dirtying incoming_cpu if not needed

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>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Paolo Abeni and committed by
David S. Miller
34cfb542 28b5ba2a

+4 -1
+4 -1
include/net/sock.h
··· 907 907 908 908 static inline void sk_incoming_cpu_update(struct sock *sk) 909 909 { 910 - sk->sk_incoming_cpu = raw_smp_processor_id(); 910 + int cpu = raw_smp_processor_id(); 911 + 912 + if (unlikely(sk->sk_incoming_cpu != cpu)) 913 + sk->sk_incoming_cpu = cpu; 911 914 } 912 915 913 916 static inline void sock_rps_record_flow_hash(__u32 hash)