Senin, 30 November 2009

OOM in linux

If the Linux system running out of memory, or a condition called OOM (out of memory), then the "OOM killer" Linux kernel will work, kill the processes of "random" (actually, the processes that deserve to be killed according to certain criteria) to a number of memory is freed and the system can continue to return. But the problem is, sometimes an important process that can be killed. For example: xlock (for lock X session), as a result of our X session to be open by itself. This is fatal, because if we leave our workstations we are the key, so it can open. Another example is the sshd on the remote server, so we lose the remote access server for the.

To overcome this problem, there are several ways / approaches.
Contents

* 1 Panic and automatic reboot
* 2 Setting kernel overcommit
* 3 oom_adj
* 4 References / links

Panic and automatic reboot

We can choose if there OOM condition, automatic kernel panic and reboot it. To do this:

# Echo 1> / proc / sys / vm / panic_on_oom
# Echo 5> / proc / sys / kernel / panic

This means that, within 5 (five) seconds after a kernel panic, direboot automated system. Note: if the kernel or a total hang the machine, of course not automatic reboot. Automatic rebooting could have done if the kernel panic (fatal error) but the kernel is still alive.

To make this setting permanent, add the line:

vm.panic_on_oom = 1
kernel.panic = 5

to / etc / sysctl.conf.

Note: the automatic settings can also be added to the kernel options, namely "panic = N '. In this way we can choose whichever kernel you want to be given this setting and which ones do not. To use the kernel options for autoreboot kernel panic, throw back the line "kernel.panic = 5" from / etc / sysctl.conf and edit / boot / grub / menu.lst and add "panic = 5" in position as below. Note that this menu.lst specific format that will be processed by a script, so the line "kopt =..." after the added "panic = 5" keep dikomen, will be automatically added to each entry is the kernel after we run the script update-grub.

# # # BEGIN AUTOMAGIC kernels LIST
# # Lines between the AUTOMAGIC kernels LIST markers will be modified
# # By the debian update-grub script except for the default options below

# # Uncomment NOT DO THEM, Just edit them to your needs

# # # # Start Default Options # #
# # Default kernel options
# # Default kernel options for automagic boot options
# # If you want special options for specific kernels use kopt_x_y_z
# # Where x.y.z is kernel version. Minor versions can be omitted.
# # E.g. kopt = root = / dev/hda1 ro
# # Kopt_2_6_8 = root = / dev/hdc1 ro
# # Kopt_2_6_8_2_686 = root = / dev/hdc2 ro
# Kopt = root = / dev/hda1 ro panic = 5

Then run update-grub and reboot the kernel.
Setting kernel overcommit

In addition to the first by the panic + autoreboot, we can also set the memory overcommit settings.

# Echo 2> / proc / sys / vm / overcommit_memory

To make this setting permanent, add this line in / etc / sysctl.conf:

vm.overcommit_memory = 2

and reboot the kernel.

This setting prohibits excessive memory allocation by the processes so that the effect of processes not in-kill in OOM conditions but will receive an error message out of memory. For more details, see the Linux kernel documentation in Documentation / vm / overcommit-accounting.

We have a system that uses Spanel 1.2 set using this setting.
oom_adj

Specific processes can be protected from the "massacre" by the OOM by setting:

# Echo -17> / proc / / oom_adj

where is the process ID concerned. Child process will inherit these settings oom_adj.

Note: the Spanel 1.2, boot script / etc / init.d / ssh has added the following lines like this:

echo -17> / proc / `cat / var / run / sshd.pid` / oom_adj

protecting sshd from OOM killer.
References / links

* Documentation Linux kernel VM subsystem (subdirectory Documentation / vm)
* Search engines with keywords such as:
o oom handling condition on linux
o oom_adj
o oom_pardon (another unofficial patch in Linux to protect the process from the OOM killer; who entered Linux is oom_adj)
o automatic kernel panic reboot

Tidak ada komentar:

Posting Komentar