Merge pull request #1672 from jaffee/better-mmap-error

better explanation for 'cannot allocate memory' error
This commit is contained in:
Matthew Jaffee 2021-09-23 09:10:09 -05:00 committed by GitHub
commit 930ec3a403
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -20,6 +20,7 @@ import (
"sync"
"sync/atomic"
"syscall"
"strings"
"github.com/pkg/errors"
)
@ -56,6 +57,9 @@ func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, e
data, err = syscall.Mmap(fd, offset, length, prot, flags)
if err != nil {
atomic.AddUint64(&mapCount, ^uint64(0)) // decrement
if strings.Contains(err.Error(), "cannot allocate memory") {
err = errors.New("mmap 'cannot allocate memory' — please see the troubleshooting how-to in the FeatureBase docs.")
}
}
return data, err
}