[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Swap configuration for 16GB of RAM, 8 cores



agenkin@gmail.com wrote:
> What are the current best practices with regards to swap partitions?
> Is it better to create one big, or several smaller swap partitions?
> Is the rule of thumb still RAM*2 for the total size?

For a server I turn off Linux memory overcommit.  This avoids ever
having the out-of-memory killer run and kill random unrelated
processes.  Especially in a multiuser environment or in an enterprise
level environment this is very important.

But turning off overcommit means that the rule of RAM*2 comes back
into play.

Search the web for linux kernel out of memory killer and memory
overcommit and you will find much discussion about it.  Start here.

  http://lwn.net/Articles/104179/

  http://linux-mm.org/OverCommitAccounting

  http://www.redhat.com/magazine/001nov04/features/vm/

I recommend trying following in order to disable linux kernel memory
overcommit.  This will cause malloc() to fail when memory is
exhausted.  (The default is that malloc() and fork() will always
pass.)  This should avoid the linux kernel out of memory killer from
becoming active and killing random processes on the system.  This will
cause only the programs that are asking for more memory to fail.  This
is the traditional Unix memory model.  I recommend configuring servers
that need reliable operation this way.

  sudo sysctl -w vm.overcommit_memory=2

HOWEVER!  If you do not have enough virtual memory / swap space at the
time that you activate this configuration then it may cause your
system to be unable to fork() and malloc() starting at that moment.
If the system becomes unusable due to fork failure you may need to
reboot.  You must have enough virtual memory configured to handle all
of your expected simultaneously running applications.  Be careful that
you can reboot your server remotely if you do not have physical
access.

Since the above 'sysctl' test is a temporary configuration a reboot
will reset to the default allowing memory overcommit and enabling the
out of memory killer if the system runs out of memory and needs a
reboot to be saved.  If you decide that is a good configuration to
keep it memory overcommit disabled then it may be configured in
/etc/sysctl.conf to be set to off at boot time.  This is what I
recommend when there is enough virtual memory available.

Bob



Reply to: