Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Sat Apr 19, 2014 5:23 pm 
Offline
Newbie

Joined: Sat Apr 19, 2014 4:59 pm
Posts: 3
You can resize a swap size via Linode Manager. But please understand, choosing a random size for your swap size is not something I recommend. In general, if you have less then 2GB of RAM on your VS, set swap size equal to your RAM size. If your RAM >= 2GB, set swap size = 2GB.

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 :D You'd rather not to swap, but having this will not hurt.


Top
   
PostPosted: Sat Apr 19, 2014 5:41 pm 
Offline
Senior Member

Joined: Fri Feb 17, 2012 8:20 pm
Posts: 365
As an honest question, what I miss is the why. Why is more swap good? Why is 2GB the recommended max? Isn't it the case that when a system starts swapping, its performance will already be terrible at that point? What important things will it do during the swapping that it cannot do with a low swap size? With a low swap size, the oom-killer would kick in sooner and kill processes/allowing the system to recover. With a high swap size it may dread on very slowly while swapping stuff in/out and eventually die anyways.

Again, I think tutorials/tips/tricks additions are great, but it would be awesome to know the reasoning behind it as well :)


Top
   
PostPosted: Sat Apr 19, 2014 7:11 pm 
Offline
Newbie

Joined: Sat Apr 19, 2014 4:59 pm
Posts: 3
Why? Because it does not hurt to have 2GB of swap. I still do NOT understand why Linode support is pushing for smaller swap. Swap space is cheap, and it makes sense to have it. What if I run an app, and say, I am getting hit by huge number of clients. What if I don't have a swap, or I only have 512MB and suddenly my app stops responding because it runs out of memory. With bigger swap my app has a chance of survival, and if fact, it is better to be slower for a small period of time, then die out and not be able to serve clients at all. It is a simple principle, and in general, it is better to be ready then sorry. How else can I explained it so it makes sense.

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.


Top
   
PostPosted: Sat Apr 19, 2014 7:45 pm 
Offline
Senior Member
User avatar

Joined: Sun Dec 27, 2009 11:12 pm
Posts: 1038
Location: Colorado, USA
zbigniew wrote:
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.

_________________
Either provide enough details for people to help, or sit back and listen to the crickets chirp.
Security thru obscurity is a myth - and really really annoying.


Top
   
PostPosted: Sat Apr 19, 2014 7:59 pm 
Offline
Newbie

Joined: Sat Apr 19, 2014 4:59 pm
Posts: 3
Well, you did not know what I run on my VS, did you? False assumption leads to failure.

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!


Top
   
PostPosted: Sun Apr 20, 2014 8:09 am 
Offline
Senior Member
User avatar

Joined: Sat Aug 30, 2008 1:55 pm
Posts: 1739
Location: Rochester, New York
It's probably safe to say that a good chunk of the folks with Linodes are doing something like web application hosting, where memory usage tends to track the requests per second. In these cases, keeping swap low is better: fail fast instead of going into swap thrashing. If you don't understand why, this video may help.

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.

_________________
Code:
/* TODO: need to add signature to posts */


Top
   
PostPosted: Sun Apr 20, 2014 10:30 am 
Offline
Senior Member
User avatar

Joined: Tue Apr 13, 2004 6:54 pm
Posts: 833
How much swap you need is dependent on your usage patterns. Things to consider:
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 2*RAM as swap only had a total of 2*RAM 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!
Code:
% 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 :-)

_________________
Rgds
Stephen
(Linux user since kernel version 0.11)


Top
   
PostPosted: Sun Apr 20, 2014 1:55 pm 
Offline
Senior Member

Joined: Mon Jan 02, 2012 12:45 pm
Posts: 365
zbigniew wrote:
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 wrote:
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?


Top
   
PostPosted: Fri Oct 23, 2015 1:03 am 
Offline
Senior Newbie

Joined: Sat Aug 22, 2015 7:02 pm
Posts: 14
What about for linode 4GB? i want to increase my swap to 4GB from 512MB


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group