Ubuntu swap partition size when using it as a hypervisor ( KVM in this case ).

Posted on 2014-09-19
Last Modified: 2016-07-22
I am in the middle of a medium sized virtual deployment of a virtual environment.  Currently i have Ubuntu 12.04 LTS installed on a bunch of servers with dual 6 core procs and 96GB of ram.

The age old question in linux is... Do i need the swap partition?  From what i know, for ubuntu desktops with anything over 6GB, its a no.  But my issue here is that we are looking at a hypervisor role.  I have another small cluster of 5 hosts and 70 VMs running on VMWare ESXi, it doesnt use swap as far as i can tell.  Those machines are booted off 8GB USB drives with no local storage and 128GB of ram, so hence my assumption there is no swap.

Anyhow, i was researching the question on the web and the only definitive thing i can find is this red hat document saying that the KVM hypervisor running on redhat needs 16GB of swap space for machines with more than 64GB of memory.  

To further muddy the waters, we are using raid 1 SSDs for OS install on these servers, so i really wonder if 16GB is a must.  To me, wasting 16GB of hard drive space on SSDs is just bad form.  On the other hand, having virtual machines crash because they ran out of Memory is a no go.  It seems Red Hat is saying that its for safety, which of course would mean that it should be done when talking about a production environment.  

So with everything said, do we really need the swap, could we get away with smaller or should we just adhere to what Redhat is saying in their guide?  Please dont answer with a simple yes/no, explain in as much detail as possible your answer.  Examples/experiences welcome!

The next question goes hand and hand with this.  If we are spinning up virtual Ubuntu 12.04 servers on top of this, do they need swap files as well?  Most of those servers will have 2-8GB memory assigned.  In my vmware environment, i let the virtual slackware machines have their swap, but just because i have been doing it that way, doesnt mean its right.  So again, can i do a small swap file for the virtuals, elminate it or must i stick with the standard recommendation for the swap?  As before, please dont answer with a simple yes/no, explain in as much detail as possible your answer.  Examples/experiences welcome!
Question by:Icetoad
  • 4
  • 2

Accepted Solution

nattygreg earned 250 total points
ID: 40333987
I run Ubuntu and I always do a swap partition, makes everything run smooth without any hiccups. next thing is that you can have the swap partition on another drive you do not want to use up 16 gig of the SSD. However I prefer to run the swap on the same drive.

Always use a swap it is 100% recommended
LVL 61

Assisted Solution

gheist earned 250 total points
ID: 40335023
You should always have swap as an indication that you run short on VM memory.
It can be zram if your disks are low grade, but 1GB swap partition will not hurt even a laptop disk.

Author Comment

ID: 40361456
Not exactly the answers i was looking for....   more detail is desired( per the original question).  Looking for experience with servers and virtualization in the linux realm.
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

LVL 61

Expert Comment

ID: 40361580
Why you ask us if you think we are so short-brained?

Best use of SSD is all sorts of flash cache while real data is on something slower.
LVL 61

Expert Comment

ID: 41713511
Please split between all participants since we were asked for opinions....

Assisted Solution

Icetoad earned 0 total points
ID: 41713585
That would be fine as i didn't mean to offend.  I was looking more at do i need the size to be 16GB ( really that size? )  or could it be smaller, like say 1GB, even if i have 48GB of memory.  Wondering if anyone had tried this in production or test and if the servers tended to crash or go unstable.  Also, if not 1GB, would 4GB work?  Basically, if as it seems, the swap is necessary, then what would be the minimum required(or suggested) for stability?

For the time being, i have left the swap partitions in place.  Its just annoying to waste the space when with VMWare you dont need to waste space on a swap partition.  With my setup, this is a pretty large caveat for using KVM instead of VMWare.

Most of the instances are disposable, which is why all the OSs are loaded locally instead of from a central SAN/NAS unit.
LVL 61

Expert Comment

ID: 41724206
Swap is used to save kernel memory dumps (thats where the idea of SWAP==RAM comes from)
Then it is used for hibernation of laptops.
For use as a general purpose RAM it is way too slow (or SSD wearing where it iss faster)

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

HOW TO: Connect to the VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere (HTML5 Web) Host Client 6.5, and perform a simple configuration task of adding a new VMFS 6 datastore.
Fine Tune your automatic Updates for Ubuntu / Debian
Teach the user how to edit .vmx files to add advanced configuration options Open vSphere Web Client: Edit Settings for a VM: Choose VM Options -> Advanced: Add Configuration Parameters:
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now