Error: mremap size mismatch on ARM64

What version of Go are you using (go version)?

go version go1.16.7 linux/arm64

What operating system are you using?

Ubuntu 20.04.2 LTS

Does this issue reproduce with the latest master?

Yes.

Steps to Reproduce the issue

You need to run this twice. On the second run badger will try to truncate mem file and it is the core of the problem:

package main

import (
	"log"

	"github.com/dgraph-io/badger/v3"
)

func main() {
	_, err := badger.Open(badger.DefaultOptions("/tmp/badger"))
	if err != nil {
		log.Fatal(err)
	}

	//defer db.Close() // It's a requirement condition, not to close db
}

On the second run you will have the following error:

2021/08/20 08:37:31 while opening memtables error: while opening fid: 5 error: while updating skiplist error: mremap size mismatch: requested: 20 got: 134217728
exit status 1

This error can only be reproduced on ARM64. The same script will work correctly on AMD64.

As I understood the problem lies within the mremap implementation in the ristretto library.

This PR should solve this problem:

Not sure about Badger, but in general we support AMD64;x86-64 only. If you reproduce it in a common CPU would help.

This is exactly a serious problem. As the ristretto library and badger are all Golang programs and never claim they are only compatible with AMD64 architecture. We are having the same issue as well.

Merged. Thanks for the contribution.

When will you release a new badger version so that we can use it in arm?

Great to see this merged. I tried to advantage of it via having run go get -u github.com/dgraph-io/ristretto@c2901dc76889a90201a15b9cfc3c04bbfe0c298c but I still got an error with making the memory map. I’ve reverted to Badger v2 and am using FileIO. My projects are on Pi3, so it might have been related to the severe memory limitations. Eventually I’d like to use a Pi4 and dig in a bit more.

I used a custom version of Badger v3 with this fix: https://github.com/46bit/distributed-systems/commit/0661a197f8603047b3a1e77aa698e650565efb55

Badger still seems fairly unstable on my Raspberry Pi 4. I’m seeing data loss when writing lots of data and there’s nothing in debug logs. Not sure what to do but give up and use AMD64