From b0bfa57cc2996a4ed498a0e7e432fe976a19e728 Mon Sep 17 00:00:00 2001 From: Anjali Chandnani Date: Fri, 12 Feb 2021 17:21:32 +1100 Subject: [PATCH] structure alignment for 386 --- policy.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/policy.go b/policy.go index e193a8a4..7b38da47 100644 --- a/policy.go +++ b/policy.go @@ -279,9 +279,15 @@ 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 + keyCosts map[uint64]int64 metrics *Metrics }