How much swap space in linux
11 Replies
Swap means somethings not configured correctly.
Try 256M and see what happens.
Swap on a desktop and swap on a server are different from a desirability standpoint. A desktop, you might have tons of apps open, and you only use one at a time, so you don't mind if something gets swapped out entirely.
On a server, that's not really the case… There's some benefit to a small amount of swap so that legitimately never used stuff can get swapped out, but you never want to have anything in swap that you might need to swap back into RAM.
Caker normally suggests no swap at all. I tend to suggest a tiny amount for this reason. I think 25% of your VPS RAM is a decent value.
@chesty:
i go by the rule of 50% of your disk space is swap, so 10G for a 512, on my desktop I have 1.5T of swap.
Oh my God!:roll:
@drpks:
@chesty:i go by the rule of 50% of your disk space is swap, so 10G for a 512, on my desktop I have 1.5T of swap.
Oh my God!:roll:
Wholly guacomole:!:
@chesty:
i go by the rule of 50% of your disk space is swap, so 10G for a 512, on my desktop I have 1.5T of swap.
i disagree, its a lot.
@chesty:
i go by the rule of 50% of your disk space is swap, so 10G for a 512, on my desktop I have 1.5T of swap.
I hope that was a joke:?
When it comes to linode, the thing to understand is that if your machine starts to swap then performance will drop through the floor. Most people only hit swap when they've got misconfigured apache/mysql setups and when it starts to swap the whole machine spends time in I/O wait and your machine has, basically, swapped to death. It's not servicing requests!
The linux kernel does like a small amount of swap, even if it doesn't really need it. My linode 512 only has around 70Mbyte of working memory; the rest is all I/O cache. And yet there's 3 Mbyte of swap in use, simply 'cos the kernel thinks it's more efficient to send those pages to disk. They're not paged back in simply 'cos they're never used.
As others have suggested, zero to a couple of hundred Mbyte is appropriate. If you're actively swapping then your linode is too small (or your application is misconfigured) and no amount of additional swap will help.
@sweh:
There's an old old rule of thumb that says "twice ram == swap". However many people who make that statement don't actually understand why it exists and why it never applies (and never has applied) to Linux.
Oh but it has applied to linux at one stage, if you google the right terms, you will see linus and alan cox both saying swap = 2 x ram on the lkml.
and yes, I was joking about swap = 50% disk.
A desktop computer is typically running a ton of different programs, only one of which is actively used at any time. A server typically runs a very small number of programs of which multiple or all are actively used at any time.
Imagine if your linode has to swap PHP out of memory to get MySQL into memory every time your web site does a SQL query… times a hundred for a database-heavy webpage.