7

I've just installed Ubuntu 15.04 on a new 240GB SSD, and immediately noticed that /dev/ubuntu-vg/swap_1 on the resulting installation is 137GB. That seems excessive, even counter-productive, but perhaps the Ubuntu installer chose that since the machine has 128GB of RAM.

Does anyone have a strong sense of whether it is useful to have ~140GB of swap, and if not, what a suitable size for the swap should be? I do run I/O heavy binaries. Though it may not be relevant I will note that the machine is dual CPU Xeon (E5).

Having consulted the link suggested below by Terrance, I am tempted to reduce the automatic ~140GB of swap to ~4GB, as it is taking up more than half of the 240GB SSD on which Ubuntu is installed!

2 Answers2

2

With that much RAM on a system, there really shouldn't be a need for a large swap partition. Most of what it would be needed for is to swap info out of the RAM that maybe dirtied up and needs to be swapped, but anywhere from 4GB to 16GB should be sufficient enough.

Great information from the link below.

https://superuser.com/questions/777907/swap-partition-size-on-a-64-gb-ram-computer-for-memory-intensive-work

Terrance
  • 41,612
  • 7
  • 124
  • 183
1

While the amount of swap you need is always dependent on your workload, that is certainly an excessive amount of swap and almost certainly can be attributed to an overly-simplistic "swap = RAM * x" type calculation.

Short answer: in my opinion, 4GB swap is almost always more than enough.

Long answer: Swap is always designed to stand-in for times where your system is operating abnormally - that is, your RAM usage by processes is nearing or exceeding the amount of physical RAM you have. If the processes you are running use a very predictable amount of RAM (eg a database server that you've configured a certain heap limit) then your RAM use is going to be somewhat stable and swap is unlikely to ever be used. If you are certain that RAM use by processes will never near or exceed physical RAM, you don't even need any swap. But on a typical server, there is usually the random possibility that tasks will run which eat up large amounts of memory for a certain period, and when this causes RAM usage to near or exceed physical RAM, swap will step in and save your system from killing processes or running out of enough cache space to run efficiently.

I say that 4GB swap is usually more than enough swap even on a system with a large amount of RAM, because I feel as if that's enough for 1 or 2 relatively memory-hungry processes to exceed physical RAM by if your system is already working near its limit. I feel as though if your are in deficit by more than 4GB, something a lot more serious is wrong which would need to be fixed by configuring your memory-hungry processes. Processes which occupy significantly more than 2GB RAM will usually be programmed to somehow self-limit their RAM use either by configuration or by being intelligent about how much physical RAM is remaining.

Other opinions on how much swap is "more than enough" will vary of course. Some will say 1GB, 2GB, 8GB, etc. Some will say you don't need any with that much physical RAM (but I'd disagree).

One more thing: "hibernation" requires enough swap space to write all process memory, so if your swap space is significantly smaller than physical RAM you are not going to be able to hibernate. On a system with 128GB RAM, you probably won't want to hibernate anyway - reserving that much swap space just for the privilege of hibernating would not only eat significantly into your disk space (especially for an SSD) it would also be pretty slow - imagine loading ~128GB from disk on resume, that would be significantly slower than just a normal boot.

thomasrutter
  • 36,774
  • Thanks Thomas for the detailed, thoughtful answer. While I've been using the new system I have noticed that swap usage is at 0 bytes even for computationally intensive bouts, so I agree with your assertion that ~4GB of swap should be 'more than enough'. – Kevin Cain May 24 '15 at 06:00