next up previous contents index
Next: Bibliography Up: understand-html Previous: 10.8 Swapping Out Process   Contents   Index

11. Out Of Memory Management

When the machine is low on memory, old page frames will be reclaimed (See Chapter 11 but during the process is may find it was unable to free enough pages to satisfy a request even when scanning at highest priority. If it does fail to free page frames, out_out_memory() is called to see if the system is out of memory and needs to kill a process.



\includegraphics[width=7cm]{graphs/out_of_memory.ps}
Figure: Call Graph: out_of_memory


Unfortunately, it is possible that the system is not out memory and simply needs to wait for IO to complete or for pages to be swapped to backing storage so before deciding to kill a process, it goes through the following checklist.

It is only if the above tests are passed that oom_kill() is called to select a process to kill.

11.0.1 Selecting a Process

The function select_bad_process() is responsible for choosing a process to kill. It decides by stepping through each running task and calculating how suitable it is for killing with the function badness(). The badness is calculated as follows, note that the square roots are integer approximations calculated with int_sqrt();


\begin{displaymath}badness\_for\_task = \frac{total\_vm\_for\_task}
{\sqrt(cpu\_time\_in\_seconds) * \sqrt[4](cpu\_time\_in\_minutes)} \end{displaymath}

This has been chosen to select a process that is using a large amount of memory but is not that long lived. Processes which have been running a long time are unlikely to be the cause of memory shortage so this calculation is likely to select a process that uses a lot of memory but has not been running long. If the process is a root process or has CAP_SYS_ADMIN capabilities, the points are divided by four as it is assumed that root privilege processes are well behaved. Similarly, if it has CAP_SYS_RAWIO capabilities (access to raw devices) privileges, the points are further divided by 4 as it is undesirable to kill a process that has direct access to hardware.

Once a task is selected, the list is walked again and each process that shares the same mm_struct as the selected process (i.e. they are threads) is sent a signal. If the process has CAP_SYS_RAWIO capabilities, a SIGTERM is sent to give the process a chance of exiting cleanly, otherwise a SIGKILL is sent.



Subsections
next up previous contents index
Next: Bibliography Up: understand-html Previous: 10.8 Swapping Out Process   Contents   Index
Mel 2003-01-14