diff --git a/lib/mergeset/table.go b/lib/mergeset/table.go index 043260961a..28e632dd05 100644 --- a/lib/mergeset/table.go +++ b/lib/mergeset/table.go @@ -10,6 +10,7 @@ import ( "sync" "sync/atomic" "time" + "unsafe" "github.com/VictoriaMetrics/VictoriaMetrics/lib/bytesutil" "github.com/VictoriaMetrics/VictoriaMetrics/lib/cgroup" @@ -158,10 +159,20 @@ func (riss *rawItemsShards) Len() int { return n } -type rawItemsShard struct { - mu sync.Mutex - ibs []*inmemoryBlock +type rawItemsShardNopad struct { + // Put lastFlushTime to the top in order to avoid unaligned memory access on 32-bit architectures lastFlushTime uint64 + + mu sync.Mutex + ibs []*inmemoryBlock +} + +type rawItemsShard struct { + rawItemsShardNopad + + // The padding prevents false sharing on widespread platforms with + // 128 mod (cache line size) = 0 . + _ [128 - unsafe.Sizeof(rawItemsShardNopad{})%128]byte } func (ris *rawItemsShard) Len() int { diff --git a/lib/storage/partition.go b/lib/storage/partition.go index 85568ee95b..9345abe892 100644 --- a/lib/storage/partition.go +++ b/lib/storage/partition.go @@ -445,10 +445,20 @@ func (rrss *rawRowsShards) Len() int { return n } -type rawRowsShard struct { - mu sync.Mutex - rows []rawRow +type rawRowsShardNopad struct { + // Put lastFlushTime to the top in order to avoid unaligned memory access on 32-bit architectures lastFlushTime uint64 + + mu sync.Mutex + rows []rawRow +} + +type rawRowsShard struct { + rawRowsShardNopad + + // The padding prevents false sharing on widespread platforms with + // 128 mod (cache line size) = 0 . + _ [128 - unsafe.Sizeof(rawRowsShardNopad{})%128]byte } func (rrs *rawRowsShard) Len() int {