SysRq Trigger
When an Out-of-Memory (OOM) condition occurs, the Linux kernel may terminate processes to free memory, but diagnosing the root cause requires capturing diagnostic data during the event. The sysrq-trigger utility provides a way to invoke kernel-level commands, including memory dumps and OOM-related diagnostics, even when the system is unresponsive. This is critical for post-mortem analysis of OOM events.
Key SysRQ Triggers for OOM Debugging¶
The sysrq-trigger command sends specific keypresses to the kernel. Use it with caution, as some triggers can cause system instability. Relevant triggers for OOM analysis include:
m: Dumps memory statistics (e.g., total, free, used memory) to the console. This provides a snapshot of memory usage at the time of the trigger.t: Triggers a full memory dump (kernel core dump) to disk. This is useful for analyzing the state of memory at the time of the OOM event.o: Displays OOM killer details, such as the process ID (PID) of the victim and memory usage metrics. This helps identify which process was terminated.d: Dumps memory to disk (similar totbut may vary by kernel version). Use this iftis unavailable or restricted.
Note: Some triggers (e.g., t or d) require the kernel to be configured with CONFIG_KALLSYMS and sufficient disk space. Always verify kernel documentation for version-specific behavior.
Example Usage¶
-
Capture memory statistics:
This outputs memory metrics to the console, such as: -
Trigger a memory dump:
This generates a file like/var/crash/vmcore-dump-<timestamp>.dmp(location depends on kernel configuration). -
View OOM killer details:
Output might include:
Analyzing the Data¶
- Memory dumps (
t/d): Use tools likecrashorgdbto analyze the core dump. For example: - OOM killer logs: Check
/var/log/kern.logor usedmesgto find OOM-related messages:
Best Practices¶
- Pre-configure sysrq: Ensure
sysrqis enabled in the kernel (CONFIG_SYSRQ), and installsysrq-toolsfor command-line access. - Monitor disk space: Memory dumps can be large (GBs), so ensure sufficient storage is available.
- Test in safe environments: Avoid using these triggers on production systems without proper safeguards.
Key takeaways¶
- Use
sysrq-triggerto capture memory stats, dumps, and OOM killer details during OOM events. - The
m,t,o, anddtriggers provide critical diagnostic data, though kernel version and configuration may affect behavior. - Analyze memory dumps with tools like
crashand review logs in/var/log/kern.logfor OOM-related messages. - Always verify kernel configuration and disk space before triggering memory dumps.