Sobes.tech
Middle+

What happens in Linux OS if we reach the RAM limit with the sound off?

sobes.tech AI

Answer from AI

The Linux operating system, when reaching the limit of RAM (OOM - Out Of Memory), triggers the OOM Killer. This is a kernel process that selects and terminates one or more processes consuming significant memory to free resources and prevent system hang. The selection of processes for termination is based on heuristics considering memory usage, process priority (oom_score), its age, and other factors. Muting the sound does not affect this mechanism.

The consequences of reaching the limit and the operation of the OOM Killer can vary:

  • Terminating a critical process: If the OOM Killer chooses a process vital for system operation (e.g., a shell or a process managing the graphical environment), it can lead to system instability or hang, requiring a reboot.
  • Terminating a user process: If a user process (e.g., a web browser, text editor) is terminated, the user will lose unsaved data in that application.
  • Temporary resource release: If one or more processes are successfully terminated, the system will temporarily free memory, allowing it to continue normal operation until memory is again exhausted.
  • Logging to system logs: Information about the OOM Killer activation and terminated processes will be recorded in system logs (e.g., dmesg or journalctl), enabling the administrator to analyze the cause of memory shortage.

You can check logs, for example, as follows:

# View the latest kernel messages, including information from the OOM Killer
dmesg | grep -i 'out of memory'

# View journald entries related to OOM
journalctl -xe | grep -i 'out of memory'

The behavior of the OOM Killer can be modified via /proc/sys/vm/oom_kill_allocating_task and /proc/<pid>/oom_score_adj.

# Disable the OOM Killer (not recommended in most cases)
echo 0 > /proc/sys/vm/oom_kill_allocating_task

# Set the oom_score_adj value for a process with PID 1234
# A higher value increases the likelihood of process termination
echo 1000 > /proc/1234/oom_score_adj

# A lower value decreases the likelihood of process termination
echo -1000 > /proc/1234/oom_score_adj