server: replace mlockall with Mlock in --experimental-memory-mlock

Implementation of `--experimental-memory-mlock` backed by `mlockall` syscall is replaced by `Mlock` flag (backed by mlock syscall) of bboltDB.
This commit is contained in:
wpedrak
2021-04-28 16:00:04 +02:00
parent cc52d994b7
commit 927b3a3152
13 changed files with 26 additions and 85 deletions

View File

@@ -122,6 +122,8 @@ type BackendConfig struct {
Logger *zap.Logger
// UnsafeNoFsync disables all uses of fsync.
UnsafeNoFsync bool `json:"unsafe-no-fsync"`
// Mlock prevents backend database file to be swapped
Mlock bool
}
func DefaultBackendConfig() BackendConfig {
@@ -155,6 +157,7 @@ func newBackend(bcfg BackendConfig) *backend {
bopts.FreelistType = bcfg.BackendFreelistType
bopts.NoSync = bcfg.UnsafeNoFsync
bopts.NoGrowSync = bcfg.UnsafeNoFsync
bopts.Mlock = bcfg.Mlock
db, err := bolt.Open(bcfg.Path, 0600, bopts)
if err != nil {
@@ -381,6 +384,8 @@ func (b *backend) defrag() error {
options.OpenFile = func(path string, i int, mode os.FileMode) (file *os.File, err error) {
return temp, nil
}
// Don't load tmp db into memory regardless of opening options
options.Mlock = false
tdbp := temp.Name()
tmpdb, err := bolt.Open(tdbp, 0600, &options)
if err != nil {