Skip to content

Commit

Permalink
fix(arm): Fix crashing under ARMv6 due to memory mis-alignment (#239)
Browse files Browse the repository at this point in the history
NOTE: align maxCost to 64-bit boundary for use with atomic.
As per https://golang.org/pkg/sync/atomic/: "On ARM, x86-32,
and 32-bit MIPS, it is the caller’s responsibility to arrange
for 64-bit alignment of 64-bit words accessed atomically.
The first word in a variable or in an allocated struct, array,
or slice can be relied upon to be 64-bit aligned."
  • Loading branch information
XIELongDragon authored Feb 15, 2021
1 parent 58fa1b4 commit 9c8fa18
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,16 @@ func (p *defaultPolicy) UpdateMaxCost(maxCost int64) {

// sampledLFU is an eviction helper storing key-cost pairs.
type sampledLFU struct {
keyCosts map[uint64]int64
// NOTE: align maxCost to 64-bit boundary for use with atomic.
// As per https://golang.org/pkg/sync/atomic/: "On ARM, x86-32,
// and 32-bit MIPS, it is the caller’s responsibility to arrange
// for 64-bit alignment of 64-bit words accessed atomically.
// The first word in a variable or in an allocated struct, array,
// or slice can be relied upon to be 64-bit aligned."
maxCost int64
used int64
metrics *Metrics
keyCosts map[uint64]int64
}

func newSampledLFU(maxCost int64) *sampledLFU {
Expand Down

0 comments on commit 9c8fa18

Please sign in to comment.