__read_only in the kernel

Anton Yuzhaninov citrin+bsd at citrin.ru
Mon Nov 28 15:16:35 UTC 2016


On 11/28/16 03:30, Ed Schouten wrote:
> 2016-11-27 22:25 GMT+01:00 Mateusz Guzik <mjguzik at gmail.com>:
>> The somewhat standard way of combating parts of it for frequently read
>> and rarely (if ever) modified variables is an annotation which puts
>> them in a dedicated part of the binary and the somewhat standard name
>> for a macro doing the work is __read_mostly.
>
> Out of curiosity, what is the advantage of doing this?

If a variable which read often shares CPU cache line with a variable 
updated often we have performance degradation. Each time second variable 
is updated first (read mostly) unnecessary flushed from CPU cache.

Some data structures already aligned by cache line size to avoid false 
sharing, but moving read only / read mostly variables to separate 
section allows to avoid false sharing without spending memory on 
alignment (and alignment not always helps to avoid false sharing AFAIK).


More information about the freebsd-arch mailing list