Expand description
Memory management for daemon processes.
§DT-007: Swap Deadlock Prevention
This module provides memory locking functionality to prevent swap deadlock for daemons that serve as swap devices (e.g., trueno-ublk).
§The Problem
When a daemon serves as a swap device, a deadlock can occur:
- Kernel needs to swap pages OUT to the daemon’s device
- Daemon needs memory to process I/O request
- Kernel tries to swap out daemon’s pages to free memory
- Swap goes to the same daemon → waiting for itself → DEADLOCK
§Evidence
Kernel log from 2026-01-06 stress test:
INFO: task trueno-ublk:59497 blocked for more than 122 seconds.
task:trueno-ublk state:D (uninterruptible sleep)
__swap_writepage+0x111/0x1a0
swap_writepage+0x5f/0xe0§Solution
Use mlockall(MCL_CURRENT | MCL_FUTURE) to pin all daemon memory,
preventing the daemon itself from being swapped out.
Enums§
- Mlock
Result - Result of memory locking operation.
Functions§
- apply_
memory_ config - Apply memory-related resource configuration.
- is_
memory_ locked - Check if memory is currently locked.
- lock_
daemon_ memory - Lock all current and future memory allocations to prevent swapping.
- unlock_
daemon_ memory - Unlock all memory (for cleanup/testing).