News for hackers. Stuff that matters.
Re:Exploring How Cache Memory Works by eikenberry on Wednesday June 26, 2024 @12:40PM (#40801850)
In case you are wondering about your cache-line size on a Linux box, you can find it in sysfs.. something like..

    cat /sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size
Re:Exploring How Cache Memory Works by Hello71 on Wednesday June 26, 2024 @02:31PM (#40802993)

  grep . /sys/devices/system/cpu/cpu*/cache/index*/coherency_line_size
would be better, but

  lscpu -C
is more useful.
Re:Exploring How Cache Memory Works by eikenberry on Wednesday June 26, 2024 @03:52PM (#40803936)
Didn't know about 'lscpu -C'.. thanks!
Re:Exploring How Cache Memory Works by wyldfire on Thursday June 27, 2024 @03:27AM (#40808224)
Another (more portable) way to get the cache line size is to use std::hardware_(destructive|constructive)_interference_size from C++17.

While it's more portable, there are some drawbacks. Drawbacks with this approach are: (1) the statically known cache line size might not be right if you deploy your code to a target CPU different from the one you compiled for, (2) using this value to define structure + member alignment in headers could end up with interesting bugs if different source files including the header are built with different flags. Also: your toolchain might not support it yet.