Reputation: 21
How does the Linux kernel handle low memory conditions?
How can we prove that the new kernel is handling the low memory conditions well enough?
Is there any standard test for the same ?
Upvotes: 2
Views: 2420
Reputation: 446
The Linux Kernel Handles low memory conditions using the OOM(Out Of Memory) Killer
.
The strategy of OOM killer is to Kill some process or processes to allow allocating process get the memory that it needs.
In order to choose a process to kill, OOM killer calculates the value named Badness
. Then it selects the process with the maximum Badness to be killed. If the allocating process was chosen, OOM terminates its work. If some other process was chosen, OOM killer can be called more than once in case the previous run of the OOM killer did not free enough memory.
The process to be killed is chosen in such a way that
We can configure the OOM killer using the /proc/sys/vm/overcommit_memory
value
0-Heuristic memory overcommit (default setting)-Obvious overcommits of address space are refused
1-Always overcommit
2-Disable overcommit-When overcommit_memory is set to 2 ,the total address space commit for the system is not permitted to exceed swap + configurable percentage (overcommit_ratio -default is 50) of physical RAM
A simple way to prove linux handles OOM is to continuously allocate memory through malloc and memset the memory till the process runs out of memory and is killed(appears in dmesg).
Standard tests for Out Of Memory can be found in Linux Test Project (LTP)
available at LTP Source Forge
The tests are available in ltp/testcases/kernel/mem/oom
Upvotes: 9