Max swap size?

Stuart Jansen sjansen at
Thu May 29 00:24:09 MDT 2008

On Wed, 2008-05-28 at 20:36 -0600, Stephen Ward wrote:
> Does a 4 GB swap partition seem excessively large to anyone?

Once upon a time the standard recommendation for swap was "2 x RAM" but
the Linux virtual memory model has come a long way from original Unix.
For example, technically swap isn't used for "swapping" these days but
instead more efficient "paging". With shared pages, copy-on-write,
overcommit, etc. the ancient wisdom that gave us the "2 x RAM" rule
simply doesn't apply anymore. So an updated rule is "1.5 x RAM", but
that still leads to crazy large swap. My personal rules is "never more
than 1GB swap (on a server)".

Of course, life is rarely simple. Linux uses swap for hibernation
(suspend to disk). If swap is smaller than RAM, you won't be able to
hibernate so "1.5 or 2 x RAM" on a laptop may be appropriate.

As for a server, if you're actually using >1GB swap you're system will
be so dog slow it'll be unusable. Unless of course we're talking a very
long running server and a program that allocates lots of memory, shoves
data into it, but rarely reads from it. Not very realistic, and not
great software design, but one possible reason for creating a huge swap

Although it is possible for Linux to run without any swap at all, doing
so is less efficient. The Linux kernel will manage memory more
aggressively when it knows that swap is available in an emergency.

And while we're on the topic of Linux memory management, I'm going to
mention a surprising feature that many don't know about: the OOM killer.
When the kernel is about to run out of memory (OOM) it has only two
options (1) dead lock hard or (2) kill a process to free memory.
Obviously #1 isn't a good options, so Linux does #2. The kernel does
it's best to pick either the process causing the problem, or an
unimportant process, but it sometimes guesses wrong. You can turn off
the OOM killer, but you probably shouldn't. Instead, just make sure you
have enough RAM+swap.

More information about the PLUG mailing list