On a VMware ESX setup what is the difference of these options?:
- a Linux VM with 1GB RAM and 1GB swap partition and the VM uses 1.5 GB ram
- a Linux VM with 1GB RAM and no swap partition and the VM uses 1.5 GB ram
I mean, in both cases swap is being used;
- in the first swap is done to the linux swap partition
- in the second case, VMware will swap 512MB to the VMware storage pool.
So are there any point in giving Linux VM's a swap partition?
Ignoring the fact that people are dealing with OS specific reasons I have two reasons why it's a bad idea to not run with a swap partition/file.
Yes. It is the Unix way.
Unix (even Linux) expects to be able to swap.
Bad Things happen when the system can't swap (either because it was misconfigured without a swap partition or because the swap space is full). In Linux one of these Bad Things is the Out Of Memory Killer, which will plunge a knife into the back of the program it thinks is using the most RAM (database servers are a favorite target).
What do you have
/proc/sys/vm/overcommit_memory
set to? From the kernel documentation:Thus if you are using 1 there is no difference. If you are using 2 and no linux swap file then no process will be able to allocate 512M of (virtual) memory. The outcome isn't clear for 0.
Edit: From http://utcc.utoronto.ca/~cks/space/blog/linux/LinuxVMOvercommit this is how 0 works:
So it uses swap in the calculation as well. In general I'd follow the RHEL recommendation of :
Swap partitions can be potentially faster, especially in situations where the root disk is nearly full and you can't create a swap file in one piece without fragmentation, let alone the overhead that might be created by the filesystem and, if applicable, things like LVM.
But the performance of both machines will suck anyway if you keep 33% of your memory requirements on the disk.
Please see the following link- https://help.ubuntu.com/community/SwapFaq
Basically, unless you need hibernate or using more memory than you're allocating to the VM, there is no significant advantage to a swap partition.
I haven't used a swap partition/file on any of my linux machines for years.
The obvious advantage for swap is that when your machine crashes you can still create a crash dump. Correct me if I'm wrong, but afaik this isn't possible without swap. This isn't VMWare specific of course but rather applies anywhere. I felt like it might be important to point out.