net: avoid possible false sharing in sk_leave_memory_pressure()

[ Upstream commit 503978aca46124cd714703e180b9c8292ba50ba7 ]

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: 0604475119 ("tcp: add TCPMemoryPressuresChrono counter")
Fixes: 180d8cd942 ("foundations of per-cgroup memory pressure controlling.")
Fixes: 3ab224be6d ("[NET] CORE: Introducing new memory accounting interface.")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Eric Dumazet 2019-10-09 12:55:53 -07:00 committed by Greg Kroah-Hartman
parent 5c1b003d22
commit 910699a81f

View file

@ -2179,8 +2179,8 @@ static void sk_leave_memory_pressure(struct sock *sk)
} else { } else {
unsigned long *memory_pressure = sk->sk_prot->memory_pressure; unsigned long *memory_pressure = sk->sk_prot->memory_pressure;
if (memory_pressure && *memory_pressure) if (memory_pressure && READ_ONCE(*memory_pressure))
*memory_pressure = 0; WRITE_ONCE(*memory_pressure, 0);
} }
} }