Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use MAP_POPULATE for our bbolt mmaps (#13573)
* Use MAP_POPULATE for our bbolt mmaps, assuming the files fit in memory. This should improve startup times when freelist sync is disabled.
- Loading branch information
Showing
6 changed files
with
49 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:bug | ||
storage/raft: On linux, use map_populate for bolt files to improve startup time. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package raft | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"github.com/shirou/gopsutil/mem" | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func init() { | ||
getMmapFlags = getMmapFlagsLinux | ||
} | ||
|
||
func getMmapFlagsLinux(dbPath string) int { | ||
if os.Getenv("VAULT_RAFT_DISABLE_MAP_POPULATE") != "" { | ||
return 0 | ||
} | ||
stat, err := os.Stat(dbPath) | ||
if err != nil { | ||
return 0 | ||
} | ||
size := stat.Size() | ||
|
||
v, err := mem.VirtualMemoryWithContext(context.Background()) | ||
if err != nil { | ||
return 0 | ||
} | ||
|
||
// We won't worry about swap, since we already tell people not to use it. | ||
if v.Total > uint64(size) { | ||
return unix.MAP_POPULATE | ||
} | ||
|
||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters