How much swap space in linux

How much swap space to give in linode 512 ?

11 Replies

As little as possible.

Swap means somethings not configured correctly.

Try 256M and see what happens.

128MB, maybe.

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.

The Linode manager suggests 256 MB as a default. I see no reason to change it.

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.

@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 :?

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.

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.

For linux desktop use, which is a completely different scenario. You don't care if it takes your IM client half a second to swap back into RAM when you switch from your browser to your IM, but you do care if you spend half a second swapping on every HTTP request to a web server.

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.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct