1 |
On Friday, July 22 at 11:13 (-0700), Grant said: |
2 |
|
3 |
> That all makes perfect sense. So the reason a swap larger than maybe |
4 |
> 1GB is not usually implemented is because idle processes don't |
5 |
> normally have more than a few hundred MB of pages in memory? |
6 |
> |
7 |
That's not entirely true, either. For example, My laptop has 4GB of |
8 |
swap. Why? Well, because I use hibernate and hibernate works on the |
9 |
swap partition and I want to make sure that I have enough swap to write |
10 |
all my memory to swap (actually It's now compressed so actually I |
11 |
probablldon't really need that much). |
12 |
|
13 |
> Wouldn't a sufficiently large swap (100GB for example) completely |
14 |
> prevent out of memory conditions and the oom-killer? |
15 |
|
16 |
No. oom killer kicks in when your system is out of virtual memory. |
17 |
Consider this example: |
18 |
|
19 |
You have 4GB RAM |
20 |
You have 0 swap. |
21 |
Therefore you have a total of 4GB virtual memory. |
22 |
|
23 |
The second all your processes try to consume more than 4G of virtual |
24 |
memory, oom killer will kick in* |
25 |
|
26 |
Consider the next example |
27 |
|
28 |
You have 4GB RAM |
29 |
You have 100GB swap. |
30 |
Therefore you have a total of 104GB virtual memory |
31 |
|
32 |
The second all your processes try to consume more than 104GB of virtual |
33 |
memory, oom killer will kick in. |
34 |
|
35 |
Oom killer works on virtual memory (RAM + swap). So it doesn't matter |
36 |
how much RAM you have or how much swap you have, when the total virtual |
37 |
memory is consumed, oom killer is called. |
38 |
|
39 |
The secret is to not run out of virtual memory. |
40 |
|
41 |
There is no *easy* way not to run out of virtual memory. You either |
42 |
don't consume as much VM, or you provide more VM (either through RAM or |
43 |
swap). |
44 |
|
45 |
* This is not entirely true, the system also needs memory for the |
46 |
kernel, buffers, hardware drivers, and other things which simply cannot |
47 |
be paged out to disk, so the actual number will be less than the amount |
48 |
of VM. |