mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
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:
parent
d906d8573e
commit
150e99d403
2 changed files with 27 additions and 6 deletions
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue