Files
VictoriaMetrics/lib/atomicutil/uint64.go
Aliaksandr Valialkin 92b85c8ded lib/atomicutil: add CacheLineSize const equal to the size of CPU cache line, and use this const for padding against false sharing across the code base
This should reduce the waste of memory on the padding from 128 bytes to 64 bytes on GOARCH=amd64,
while preserving bigger padding for platforms with bigger cache line sizes.

See https://stackoverflow.com/questions/68320687/why-are-most-cache-line-sizes-designed-to-be-64-byte-instead-of-32-128byte-now

Thanks to @tIGO for the hint
2025-06-06 10:24:43 +02:00

18 lines
449 B
Go

package atomicutil
import (
"sync/atomic"
"unsafe"
)
// Uint64 is like atomic.Uint64, but is protected from false sharing.
type Uint64 struct {
// The padding prevents false sharing with the previous memory location
_ [CacheLineSize - unsafe.Sizeof(atomic.Uint64{})%CacheLineSize]byte
atomic.Uint64
// The padding prevents false sharing with the next memory location
_ [CacheLineSize - unsafe.Sizeof(atomic.Uint64{})%CacheLineSize]byte
}