forked from etcd-io/bbolt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
`Mlock` flag will cause mlock on db file which will prevent memory swapping of it. Motivation of this commit (etcd): etcd-io/etcd#12750
- Loading branch information
Showing
4 changed files
with
108 additions
and
3 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
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 @@ | ||
// +build !windows | ||
|
||
package bbolt | ||
|
||
import "golang.org/x/sys/unix" | ||
|
||
// mlock locks memory of db file | ||
func mlock(db *DB, fileSize int) error { | ||
sizeToLock := fileSize | ||
if sizeToLock > db.datasz { | ||
// Can't lock more than mmaped slice | ||
sizeToLock = db.datasz | ||
} | ||
if err := unix.Mlock(db.dataref[:sizeToLock]); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
//munlock unlocks memory of db file | ||
func munlock(db *DB, fileSize int) error { | ||
if db.dataref == nil { | ||
return nil | ||
} | ||
|
||
sizeToUnlock := fileSize | ||
if sizeToUnlock > db.datasz { | ||
// Can't unlock more than mmaped slice | ||
sizeToUnlock = db.datasz | ||
} | ||
|
||
if err := unix.Munlock(db.dataref[:sizeToUnlock]); err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
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,11 @@ | ||
package bbolt | ||
|
||
// mlock locks memory of db file | ||
func mlock(_ *DB, _ int) error { | ||
panic("mlock is supported only on UNIX systems") | ||
} | ||
|
||
//munlock unlocks memory of db file | ||
func munlock(_ *DB, _ int) error { | ||
panic("munlock is supported only on UNIX systems") | ||
} |