Ubuntu – a “Swap Area”


So I noticed this question has not been asked directly;

What is this "Swap Area" people keep referring to when it comes to installing Ubuntu?

Best Answer


The Swap Area is just fake RAM that lives on your hard drive. It is much slower than actual RAM, but is necessary in many cases to keep a computer running normally. A good rule of thumb is to have as much swap space as you do normal RAM.


Your computer has a couple different kinds of memory that we need to talk about. Your files and operating system are stored on your hard drive (commonly HDD). This is relatively slow and cheap, but is persistent between system shutdowns. Your computer also has RAM (Random Access Memory) which is much faster, more expensive, and loses its contents when your computer loses power. In order to run a program, it is first copied from your HDD to your RAM (which is much faster) so that it can execute in close to real time.


However, we should ask the question: what happens if you run out of RAM but want to open another program? The answer isn't good; your computer freezes until there is enough RAM to complete the operation (this is commonly called "thrashing"). Although you might only have a few Gigabytes of RAM, most computers have more HDD space than they know what to do with. So we can use some of that extra space as fake "RAM" in a pinch. That is what swap space is; emergency RAM that lives on your hard drive.

Swap lives on your hard drive

Now that we have some swap space on our hard drive, running out of RAM isn't as big of a deal. Now when we run out and wish to open another program, the operating system looks through all of the open programs currently in RAM, and chooses one that hasn't been used for a while. It then copies that program out of RAM and stores it in swap space, freeing up room for the new program. If in the future we want to access the "swapped out" program, the operating system simply copies it back to RAM, potentially swapping out other programs in the process.

Partition vs. File

When creating a swap space, you have two choices. You can make a separate partition on your hard drive, which is recommended in Ubuntu and necessary if you wish to hibernate your system. Or, you can create a Swap File (called the Pagefile in Windows) on your hard drive. Technically a swap partition will out-perform a swap file, but the difference will likely be negligible. Also note that if you have multiple linux distributions on the same hard drive, they can share a single swap partition (swap partitions do not have a file system).


If you are installing Ubuntu for the first time, you might as well make a swap partition. This is the default in the Ubuntu installer, and also my personal recommendation. On the other hand, if you do not have any swap space and would like to add some after installation, it may be much easier and faster to use a swap file.

In terms of size, if you have no idea how big to make it, a good baseline (and the default in the Ubuntu installer) is to have the same amount of swap as you do RAM. That being said, this is only a very general guideline, and depends on how you use your system. There is nothing wrong with having no swap space. If you start running out of RAM, just make your swap space larger.

See also

Related Question