Increasing swap

After increasing your linode, how would you increase your swap space accordingly? By adding a swap file?

20 Replies

I know that on mine the swap is actually a disk image. You should be able to resize that disk and then you'll have more space.

Yes, I noticed that mine too. So it should be easy to increase, isn't it?

It's generally recommended to always use 256 MB of swap, no matter the size of your Linode. Significant swapping is almost always really, really bad; better to OOM earlier without crushing the disks first.

Is there an official post for this recommendation?

In https://help.ubuntu.com/community/SwapFaq they say:

> As a base minimum, it's highly recommended that the swap space should be equal to the amount of physical memory (RAM).

@fernandoch:

Is there an official post for this recommendation?
~~[http://library.linode.com/getting-started#sphdeploy-a-linux-distribution" target="blank">](http://library.linode.com/getting-start … stribution">http://library.linode.com/getting-started#sph_deploy-a-linux-distribution](

I meant recommended by Linode, not by some distro crap. :P

Well, the Ubuntu distro is the most used in Linode.com…

The problem might be having a big swap in a virtual environment like this one, but in a physical server, the swap should be well sized.

Being widely-used doesn't mean Ubuntu-related documentation is automatically good.

Shrug. I wasn't very seriously insulting it. You're right, though. I was only thinking in terms of Linode, not the wider use-cases that documentation is written for. In any case, I don't have a position on swap in general; but on Linode, 256 MB plz.

The 256MB suggestion on some of the larger Linode sizes might not be quite sufficient… I'd tend to suggest max(256, RAM*0.25) as a baseline.

Anyhow, 1:1 ratio of RAM to swap is greatly excessive, be it on a linode or physical server. Desktops are a different story, but for servers, the case for extra swap is pretty poor. Swap is slow. If you need more swap because you don't have enough RAM, adding swap isn't going to solve your problems, it's only going to slow your linode to a crawl.

To put it this way, swap is fine for moving inactive things out of RAM to free up memory. Swap is NOT fine for actively running anything. If you're creeping into swap because of insufficient memory rather than because stuff is inactive, you're in for a very bad day.

While I tend to argue that a 512MB linode can handle enormous loads as a basic LLMP/LEMP/etc stack (into the millions of pageviews per day), if you're maxing out your RAM, you're better getting more RAM than more swap.

@fernandoch:

Well, the Ubuntu distro is the most used in Linode.com…
Ubuntu was designed to become a desktop OS, and for desktop OS it's good advice to set size of swap not less than size of RAM, to use hibernation. But it's not actual for servers.

@OZ:

@fernandoch:

Well, the Ubuntu distro is the most used in Linode.com…
Ubuntu was designed to become a desktop OS, and for desktop OS it's good advice to set size of swap not less than size of RAM, to use hibernation. But it's not actual for servers.

Oh really? How come Oracle and Redhat have some minimum swap requirements?

http://docs.redhat.com/docs/en-US/Red_H … ap-what-is">http://docs.redhat.com/docs/en-US/RedHatEnterpriseLinux/5/html/DeploymentGuide/ch-swapspace.html#s1-swap-what-is

http://download.oracle.com/docs/cd/B193 … m#sthref63">http://download.oracle.com/docs/cd/B1930601/install.102/b15667/preinstall.htm#sthref63

These are no desktops and no hibernation…

The RHEL recommendations also state that "the amount of memory in modern systems has increased into the hundreds of gigabytes"… which may be true for a small number of very high-end systems, but I doubt servers with 256GB+ of RAM are all that common.

There are still edge cases where large amounts of swap can be beneficial. Varnish, for example, eschews disk caching, and instead uses swap as a disk cache. My understanding is that it essentially shoves everything in RAM and then lets the OS figure out what stuff is frequently accessed enough to stay in RAM. Perhaps Oracle does something like this. But failing this kind of specific use of swap, the general case doesn't warrant having much of it.

@fernandoch:

Oh really?
Yes.

@fernandoch:

http://download.oracle.com/docs/cd/B193 … m#sthref63">http://download.oracle.com/docs/cd/B1930601/install.102/b15667/preinstall.htm#sthref63
It's OS recommendations? If you have recommendations for concrete software - it's another case and no reasons to ask this on forum, if you have already strict recommendations.

@fernandoch:

These are no desktops and no hibernation…
Oh, really? RHEL has hibernation.

And, if you don't want to listen answers here - why do you asking here? Ask those authors whose recommendations you cite.

You have recommendation from Linode:
> We strongly recommend sticking with the default swap image size, as allowing your Linode to go heavily into swap can seriously degrade performance in an environment where disk IO is shared among virtual machines.

Of course I do want to listen to answers here, this is why I asked.

No more comments from my side.

Thank you all.

The days of mem = swap are long gone. Those days it was actively used - to store recenty used images for example, but it was the relatively huge price of memory ( nobody will need more than 640KB anybody? ) that started this off.

Nowadays, as others have said, if you are using swap on a regular basis, then you're hurting your system performance, and should be looking at upgrading. The swap's there just in case, and to provide a warning.

Oracle's demands that you have the same swap as memory are the most annoying… why did you install 64GB in the first place??? I just live with it then throw it away when up and running.

Finally, server loads are generally more predictable than a desktop - and Ubuntu provide both, so their recommendations may well be covering both setups as well. Personally, I don't even install a GUI on my servers, let alone run bloatware like firefox… my poor old workstation has to take that, and it has far more mem than most of my linodes!

Steve.

Running bundle install for the first time rinses ram so hard. For me, each process uses over 250mb of ram each, and heroku buildpacks use 4 of them by default. This would be a valid reason to use swap IMO, since you don't do it very often. I just created a swapfile on my server for this purpose.

If bundle install is using 250 MB of RAM, you really ought to investigate what the heck it's doing.

  • Les

Simply put, swap is bad - mkay?

Debates about the ideal swap size aside,

How can the swap size be increased?

Umm- dashboard -> Disks -> edit

run command "top"

KiB Mem : 8167504 total, 2714884 free, 900236 used, 4552384 buff/cache
KiB Swap: 1884156 total, 1865968 free, 18188 used. 6830016 avail Mem

then you will know how much Swap you need to set,in my case ,512M or 256M is totally enough.

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