How to assign Swap Space on Linux PC
While installing many of we ignore Swap space. It does not matter what Linux Distro you are using. It can be the last Mint or Ubuntu or any older Debian based operating system. Swap space place a vital role in your systems performance. You cannot just ignore that. I had tested two systems. Both are working on latest Linux Mint Maya. The only different among them was the Swap space. System A has a dedicated partition of 20GB as swap space and System B does not have any swap space. There are major changes in performance observed. When I open YouTube using Opera in System a, it worked smoothly. I had downloaded some software on the same hand, played music files, etc. In system monitor the ram usage was clear and it showed that with Swap space Linux manages the performance. But in System B, when same process was repeated it started freezing at some point. Though there was 50% physical memory available. It looks that some part of ram is kept reserved. The explorer takes time to open and files were listed slowly. The same if done in Windows, then this is a disaster. Swap space is same as Page File in Windows.
In simple word a Page file is memory management tool which is used by resource intensive application to perform well. Many time in Task Manage you can see the virtual memory usage. Swap space is similar to that. Your hard drive has ample of free space. You can assign an empty partition as Swap space and continue with your work. Linux do not format that partition but uses its empty space to fulfill the memory requirement. This is very important for every system. Swap space can improve the systems output. Do not ignore the same while installation. To understand how Swap space work, lets learn about Page file. Here is a very common example. Let’s assume that you have two desks in front of you. The first desk is filled with objects like pager, computer, printer, etc. The second desk is partially filled. Now to arrange a set of paper you need some empty space. For temporary basis you can use the second desk. You can move the papers on it and then pickup them back on your desk. Page File is somewhat similar to that.
In a computer you have two types of memories. First is Physical memory, what you called RAM and the second is Virtual memory which is actually your empty hard drive storage space. Operating system needs physical memory (RAM) to initiate various functions. But when the limit is crossed, then they work on special algorithm (supported by hardware) which helps them to use the empty hard drive space as ram. For example when you open a web browser, it needs RAM to keep those all stuff on your screen, the buttons, the window, etc. But when you open more than 1 tab more memory is consumed. In order to maintain the performance virtual ram is used.
The data is divided into small parts inside memory. Those small parts are known as pages. When the physical memory is out of stock, those pages are transferred to your empty partition for some time. Swapping consist of process where those parts are actually moved to a hard drive partition which is configured as Swap space. Combination of physical and swap space makes the virtual memory. The more you have the better system works. Today’s applications are designed features point of view because of which they need more memory power. The same is mostly applicable to web browser. You can find simply how much ram they consume when you check in System Monitor. The last test that I did, when I open around 7 videos in different opera tab. The maximum ram it was eating was 292 mb. Now you can considered what would your operating system if a major part of resource is consumed so instantly. It will freeze or lag.
But the best part of Linux Distros is that they do not simple go black. In Windows if this thing happen, the screen just zombify. Nothing happens, no mouse movement, app stucked in between, no keyboard reaction, etc. But in Linux after little time, things went back to normal. Swap is needed in every system. It makes your process smoother. Swap helps the system by providing more memory to those applications which are resource intensive. Because of which you do not find any difference on your screen, but in the background this all process are carried out. In some case swap fails. There is a reason for that. Linux mostly work on two different type of swap space. Among which one is dedicated to swap partition assigned by you and second is the swap file which works inside the file system.
Re: How to assign Swap Space on Linux PC
Why Swap Space does not work or fails?
Swap space is a process of providing more memory power to software’s. Now that extra memory power is taken from your current hard drive. Compared to RAM the Hard disk is slower unless you have a SSD. Hard drive works much slower than RAM. So if swapping occurs continuously in the background, your system can appear more slow or even crash sometime. At that point the best thing you can do is add more RAM stick. This happens in exception case only. It does not mean every system is prone to this issue. I am talking about slow system. For example you are trying to run 3D model application on Dual Core pc with 1GB or lesser ram. This type of application needs good processing power and virtual memory. If your system fails to meet the need, the application freezes on your screen. It is not terminated automatically as your operating system still tries to open it. Every system either Windows or Linux are vulnerable to this. Swapping just helps the system to run some apps. It can be a temporary fuel.
You cannot assign 80GB partition as swap space and then wonder I have the fastest system. Every piece of hardware on your motherboard works with appropriate co-ordination. Here this article is based on assigning swap space to Linux Distro. Let’s take Linux Mint Maya under test. There are two conditions for assigning a swap space. First doing that at the time of installation and second after installation Linux Mint. Both the ways are fine. The condition to assign a swap is that you need a separate partition. I will not recommend you to play with the same if there is any data. You can shrink the partition size also. With a simple command you simply find out what is the actual swap space of your existing system. For that in terminal type swapon -s. You can see se the listed swap partition in terminal itself. If you cannot see it then there is no space assigned. I had tested my 8GB usb a number of times to use it as a Swap partition and it have helped a lot.
Maximum Size of Swap File:
If you are confused that how big must be your swap file, then here is answer for the same. Actually you do not need really a very large size. The system when run out of memory the swap partition is then used to give you more performance. You just need a proper disk space for that. I will not recommend installing Linux Mint type of os without swap file. What you can benefit from new distribution is that, the more new the lesser requirement of swap files and better memory management. While in older system the same demand is quiet higher. Your swap space must be double the size of your ram. That is the most common assumption I can give you. If you have 1GB ram in your system then you can add 2 or 3GB swap space which is quiet enough.
How to assign Swap space
A partition which is marked as swap will only be used as swap space. Luckily there are post installation methods that can be used to for this. First let’s begin with adding extra swap space. For that type this in terminal --- fdisk -l /dev/hdb (do not put the starting hyphens). You can see the output of partition which already has a swap space. I am showing you the way here to extend it. If in the result in terminal there is on swap marked then you have to do that before extending the partition. Assigning swap space will wipe out your partition. Your all data will be lost, so be preparing before going for this. Now to make a swap space you need to use mkswap command. You just need to provide the hard drive reference after that. Like mkswap /dev/hdb1. The process will only be successful if you do not face any kind of error after running the command. You can again check back by typing swapon -s to see the partition is actually marked as swap or not. For more advance process you can read a swapfaq on official sites of Mint or Ubuntu. You can also use Gparted tool. For that restart your pc with bootable Mint disc and run Gparted. Format a partition and assign it as the default swap space.
|Tags: linux, linux mint, swap space|
|Thread Tools||Search this Thread|
|Similar Threads for: "How to assign Swap Space on Linux PC"|
|Thread||Thread Starter||Forum||Replies||Last Post|
|Sharing the CentOS 5.5 Swap partition with any other Linux OS||Pawna||Operating Systems||5||04-05-2011 11:51 AM|
|Reducing Swap Size in Linux Mint 10||Rufta||Operating Systems||4||13-01-2011 10:24 AM|
|Where to put swap partition in Linux||foraman||Operating Systems||4||02-01-2011 07:47 AM|
|In Linux 2.6.31 kernel scheduler how to assign threads in each core?||SaleemJI||Windows Software||6||25-09-2010 05:55 PM|
|Why do i need a SWAP partition for linux?||Windows7er||Operating Systems||3||17-11-2009 11:45 AM|