Skip to content

Commit

Permalink
net: avoid possible false sharing in sk_leave_memory_pressure()
Browse files Browse the repository at this point in the history
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: 0604475 ("tcp: add TCPMemoryPressuresChrono counter")
Fixes: 180d8cd ("foundations of per-cgroup memory pressure controlling.")
Fixes: 3ab224b ("[NET] CORE: Introducing new memory accounting interface.")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
  • Loading branch information
Eric Dumazet authored and Jakub Kicinski committed Oct 10, 2019
1 parent 4ffdd22 commit 503978a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions net/core/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -2334,8 +2334,8 @@ static void sk_leave_memory_pressure(struct sock *sk)
} else {
unsigned long *memory_pressure = sk->sk_prot->memory_pressure;

if (memory_pressure && *memory_pressure)
*memory_pressure = 0;
if (memory_pressure && READ_ONCE(*memory_pressure))
WRITE_ONCE(*memory_pressure, 0);
}
}

Expand Down

0 comments on commit 503978a

Please sign in to comment.