diff --git a/storage/backend/backend.go b/storage/backend/backend.go index 155cdac7478a..9183f8dc8337 100644 --- a/storage/backend/backend.go +++ b/storage/backend/backend.go @@ -34,11 +34,6 @@ var ( defaultBatchInterval = 100 * time.Millisecond defragLimit = 10000 - - // InitialMmapSize is the initial size of the mmapped region. Setting this larger than - // the potential max db size can prevent writer from blocking reader. - // This only works for linux. - InitialMmapSize = 10 * 1024 * 1024 * 1024 ) type Backend interface { diff --git a/storage/backend/boltoption_arm.go b/storage/backend/boltoption_arm.go new file mode 100644 index 000000000000..2fd720e631d0 --- /dev/null +++ b/storage/backend/boltoption_arm.go @@ -0,0 +1,45 @@ +// Copyright 2015 CoreOS, Inc. +// +// 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. + + +// +build linux,arm + +package backend + +import ( + "syscall" + "math" + + "github.com/coreos/etcd/Godeps/_workspace/src/github.com/boltdb/bolt" +) + +var ( + // InitialMmapSize is the initial size of the mmapped region. Setting this larger than + // the potential max db size can prevent writer from blocking reader. + // This only works for linux and only on arm 32-bit + // This sets InitialMmapSize to 2GB, or (2 * 1024 * 1024 * 1024) - 1 + InitialMmapSize = math.MaxInt32 +) + + +// syscall.MAP_POPULATE on linux 2.6.23+ does sequential read-ahead +// which can speed up entire-database read with boltdb. We want to +// enable MAP_POPULATE for faster key-value store recovery in storage +// package. If your kernel version is lower than 2.6.23 +// (https://github.com/torvalds/linux/releases/tag/v2.6.23), mmap might +// silently ignore this flag. Please update your kernel to prevent this. +var boltOpenOptions = &bolt.Options{ + MmapFlags: syscall.MAP_POPULATE, + InitialMmapSize: InitialMmapSize, +} diff --git a/storage/backend/boltoption_unix.go b/storage/backend/boltoption_unix.go index f4824a2701ca..c53f1e6ec570 100644 --- a/storage/backend/boltoption_unix.go +++ b/storage/backend/boltoption_unix.go @@ -12,7 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -// +build linux + +// +build linux,!arm package backend @@ -22,6 +23,13 @@ import ( "github.com/coreos/etcd/Godeps/_workspace/src/github.com/boltdb/bolt" ) +var ( + // InitialMmapSize is the initial size of the mmapped region. Setting this larger than + // the potential max db size can prevent writer from blocking reader. + // This only works for linux. + InitialMmapSize = 10 * 1024 * 1024 * 1024 +) + // syscall.MAP_POPULATE on linux 2.6.23+ does sequential read-ahead // which can speed up entire-database read with boltdb. We want to // enable MAP_POPULATE for faster key-value store recovery in storage