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

net: avoid possible false sharing in sk_leave_memory_pressure()

As mentioned in https://github.com/google/ktsan/wiki/READ_ONCE-and-WRITE_ONCE#it-may-improve-performance
a C compiler can legally transform :

if (memory_pressure && *memory_pressure)
*memory_pressure = 0;

to :

if (memory_pressure)
*memory_pressure = 0;

Fixes: 0604475119de ("tcp: add TCPMemoryPressuresChrono counter")
Fixes: 180d8cd942ce ("foundations of per-cgroup memory pressure controlling.")
Fixes: 3ab224be6d69 ("[NET] CORE: Introducing new memory accounting interface.")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>

authored by

Eric Dumazet and committed by
Jakub Kicinski
503978ac 4ffdd22e

+2 -2
+2 -2
net/core/sock.c
··· 2334 2334 } else { 2335 2335 unsigned long *memory_pressure = sk->sk_prot->memory_pressure; 2336 2336 2337 - if (memory_pressure && *memory_pressure) 2338 - *memory_pressure = 0; 2337 + if (memory_pressure && READ_ONCE(*memory_pressure)) 2338 + WRITE_ONCE(*memory_pressure, 0); 2339 2339 } 2340 2340 } 2341 2341