Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I was wondering since I heard that swap is used when you're out or RAM and and swapping too much is bad, since I have a lot of RAM ( 8GB )....

what if I dont create a swap partition?

Also, do I need it for hibernation or it isn't a must?

share|improve this question
    
you must create swap, i once tried not to create swap, couldn't proceed the installation –  Fischer Sep 1 '13 at 20:02
    
what happens when you install inside windows? I did that and it also seemed a bit slow for my rig compared to windows, but I didn't create the partition –  Mihai Bratulescu Sep 1 '13 at 20:07
    
I never tried installing a Linux inside windows, I always create a separate partition –  Fischer Sep 1 '13 at 20:41

5 Answers 5

up vote 3 down vote accepted

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.

share|improve this answer
2  
"So you want swap whether you need it or not." -- Seems like you made the case that he needs swap whether he wants it or not. –  sawdust Sep 2 '13 at 0:50

It is a common misconception to think having a swap area negatively affects performance. What does severely affects performance is not having enough RAM. Swap area per se have no negative effect on performance unless you do not care about reliability. It can have a positive impact on performance even while you think you have enough RAM (and no RAM shortage is reported).

There are essentially three cases to consider:

  • 1: There is enough RAM for internal kernel needs, for all your applications to have their working set of pages on RAM and still have "free" RAM for the buffer cache to store most of the file system hot data.

  • 2: same as the above except you have not enough free RAM for the buffer cache to be fully efficient.

  • 3: There is not enough RAM to even store your applications used pages.

In case 1, which should be the norm for a production machine, having a swap area or not doesn't change anything (at least on Linux based OSes and other OSes that over-commit memory).

In case 2, having a swap area might improve the overall performance by allowing the system to page out very infrequently used pages and then allow the buffer cache to better play its role.

In case 3, having a swap area allows application to keep on running at the expense of a performance degradation due to pagination. On the other hand, missing a swap area (or a large enough one) will make applications crash randomly. Additionally, depending on OS settings, the OOM killer might also decide to kill the most memory hungry applications if there is a strong RAM demand without even giving them a chance to save their (your) critical data.

This latter case is one with which you have to make a choice. There are certainly some use cases where having processes being killed is the preferred option like systems where response time is crucial and where losing a transaction / process is no big deal.

However, I tend to believe in most situations, it is better to be able to let a chance for the user/administrator to notice the RAM shortage and act accordingly without risking losing data.

share|improve this answer

If you don't want to use a swap partition, you can use a swap file: a filesystem image stored on a regular file and used as your swap space.

The following articles explain how to do it in detail:

share|improve this answer
    
what is the difference between a swap file and a swap partition? and what would happen if I have none? –  Mihai Bratulescu Sep 1 '13 at 20:33
    
speed of access.... –  mdpc Sep 1 '13 at 20:38
2  
If used YES it is quite significant. If you use a partition, it is simple addressing, if you use a file, you have to do all the filesystem overhead to use a swap file and you CANNOT guarantee where on the disk the segments will reside. –  mdpc Sep 1 '13 at 20:46
1  
@mdpc File system overhead is negligible starting from kernel 2.6. Metadata, cache and file system code is bypassed. Raw disk blocks are simply directly accessed. –  jlliagre Sep 1 '13 at 22:22
1  
@mdpc A swap file shouldn't be significantly fragmented if at all, unless you create it lately. Moreover, swap access is rarely sequential but mostly random due to how demand paging works so fragmentation shouldn't be that a problem. –  jlliagre Sep 1 '13 at 22:50

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

share|improve this answer
    
Thus the size of the swap area should be a little over the size of the memory installed in your system. –  mdpc Sep 1 '13 at 21:16
    
@mdpc, not necessarily; it just has to be large enough to hold the used ram that can not be discarded ( i.e. data backed by a file on the disk ). –  psusi Sep 1 '13 at 21:24
    
and how would you estimate that on the creation? Wouldn't you so the proper planning and prepare for the worse case as partitioning is generally a pain to change after it is set? –  mdpc Sep 1 '13 at 22:07

It's a bit dangerous but you CAN run without a swap space. But if you finally exceed the amount of memory you have your system will nearly immediately crash without notice.

What swap gives you basically is an extended but far slower for your memory. If you exceed you will start swapping, it will really take the life out of your system....HOWEVER by killing off the errant processes you can still save your system.

Some programs insist on allocating (but not using) swap space, some of these are database programs if I recall. Again, by not having swap space you might limit the programs that may be run.

Finally, look SWAP is CHEAP in the fact that you do not have to backup the area. (I'm hoping that you are one of these fine outstanding sysadmins who backup their systems).

So create it.

My rule of thumb used to be 2*memory-size.....but now adays I am ok in many cases with 1*memory-size but generally use 1.5*(memory-size). You don't have to create this great of an amount, but I would...especially if there is any production type of work you are doing.

Oh yes, and for hibernation, swap is REQUIRED to hold a total image of memory. And thus the size if you are considering h8ibernation should be AT LEAST (1*memory-size)+100MB..the 100 MB is for possible overhead needed in the process.

share|improve this answer
    
so... for some programs you kind of need a swap area for them to run? I'm not worried of running out of ram with 8GB (though not impossible) –  Mihai Bratulescu Sep 1 '13 at 20:53
    
The 2x memory size rule is old and outdated. But having some swap is not a bad idea. It does not use too much disk space, so you will not miss the space used; it is not usually used if you have enough RAM, and it allows you to dump core to your swap. –  Hennes Sep 1 '13 at 21:10
    
@Hennes -- read my note..."used to be" –  mdpc Sep 1 '13 at 21:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.