Specify swap space size in "Create an instance"
Currently, after a new VM instance is created, the swap space size is 0 and, if desired, we have to add swap space post-creation. It would be nice to be able to enter a desired swap space size in the instance creation form and it would be ready and active when the instance becomes available. Note: I'm mostly using CentOS images.
Thanks for the suggestion! Swap space is not a very common use case, so far as we know, and it might not rise to the level of something that makes sense to burden the API with for all time, but we’ll take a look.
Tim White commented
Swap space is a common use case. Most cloud providers give you a small swapfile or swap partition by default. It prevents OOM issues when something suddenly balloons in memory, and swap will allow it to complete without crashing. For example, compiling something. Just adding an extra persistent disk for swap, or a swapfile would be useful. cloud-init should be able to handle this already
Ildefonso Camargo commented
There is also the case of how overcommit_ratio is used, swap + RAM*overcommit_ratio/100, funny enough, swap is the base for this calculation. Now, of course, there is the added i/o load added by swap, and the kind of i/o system used on the cloud implementation, performance would probably tank and cause some other issues. I guess the right thing to do is: get as much RAM as you need, and scale up if you need more, using swap is not necessarily a good thing with this kind of systems.
David Kulp commented
Here are some examples:
I had a VM instance where I was performing some interactive compilations on a micro that I use for manual one-off tasks and gcc died. The error reported was not OOM, but increasing RAM solved the problem. If I had a swap, then this would have easily completed without problem.
In another situation I had a VM instance perform RAM intensive computations as part of a pre-processing stage. It died with an OOM when it hit one section of data that required more RAM. It had been running for many hours and I had to restart because there were no checkpoints. If I had a swap, then that task might have slowed down for part of the job, but not died. Having a swap space and slower runtime would be preferable over the additional engineering to incorporate checkpointing into a long running computation job.
Any interactive host is probably better gracefully degrading performance than simply dieing.
While servers understandably are best without swap, there are many examples where swap is helpful.
Christian Mardini commented
I should add:
- I feel it is a bit imprudent to not add swap by default, even if other cloud providers don't do it for you. It can buy some time to swap to disk some unused pages until the VM can be resized.
- Can be implemented as a swap partition (like, I believe, anaconda does) or a swap file