...
>> That all makes perfect sense.  So the reason a swap larger than maybe
>> 1GB is not usually implemented is because idle processes don't
>> normally have more than a few hundred MB of pages in memory?
>>
> That's not entirely true, either.  For example, My laptop has 4GB of
> swap. Why?  Well, because I use hibernate and hibernate works on the
> swap partition and I want to make sure that I have enough swap to write
> all my memory to swap (actually It's now compressed so actually I
> probablldon't really need that much).
>
>> Wouldn't a sufficiently large swap (100GB for example) completely
>> prevent out of memory conditions and the oom-killer?
>
> No.  oom killer kicks in when your system is out of virtual memory.
> Consider this example:
>
> You have 4GB RAM
> You have 0 swap.
> Therefore you have a total of 4GB virtual memory.
>
> The second all your processes try to consume more than 4G of virtual
> memory, oom killer will kick in*
>
> Consider the next example
>
> You have 4GB RAM
> You have 100GB swap.
> Therefore you have a total of 104GB virtual memory
>
> The second all your processes try to consume more than 104GB of virtual
> memory, oom killer will kick in.
>
> Oom killer works on virtual memory (RAM + swap).  So it doesn't matter
> how much RAM you have or how much swap you have, when the total virtual
> memory is consumed, oom killer is called.
>
> The secret is to not run out of virtual memory.
>
> There is no *easy* way not to run out of virtual memory.  You either
> don't consume as much VM, or you provide more VM (either through RAM or
> swap).
>
> * This is not entirely true, the system also needs memory for the
> kernel, buffers, hardware drivers, and other things which simply cannot
> be paged out to disk, so the actual number will be less than the amount
> of VM.

You have all been very patient with me and I truly appreciate it.
Let's see if I've got it.

When the system is in a healthy state, swap is used to store pages of
idle processes (which should not typically amount to more than about
200MB) in order to free up as much RAM as possible for filesystem
cache if nothing else.  Linux will attempt to fill any unused RAM with
filesystem cache.  The system should be configured to assure it will
not use an amount of memory greater than the amount of physical RAM,
otherwise the system may run out of physical RAM.  If this happens and
the system has no swap, the system will initiate the oom-killer.  If
this happens and the system has swap, the system will thrash until it
runs out of swap at which point it will initiate the oom-killer.
Besides providing storage for idle process pages, when available
physical RAM is depleted, swap gives the user some time to intervene
before the oom-killer is initiated, although at that point the system
will be in a state of thrashing.  Too much swap will cause the system
to thrash for a long time before the oom-killer is initiated which is
not ideal.

How did I do?  Is there anything else I should keep in mind?

- Grant

Reply via email to