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?
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.
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:
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.
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:
Swap is required for hibernation, otherwise you can get by without it just fine.
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.