Linux Magic SysRq Key and OOM

Overview ¶


Unlike MacOSX and Microsoft Windows NT, the Linux kernel and consequentely, Linux distributions still have an OOM - Out-Of-Memory bug, which freezes the computer and makes it unresponsive when almost all memory is used. This issue is annoying as even the keyboard becomes unresponsive and key combination similar to Windows' Ctrl+Al+Del for invoking a process manager does not work.

For many users, the solution is a forced system reboot. However, it may lead to data loss, data corruption and loss of productivity. An alternative to system reboot is the Linux's kernel magic SysReq key combination, which is available in Linux kenels compiled with CONFIG_MAGIC_SYSREQ option enabled. Nowadays, most Linux distributions are shipped with a kernel using this option enabled. In order to use SysReq keyboard shortcut for system recovery, it is necessary to enable it either temporarily or permanently by editing the appropriate configuration file.

SysRq Settings ¶


Check whether SysRq status ¶

To check whether SysRq is eanabled, run

$ cat /proc/sys/kernel/sysrq
1

if the output is 0, then sysrq is disabled, otherwise sysrq is enabled. All sysrq functions are only enabled when this pseudo-file, created by the Linux kernel, is set to 1.

Set SySrq Value without reboot ¶

Enable all SysRq options/functions.

$ sudo sysctl kernel.sysrq=1

All SysRq options can be enabled by setting the pseudo-file (a kernel interface) using the command.

$ echo 1 | sudo tee /proc/sys/kernel/sysrq

Persist SysRq Value on Reboot ¶

Create backup of the configuration file.

$ sudo cp /etc/sysctl.d/99-sysctl.conf -v /etc/sysctl.d/99-sysctl.conf.back

Override the file 99-sysctl.conf with the line kernel.sysrq = 1.

$ echo "kernel.sysrq = 1" | sudo tee /etc/sysctl.d/99-sysctl.conf

Commands ¶


SysRq key-combination provide the following commands.

Unfreeze Computer in OOM ¶

Unfreeze computer in OOM (Out-Of-Memory) by terminating memory hogging processes.

Safe System Reboot ¶

Safe system reboot with graceful termination of processes for avoiding data loss and file system damage.

This keybinding peforms the following sequence of operations.

reisub meneumonic:

See ¶