1 |
... |
2 |
>> That all makes perfect sense. So the reason a swap larger than maybe |
3 |
>> 1GB is not usually implemented is because idle processes don't |
4 |
>> normally have more than a few hundred MB of pages in memory? |
5 |
>> |
6 |
> That's not entirely true, either. For example, My laptop has 4GB of |
7 |
> swap. Why? Well, because I use hibernate and hibernate works on the |
8 |
> swap partition and I want to make sure that I have enough swap to write |
9 |
> all my memory to swap (actually It's now compressed so actually I |
10 |
> probablldon't really need that much). |
11 |
> |
12 |
>> Wouldn't a sufficiently large swap (100GB for example) completely |
13 |
>> prevent out of memory conditions and the oom-killer? |
14 |
> |
15 |
> No. oom killer kicks in when your system is out of virtual memory. |
16 |
> Consider this example: |
17 |
> |
18 |
> You have 4GB RAM |
19 |
> You have 0 swap. |
20 |
> Therefore you have a total of 4GB virtual memory. |
21 |
> |
22 |
> The second all your processes try to consume more than 4G of virtual |
23 |
> memory, oom killer will kick in* |
24 |
> |
25 |
> Consider the next example |
26 |
> |
27 |
> You have 4GB RAM |
28 |
> You have 100GB swap. |
29 |
> Therefore you have a total of 104GB virtual memory |
30 |
> |
31 |
> The second all your processes try to consume more than 104GB of virtual |
32 |
> memory, oom killer will kick in. |
33 |
> |
34 |
> Oom killer works on virtual memory (RAM + swap). So it doesn't matter |
35 |
> how much RAM you have or how much swap you have, when the total virtual |
36 |
> memory is consumed, oom killer is called. |
37 |
> |
38 |
> The secret is to not run out of virtual memory. |
39 |
> |
40 |
> There is no *easy* way not to run out of virtual memory. You either |
41 |
> don't consume as much VM, or you provide more VM (either through RAM or |
42 |
> swap). |
43 |
> |
44 |
> * This is not entirely true, the system also needs memory for the |
45 |
> kernel, buffers, hardware drivers, and other things which simply cannot |
46 |
> be paged out to disk, so the actual number will be less than the amount |
47 |
> of VM. |
48 |
|
49 |
You have all been very patient with me and I truly appreciate it. |
50 |
Let's see if I've got it. |
51 |
|
52 |
When the system is in a healthy state, swap is used to store pages of |
53 |
idle processes (which should not typically amount to more than about |
54 |
200MB) in order to free up as much RAM as possible for filesystem |
55 |
cache if nothing else. Linux will attempt to fill any unused RAM with |
56 |
filesystem cache. The system should be configured to assure it will |
57 |
not use an amount of memory greater than the amount of physical RAM, |
58 |
otherwise the system may run out of physical RAM. If this happens and |
59 |
the system has no swap, the system will initiate the oom-killer. If |
60 |
this happens and the system has swap, the system will thrash until it |
61 |
runs out of swap at which point it will initiate the oom-killer. |
62 |
Besides providing storage for idle process pages, when available |
63 |
physical RAM is depleted, swap gives the user some time to intervene |
64 |
before the oom-killer is initiated, although at that point the system |
65 |
will be in a state of thrashing. Too much swap will cause the system |
66 |
to thrash for a long time before the oom-killer is initiated which is |
67 |
not ideal. |
68 |
|
69 |
How did I do? Is there anything else I should keep in mind? |
70 |
|
71 |
- Grant |