What is swap partition?
Swap partition is used for paging in memory management method by which computer can store and retrieve data from secondary storage (Hard disk) and then for use in primary storage (RAM).
What is paging?
Operating system retrieves data from secondary storage in same size blocks called pages
Why its required?
The main purpose of this file system is when an Application or process data not fit into physical memory (RAM) then disk storage (Hard disk) is used as temporary memory.
Example:Your system having 1GB RAM and running Apache web server and because of huge traffic on server 1 GB RAM exceded. Then memory management schemes moved the low proiprty process (tasks) to Swap file sysem and started execute remaining high priority process first.
If system needs run moved process then it copies pages from swap partion to System RAM.
what is the size of swap partition?
Common recommendation is 2 times of your physical RAM.
But According to Open BSD FAQ:
Nonsense rule: Twice the size of your main system RAM for Servers
Many people follow an old rule of thumb that your swap partition should be twice the size of your main system RAM. This rule is nonsense. On a modern system, that's a LOT of swap, most people prefer that their systems never swap. You don't want your system to ever run out of RAM+swap, but you usually would rather have enough RAM in the system so it doesn't need to swap
My recommendation: If you are a kernel hacker (debugging and fixing kernel issues) and generating core dumps, you need twice the RAM swap space.
example: Your server having 2GB RAM then Swap partion should be 4GB
How to create swap partition?
There are 2 methods
1.While installing new OS
2.After installing OS
While installing new OS
While installing new OS you have to select new partion of file system type SWAP with Size.
After installing OS
Check previous swap partitions and their size as below.
cat /proc/swaps
swapon -s
free -m
top
Create a file for swap usage as shown below
Use the mkswap command to make our file swap-consumable for the Linux kernel. Again as root, carefully
To turn on our swap file, we should run
swapon
Add the following line to /etc/fstab and reboot the system for the swap
to take into effect.
/root/swap-fs swap swap defaults 0 0
No comments:
Post a Comment