lib/{mergeset,storage}: avoid unaligned 64-bit atomic operation panic on 32-bit platforms

The panic has been introduced in 68f3a02589

While at it, add padding to shard structs in order to avoid false sharing on mordern CPUs

This should improve scalability on systems with many CPU cores
This commit is contained in:
Aliaksandr Valialkin 2022-10-20 16:17:09 +03:00
parent d906d8573e
commit 150e99d403
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
2 changed files with 27 additions and 6 deletions

View file

@ -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 {

View file

@ -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 {