Linux: don't create swap partition?

Modern operating systems require a swap space to make efficient use of RAM. Even if your system has plenty of RAM, wasting RAM results in a smaller buffer cache, which means increased disk I/O. So no matter how much RAM you have, you still want the system to use it efficiently. Using it efficiently means getting things out of RAM that are extremely unlikely to ever be accessed.

When you start up a typical system, a large number of services start up. Programs run initialization code and modify private memory mappings in the process. A number of these services will never run again. Many of them won't run for hours. Without swap, the OS has no choice but to keep the modified private memory mappings associated with those services in RAM forever. That's RAM that can never be used as disk cache.

So you want swap whether you need it or not.


I've been running a desktop system without any swap for a couple years, and it's been going great! There are a few behaviours that are different; some of these are advantageous and some might harm you. It all depends on what you're doing.

One major difference is how the system behaves when memory runs out:

If there is no swap partition, the OOM killer runs immediately. If you've got a program leaking memory, that's likely to be the one that gets killed. That happens and you recover the system nearly instantly.

If there is a swap partition, the kernel pushes the contents of memory into swap. Errant process can continue allocating memory. This keeps happening until swap runs out, which could be ten minutes to an hour if you have a big swap partition. While it's doing this, your system slows to a crawl. It becomes impossible to open a terminal and kill the process. I usually unplug the power cord when this happens.

So, since I'm going to lose my data anyways when the system OOMs, I prefer the former option to at least have a (high) chance of recovery.


Swap is required for hibernation, otherwise you can get by without it just fine.