mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #12750 from ptabor/20210306-mlock
--experimental-memory-mlock support
This commit is contained in:
@@ -169,6 +169,14 @@ type ServerConfig struct {
|
||||
UnsafeNoFsync bool `json:"unsafe-no-fsync"`
|
||||
|
||||
DowngradeCheckTime time.Duration
|
||||
|
||||
// ExperimentalMemoryMlock enables mlocking of etcd owned memory pages.
|
||||
// The setting improves etcd tail latency in environments were:
|
||||
// - memory pressure might lead to swapping pages to disk
|
||||
// - disk latency might be unstable
|
||||
// Currently all etcd memory gets mlocked, but in future the flag can
|
||||
// be refined to mlock in-use area of bbolt only.
|
||||
ExperimentalMemoryMlock bool `json:"experimental-memory-mlock"`
|
||||
}
|
||||
|
||||
// VerifyBootstrap sanity-checks the initial config for bootstrap case
|
||||
|
||||
27
server/etcdserver/mlock_not_unix.go
Normal file
27
server/etcdserver/mlock_not_unix.go
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright 2021 The etcd Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package etcdserver
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
// MlockAll prevents current and future mmaped memory areas from being swapped out.
|
||||
func MlockAll() error {
|
||||
return errors.New("Mlockall is supported only on UNIX systems.")
|
||||
}
|
||||
33
server/etcdserver/mlock_unix.go
Normal file
33
server/etcdserver/mlock_unix.go
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright 2021 The etcd Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || zos
|
||||
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris zos
|
||||
|
||||
package etcdserver
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// MlockAll prevents current and future mmaped memory areas from being swapped out.
|
||||
func MlockAll() error {
|
||||
err := unix.Mlockall(unix.MCL_FUTURE | unix.MCL_CURRENT)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot mlockAll: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -316,6 +316,14 @@ func NewServer(cfg ServerConfig) (srv *EtcdServer, err error) {
|
||||
)
|
||||
}
|
||||
|
||||
if cfg.ExperimentalMemoryMlock {
|
||||
cfg.Logger.Info("mlocking memory")
|
||||
err := MlockAll()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if terr := fileutil.TouchDirAll(cfg.DataDir); terr != nil {
|
||||
return nil, fmt.Errorf("cannot access data directory: %v", terr)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user