Example #1
0
// Locks memory, preventing memory from being written to disk as swap
func lockMemory() {
	err := unix.Mlockall(unix.MCL_FUTURE | unix.MCL_CURRENT)
	switch err {
	case nil:
	case unix.ENOSYS:
		log.Println("mlockall() not implemented on this system")
	case unix.ENOMEM:
		log.Println("mlockall() failed with ENOMEM")
	default:
		log.Fatalf("Could not perform mlockall and prevent swapping memory: %v", err)
	}
}
Example #2
0
func lockMemory() {
	err := unix.Mlockall(unix.MCL_FUTURE | unix.MCL_CURRENT)
	switch err {
	case nil:
	case unix.ENOSYS:
		logrus.WithError(err).Warn("mlockall() not implemented on this system")
	case unix.ENOMEM:
		logrus.WithError(err).Warn("mlockall() failed with ENOMEM")
	default:
		logrus.WithError(err).Warn("could not perform mlockall to prevent swapping memory")
	}
}
// Locks memory, preventing memory from being written to disk as swap
func lockMemory(debug bool) {
	logConfig := klog.Config{
		Debug:      debug,
		Mountpoint: "",
	}
	logger := klog.New("kwfs_main", logConfig)

	err := unix.Mlockall(unix.MCL_FUTURE | unix.MCL_CURRENT)
	switch err {
	case nil:
	case unix.ENOSYS:
		logger.Warnf("mlockall() not implemented on this system")
	case unix.ENOMEM:
		logger.Warnf("mlockall() failed with ENOMEM")
	default:
		log.Fatalf("Could not perform mlockall and prevent swapping memory: %v", err)
	}
}
Example #4
0
func lockMemory() error {
	// Mlockall prevents all current and future pages from being swapped out.
	return unix.Mlockall(syscall.MCL_CURRENT | syscall.MCL_FUTURE)
}