What is swap for?

As we’ll see, there are basically four different purposes for swap :

  • Some programs really are memory-consuming.
  • Extra memory might come in handy.
  • Optimizing memory usage.
  • Hibernation (suspend-to-disk)

To begin with, let’s say that computers have changed a lot since swap was first used :

  • At first, swap was needed to extend real memory capacity. You would use swap so that the available memory would be the addition of the RAM space and the swap space.
  • Nowadays, RAM are often big enough so that we could use the computer without any swap at all.

Some programs really are memory-consuming :

  • Sometimes, something big (like MySQL, Apache, PHP Handler etc) make the entire system need extra memory.
  • In these cases, swap will be used to make the system able to handle the extra load.

Extra memory might come in handy :

  • Unforeseeable events, might and will happen (a program going crazy, some action needing much more space than you thought, or any other unbelievable combination of events).
  • In these cases, swap will give you an extra delay to figure out what happens or to finish something.

Swap can optimize memory usage :

  • Hard drives are considerably slower than RAM. So when you need a file (be it a data file, like this video you’re watching again and again, executables, like Firefox, or libraries), the Linux kernel reads the file into RAM and keeps it there so than the next time you need it again, it’s already in RAM and data access is much faster (thousands of times faster). We call these portions of RAM that accelerate disk read “cached memory.” They make a huge difference in terms of responsiveness.
  • The Linux kernel automatically moves RAM reserved by programs but not really used in swap so that this RAM can serve the better purpose of having more cached memory.

Hibernation needs swap

  • The hibernation feature (suspend-to-disk) writes out the contents of the memory to the swap partition before turning off the machine. Therefore, your swap partition should be at least as big as your RAM size. The hibernation implementation currently used in Ubuntu, swsusp, needs a swap or suspend partition, and can not use a swap file on an active file system.

Do I Need a Swap Partition and If So, How Big?

A computer running GNU/Linux generally has a few different partitions on it (not including any Windows or other OS dual boot scenarios). There’s usually a small Master Boot Record (MBR) partition which houses your boot loader (usually GRUB or Lilo); a system partition which houses your actual OS (usually quite large), and there’s usually a swap partition.

I have another paritition which I use as my home directory, but that’s kind of a specialized, yet common, set up.

The swap partition is used to help your system run faster. When your system runs out of physical RAM during operations, it uses the swap partition as RAM and writes little bits of stuff that is currently in RAM, but not needed, to the swap partition. This allows you to run more programs at once. The alternative to having swap is…well…not having swap. In this scenario, when you’ve opened up enough applications that your physical memory fills up, there’s no place to write the overflow and your system will bog down quite miserably.

Most modern OSes have some sort of swap facility. In Windows this is referred to as the pagefile, and I’m not sure what it’s referred to as on a Mac.

So, the answer seems obvious, doesn’t it? Swap is good. You should have swap and worship it every day.

I can’t argue with that. Swap is good, but in many systems it’s not necessary. I discovered this completely by accident one day. I muffed up the partitioning when I installed Kubuntu and didn’t allocate a swap partition. The funny thing is that I didn’t notice for months and when I did notice it was by conversing with someone who asked me something about my swap, not due to any system performance issues.

Prior to this incident, I didn’t think it was possible to run a GNU/Linux box without swap, but it turns out that not only is it possible, some people do it on purpose.

In the home/desktop world, if you have a GB of RAM or more, your system may never swap anything out. The recommendations for allocating swap is anywhere from 1.5 to 2 times the amount of physical RAM on your system. On some systems, losing 2 to 3 GB of disk space might be a considerable loss and therefore not worth it.

In the server world, running without swap is propbably suicidal. Don’t do that.

If you’re curious, check out your swap usage now and again. With KDE you can use KDE System Guard and there are some gDesklets available for Gnome (and possibly a built in application as well, not sure) to view your swap usage.

Source : (Ubuntu Community –, (Jon –

This entry was posted on Sunday, January 18th, 2009 at 9:46 pm and is filed under Informasi IT. You can follow any responses to this entry through the RSS 2.0 feed.
Tentang BOC Indonesia
Sejak tahun 2003 sebagai perusahaan penyedia domain name ekstensi internasional dan Indonesia, serta penyedia web hosting datacenter Indonesia, Singapura dan USA. Layanan lain adalah website developer dan konsultan internet marketing.

Proposal Domain name dan web hosting

Workshop Digital Marketing - DONGKRAK