Skip to content

Commit 849eb4a

Browse files
committed
Don't use MADV_RANDOM
In addition to the explicit documented behavior in posix_madvise(2) this call since Linux 6.4 also causes the kernel to aggressively free pages from the page cache by short circuiting the LRU second chance mechanism. The result is compaction events that took 900ms now take up to 20s and a system which generally operated with near zero major page faults sees 600 or more major faults per second during compaction events. We've tested this change in older kernels and observed no negative impact in typical cloud instances. Fixes #939
1 parent 53df586 commit 849eb4a

File tree

1 file changed

+0
-8
lines changed

1 file changed

+0
-8
lines changed

bolt_unix.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
package bbolt
44

55
import (
6-
"fmt"
76
"syscall"
87
"time"
98
"unsafe"
@@ -58,13 +57,6 @@ func mmap(db *DB, sz int) error {
5857
return err
5958
}
6059

61-
// Advise the kernel that the mmap is accessed randomly.
62-
err = unix.Madvise(b, syscall.MADV_RANDOM)
63-
if err != nil && err != syscall.ENOSYS {
64-
// Ignore not implemented error in kernel because it still works.
65-
return fmt.Errorf("madvise: %s", err)
66-
}
67-
6860
// Save the original byte slice and convert to a byte array pointer.
6961
db.dataref = b
7062
db.data = (*[maxMapSize]byte)(unsafe.Pointer(&b[0]))

0 commit comments

Comments
 (0)