diff --git a/storage/backend/backend.go b/storage/backend/backend.go index 3f00821c1..5a6e7c3ba 100644 --- a/storage/backend/backend.go +++ b/storage/backend/backend.go @@ -31,6 +31,11 @@ import ( var ( defaultBatchLimit = 10000 defaultBatchInterval = 100 * time.Millisecond + + // 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_unix.go b/storage/backend/boltoption_unix.go index b20a71312..f4824a270 100644 --- a/storage/backend/boltoption_unix.go +++ b/storage/backend/boltoption_unix.go @@ -28,4 +28,7 @@ import ( // 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} +var boltOpenOptions = &bolt.Options{ + MmapFlags: syscall.MAP_POPULATE, + InitialMmapSize: InitialMmapSize, +}