lock_daemon_memory

Function lock_daemon_memory 

Source
pub fn lock_daemon_memory(required: bool) -> Result<MlockResult>
Expand description

Lock all current and future memory allocations to prevent swapping.

This is CRITICAL for swap device daemons to prevent deadlock.

§Arguments

  • required - If true, returns an error on failure. If false, logs warning and continues.

§Returns

  • Ok(MlockResult::Success) if memory was locked successfully
  • Ok(MlockResult::Failed(errno)) if mlockall() failed and required is false
  • Err(...) if mlockall() failed and required is true

§Platform Support

  • Linux: Full support via mlockall()
  • macOS: Limited support (requires entitlements)
  • Others: Returns MlockResult::Disabled

§Capability Requirements

Requires one of:

  • CAP_IPC_LOCK capability
  • Root privileges
  • Sufficient RLIMIT_MEMLOCK limit

§Errors

Returns PlatformError::Resource if required is true and mlockall fails.