13.3 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();
badness_for_task = total_vm_for_task /
(sqrt(cpu_time_in_seconds) * sqrt(sqrt(cpu_time_in_minutes)))
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.