Module memory

Module memory 

Source
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:

  1. Kernel needs to swap pages OUT to the daemon’s device
  2. Daemon needs memory to process I/O request
  3. Kernel tries to swap out daemon’s pages to free memory
  4. 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§

MlockResult
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).