SWAP resize via Linode Manager
Note, that during server deployment the maxim swap size you can choose is 512MB. Well, you can live with it, but why not have 2GB of swap if your RAM >= 2GB. It does not hurt, and in some instances may spare you some issues.
To resize swap size on your VS you need to perform few steps. I am going to base this discussion on a 1st tier VS, with 2GB of RAM and 48GB SSD.
Further, I want 2GB swap = 2048 MB, and 48GB = 49152 MB.
(1) Choose your server and shut it down
(2) Choose a primary disk /the one your Linux resides on, in case of CentoS it could be : CentOS 6.5 Disk Image/
- You will see 'Edit Disk Image' section : put 47104 in New Size and click 'Save Changes'
// you need to shrink this Disk Image it to allow for 2GB of swap
// 49152 MB - 2048 MB = 47104 MB
(3) Go back to Dashboard and click on 'Swap Image'
- put 2048 in New Size and click Save Changes
(4) Reboot your VS
You can logon to your server and see available swap space. In your shell prompt type cat /proc/swaps, and press enter
You may see similar output to the one below /filename may be different, but size : 2097148 = 2GB shall be the same/
Filename Type Size Used Priority
/dev/xvdb partition 2097148 0 -1
Now you have 2GB of swap space. Happy swapping
8 Replies
Again, I think tutorials/tips/tricks additions are great, but it would be awesome to know the reasoning behind it as well
I do not proclaim swap space as a substitute for RAM. Swap space is a backdoor in extreme cases, and is a part of Linux architecture, so have it there ready, when extreme happens. This is as simple as that.
Also, Linux experts and system admins do recommend swap space like that. Their recommendation is based on years of experience, various scenarios, and simply system knowledge.
I hope this explanation is clear enough.
@zbigniew:
How else can I explained it so it makes sense.
Maybe by not spouting nonsense?
I would NEVER have a swap that large, using swap means your applications are setup incorrectly.
Please name these "linux experts and system admins" that are living in the 1990's and still using boatloads of useless swap.
Back when systems were slow and ram was expensive, swap was a necessity. Today, fast cpu and cheap ram means lose the swap, and config your apps not to use it.
As to "not hurting", it's a waste of space and a false security net. If your VPS system starting hitting any where close to 2g of swap, it would pretty much be inaccessible, so no safety net, no slow but still serving clients, nothing but wasted space and a OOM crash.
For almost every case, 512M is more then sufficient for swap. Only exception is if you're running Oracle or another Database engine that uses swap for it's own purposes.
So you say
"I would NEVER have a swap that large, using swap means your applications are setup incorrectly"
And then you conclude
"For almost every case, 512M is more then sufficient for swap. Only exception is if you're running Oracle or another Database engine that uses swap for it's own purposes"
You obviously contradict yourself, so it is you spouting nonsense, not me!
this video
If you're running… oh, I dunno, a desktop environment in a Linode, more swap might be helpful, sure.
The above is based on over a decade of experience as a Linux sysadmin.
tl;dr: Use 256 MB of swap by default, but if you run out of memory, change it to 128 MB.
1) How much virtual memory do I really need?
2) Can I afford that much RAM?
3) How much performance impact can I live with? (swap is much slower than RAM).
It's then a matter of juggling those factors to decide on how much swap is needed (if any). For example, if you have a linode2G and your application needs 1G of RAM then you might decide not to have any swap at all. If however it needs 3G then you might want to either consider getting a larger machine, or creating sufficient swap; "cost" and "speed" become the primary factors.
People have mentioned oracle in this thread. Oracle reserves a lot of memory for itself (tunable from the db.ora file); block buffer cache, sql cache, per-connection cache and so on. In general (not totally true, just a rule of thumb) the bigger the cache the better the performance. However if you make the caches too big then other applications may be starved of memory and so need swap. Again you need to balance DB performance with system performance; do you get more RAM, shrink the caches, swap to disk?
Usage patterns also impact how much swap you need; a desktop running Libre Office may be fine with some swap 'cos you don't care too much about a small delay in starting desktop apps. A web server, however, may be a lot more sensitive to swapping and performance degradation caused by swap may not be acceptable. One thing you don't want is for the machine to spend more time paging memory in/out than actually doing any real work ("thrashing").
Small side note: some people say "twice RAM = swap". This comes from old SunOS 4 and old BSD days where the swapping algorithm needed "RAM" amount for paging, and then additional swap got added, so a machine with 2RAM as swap only had a total of 2RAM for virtual memory, and not 3*RAM that you might have thought. This was never true for Linux and isn't true for any modern OS I'm aware of. So ignore 'twice RAM = swap' guidelines.
So how much wap do you need? The answer is "it depends!"
Since most linodes are servers, in general I wouldn't recommend much more than 512Mb; if you find yourself hitting the "out of memory" (OOM) killer then it means your system is likely undersized (mysql tuning needed? apache tuning needed?) or that you have special requirements. At this point evaluate your total RAM requirements and resize as necessary.
In my case I don't need swap at all; I'm using less than 200Mb of my 2G RAM!
% free -m
total used free shared buffers cached
Mem: 1993 1437 556 0 78 1173
-/+ buffers/cache: 185 1808
Swap: 256 2 254
The 256Mb of swap is legacy from way back when linodes were a lot lot smaller
@zbigniew:
Well, you did not know what I run on my VS, did you? False assumption leads to failure.
I think it's a safe assumption that you aren't running Oracle or you would have qualified your post by stating it. Oracle has uncommon resource requirements and anyone posting about Oracle DB issues will identify Oracle by name. vonskippy doesn't need to know what you are running to address the swap size issue; he only needs to know what you are not running (e.g., Oracle).
@zbigniew:
So you say
"I would NEVER have a swap that large, using swap means your applications are setup incorrectly"
And then you conclude
"For almost every case, 512M is more then sufficient for swap. Only exception is if you're running Oracle or another Database engine that uses swap for it's own purposes"
You obviously contradict yourself, so it is you spouting nonsense, not me!
Just like you, vonskippy is not running Oracle. His statement "I would NEVER have a swap that large…" is consistent with his not running Oracle. The fact that he provided an exception demonstrates that he knows what exceptions apply to his statement (though they do not apply to him as he is not running Oracle).
Anyone who seems to know more than Linode's support team about what swap size is best for a Linode is mistaken. Linode knows their own systems and infrastructure better than anyone. It is their job and their responsibility to provide us with the best configuration information about using Linode. Not to mention that it's in their best interest to do so.
More is not always better, but I guess if you think more swap is better, then you should also be advocating for as much RAM as possible because more RAM is always better, right?