Skip to content

Commit

Permalink
Add notes for section 13.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo-stoakes committed May 10, 2016
1 parent e94f44b commit c328acd
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions 13.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,38 @@ reset:
this, we want to avoid killing a process as much as we can which is why there
are checks in the first instance.
## 13.3 Selecting a Process
* [select_bad_process()][select_bad_process] determines the process to kill by
stepping through each running task and calculating how suitable it is for
killing via the function [badness()][badness], which determines this via:
```
badness_for_task = total_vm_for_task/(cpu_time_in_seconds^0.5 * cpu_time_in_minutes^0.25)
```
* The square roots are approximated by [int_sqrt()][int_sqrt].
* This has been chosen to prefer a process that is using a large amount of
memory but is not that long-lived. Long-lived processes are unlikely to be the
cause of memory shortage.
* If the process is a root process or has `CAP_SYS_ADMIN` capabilities, the
points are divided by 4 since it is assumed that privileged processes are
well-behaved.
* Similarly, if the process has `CAP_SYS_RAWIO` capabilities (access to raw
device), the points are further divided by 4 because it's not a good idea to
kill a process that has direct access to hardware.
[brk]:http://man7.org/linux/man-pages/man2/brk.2.html
[mremap]:http://man7.org/linux/man-pages/man2/mremap.2.html
[out_of_memory]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/mm/oom_kill.c#L202
[vm_enough_memory]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/mm/mmap.c#L53
[swapper_space]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/mm/swap_state.c#L39
[dentry]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/include/linux/dcache.h#L67
[inode]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/include/linux/fs.h#L438
[select_bad_process]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/mm/oom_kill.c#L121
[badness]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/mm/oom_kill.c#L40
[int_sqrt]:https://github.com/lorenzo-stoakes/linux-historical/blob/v2.4.22/mm/oom_kill.c#L26

0 comments on commit c328acd

Please sign in to comment.