Results 1 to 10 of 17
Friends plz tell me how to include swap space ?...
- 04-13-2009 #1Just Joined!
- Join Date
- Jul 2008
- Posts
- 10
increase swap space
Friends plz tell me how to include swap space ?
- 04-13-2009 #2
Which Linux distro are you using? Post the output of free and fdisk -l commands.
Code:free sudo fdisk -l
It is amazing what you can accomplish if you do not care who gets the credit.
New Users: Read This First
- 04-13-2009 #3Just Joined!
- Join Date
- Dec 2005
- Posts
- 96
And a reason why would you want to increase swap. On modern computers you can turn it off. It just occupies space and never used.
- 04-13-2009 #4Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
I am usually reluctant to do that. When the kernel has no memory it will start killing applications, and you can lose your work. When there's swap you can start noticing how your system become unresponsive and do something about it before the catastrophe arrives.
It doesn't matter how much bucks you spent in your box and how much ram it has. When an application starts leaing ram due to a bug it will eventually fill it all up within a short amount of time.
Besides that, even when your ram is empty, the kernel can still use the swap for many things.
You first need some space. Do you have a spare partition or some free unpartitioned space for this? If so, you only need to add it in your fstab file.
If not, you could still use a loopback file and use it as swap.
- 04-13-2009 #5
However ridiculous amounts of swap space will do you no good performance-wise and actually may slow your system down, due to the difference in access speeds between RAM and harddrive space.
I wouldn't necessarily recommend having NO swap space, but having too much of it is a bad thing as well. It would help if we knew how much RAM the original poster had so we could suggest a reasonable amount of swap to allocate.Registered Linux user #270181
TechieMoe's Tech Rants
- 04-13-2009 #6Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
I agree. 512 mb is the standard I always suggest, unless it's for a very specific reason, or unless you need it to hibernate. I agree that having 16GB swap in a system with 8GB RAM is not smart. The "one size stick (2x your ram size) to rule them all" never convinced me.
However an over sized swap partition shouldn't create any performance problem, unless you start to swap massively that is, and then the problem is not in the swap per sč, but in your applications (or in the person who opened twenty copies of blender 3d while playing counter strike).
- 04-13-2009 #7Just Joined!
- Join Date
- Dec 2005
- Posts
- 96
Thats the point! Instead of using fast RAM linux uses slow HDD.Besides that, even when your ram is empty, the kernel can still use the swap for many things.
Anyway. To the topic:
Copied from all the best linux cheatsheets that I bookmarked few days ago. $)Code:Suppose you need more swap (right now), say a 2GB file /swap2gb (Linux only). # dd if=/dev/zero of=/swap2gb bs=1024k count=2000 # mkswap /swap2gb # create the swap area # swapon /swap2gb # activate the swap. It now in use # swapoff /swap2gb # when done deactivate the swap # rm /swap2gb
- 04-13-2009 #8Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
No, you don't understand how the thing works at all. The kernel only uses swap when there's a good reason, and not to intentionally cut down the performance of your box. And a good reason is one of these:
- there's no available free ram
- it's better to use swap (yes, believe it or not, there are circumstances where's it's better)
Believe it or not, the kernel is not that idiotic to use swap when it would harm the performance, unless there's no other option.
The only truth is that, besides the aesthetic aspect, having a small swap partition doesn't do any harm, while not having it could lead to potential problems like the one I described (no ram, apps crash). That is, unless you are very limited in storage space which is rare these days.
Consider this situation, which is what happens everyday in your system without you noticing it.
The tale begins:
You have 1gb of physical ram. You turn your pc on and after a minute you have your desktop in front of your face. You start up firefox and open a few documents, etc. etc. etc, after some minutes you decide to look at top to see the memory usage and see that there're 200 mb used. But you also see that the other 800 are being used for cache and buffers. They are basically free ram, and that's what memory monitors will say. But in Linux, the concept of free ram as such doesn't exist, because free ram is wasted ram. The ram is always used to max out the performance.
Well, you continue working and after a few hours you notice that there are 100 mb or swap being occupied. What's this? Hell, I have free ram, why doesn't firefox use it instead?
Well, the fact is that using true ram for this 100 mb would be bad for your performance. Why? These 100 mb are probably occupied by some temporal info and structures from firefox that hasn't been used in hours, and probably are not going to be used again, but are there just in case. If that info were in your ram that would mean 100 mb (10% or your ram) less space to be used as cache and for i/o buffers, which would actually cut down your performance.
... and so the tale ends.
And this is just one example of why having swap is a good thing for performance, even if your physical ram is huge. Of course that swap is slower than ram, that's obvious, but swap is actually used when there's a benefit from
using it or simply there's no other alternative. Ram can always be used for useful things, even when you think it's free ram it isn't most times. Having swap gives you a place where to store crap that's hardly been going to be used so you can devote "free ram" to something that's actually more useful than holding ancient crap, and firefox does a lot of that by the way
If you have 16GB or ram and want to ditch your swap, that's ok. But having it still doesn't harm at all, and it still improves how everything is handled, even if in such case it's not noticeable at all.
People should also think of the slowness of swap as a feature and not something bad. The graceful degradation of the performance is telling you that it's time to save your docs and close something heavy. Otherwise, your first and only warning will be an application closed by the kernel OOM killer, or even worse, a crash during a save operation that can even corrupt your data and leave it in an non recoverable status.
As said, this can hit you no matter how big your ram is, key code "mem leaks".
- 04-13-2009 #9
I'm pretty sure the original poster didn't mean to touch off a debate about swap space, so let's summarize what's been said so far and move on to the actual task described (as void_false suggested).
- Having swap is generally a good thing, or at least does no harm if you have it.
- Having TOO MUCH swap is a bad thing.
- Swap space is slower than RAM, and shouldn't be used as a substitute for it.
sushil_sk, could you please tell us why you feel it necessary to add more swap? It would also be helpful to know how much RAM your system has.Registered Linux user #270181
TechieMoe's Tech Rants
- 04-13-2009 #10Just Joined!
- Join Date
- Dec 2005
- Posts
- 96
i92guboj, ok ok don't go on me! I'll recreate my swap partition. I promise

I removed it because I noticed that swap was always at 0% for few years on different distros.



