Re: [PATCH 4.19 599/639] net: avoid possible false sharing in sk_leave_memory_pressure()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri 2020-01-24 10:32:49, Greg Kroah-Hartman wrote:
> From: Eric Dumazet <edumazet@xxxxxxxxxx>
> 
> [ 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;

Well, C compiler can do a lot of stuff, and we rely on C compiler
being "sane" -- that is gcc.

Even if compiler did the transformation, that will only result in
slightly slower performance, right?

Is there any evidence this is problem in practice? Should this be in
stable?

Best regards,
								Pavel


> +++ b/net/core/sock.c
> @@ -2179,8 +2179,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);
>  	}
>  }



-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux