LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-17-2010, 07:20 AM   #1
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Rep: Reputation: 59
Physical RAM and SWAP Memory


Hi,


How can we find out as to at what point does SWAP Memory come to play its role? Or in other words, as we know, when RAM is being utilized and the the OS (Unix / Linux in our scenerio) needs more memory to run applications or commands then it makes use of the SWAP Memory. But when can we say that now SWAP is being used or what percentage of the Physical RAM is determined after which the system must use the SWAP Memory?

Configuration Example:

Physical RAM: 1 GB
SWAP Partition: 2 GB
OS: RHEL 5 (or any UNIX OS)

Now, when can we say that SWAP would be utilized or upto what percentage of the available RAM no SWAP would be required?

Also, what level of RAM and SWAP should we set as "Crtitical" in a production enviroment? For example, 90%?

Also, do we always need this configuration: RAM Size * 2 = SWAP?
 
Old 12-17-2010, 08:45 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
you can say that swap would be used when you are requiring more than 1gb of active memory.

You don't need 2 times at all. That's a very very old rule of thumbs. Generally on a dedicated function server you should *NEVER* need swap, if you do, you are doing something wrong. Performance will degrade significantly if you are repeatedly swapping pages in and out, so the ideal should always be to never use it in the first place. And if you don't ever use it, you clearly don't need twice as much as physical memory.

www.linuxatemyram.com
 
Old 12-17-2010, 08:45 AM   #3
valen_tino
Member
 
Registered: Jan 2008
Posts: 105

Rep: Reputation: 28
Quote:
Also, do we always need this configuration: RAM Size * 2 = SWAP?
See this link
 
Old 12-18-2010, 08:23 AM   #4
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Original Poster
Rep: Reputation: 59
Quote:
Originally Posted by acid_kewpie View Post
you can say that swap would be used when you are requiring more than 1gb of active memory.

You don't need 2 times at all. That's a very very old rule of thumbs. Generally on a dedicated function server you should *NEVER* need swap, if you do, you are doing something wrong. Performance will degrade significantly if you are repeatedly swapping pages in and out, so the ideal should always be to never use it in the first place. And if you don't ever use it, you clearly don't need twice as much as physical memory.

www.linuxatemyram.com

Thanks for the insight!
 
Old 12-18-2010, 08:30 AM   #5
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Original Poster
Rep: Reputation: 59
Quote:
Originally Posted by valen_tino View Post
See this link
Thanks for it! I have got a very good understanding of RAM and SWAP reltionship now. Thanks!
 
Old 12-18-2010, 08:51 AM   #6
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by devUnix View Post
what percentage of the Physical RAM is determined after which the system must use the SWAP Memory?
It is not at all that simple because SWAP space is used for anonymous memory and not for file mappings. File mappings includes most of the executable code in both main executables and .so's.

Unless you are short of disk space, you should have swap space set to significantly more than you ever expect to need. That way if you ever have an unexpectedly high memory load your system will just slow down a little rather than failing.

Quote:
Physical RAM: 1 GB
SWAP Partition: 2 GB
Absent any info about how you use that system, I think you guessed the swap size correctly. Even more than the other posters here, I disagree with the old rule of 2x ram size. So I don't think the reason 2GB swap is a good guess is because it is 2x ram size. I think 2GB is a good guess because that is a generous but not absurd amount of swap for most lightly to moderately loaded Linux systems with typical current software. If you had .5GB of ram or 4GB of ram, I'd still think 2GB is a good guess for swap size.

Quote:
Also, what level of RAM and SWAP should we set as "Crtitical" in a production enviroment? For example, 90%?
You should occasionally check your swap usage. If any significant fraction of the swap space gets used, you should check the rate of swap-in I/O activity. If there is a moderate to high rate of swap-in, you should get more ram. If a significant fraction of swap space is used but swap-in rates are very low, you should increase the amount of swap space.

In your example of 1GB ram and 2GB of swap, you should probably think of that as up to .5GB of swap for actual use and 1.5GB swap as reserve for rare unexpected incidents. If you notice more than .5GB swap in use, you don't have enough swap space (or depending on swap in rate, you may not have enough ram).

Quote:
Originally Posted by acid_kewpie View Post
you can say that swap would be used when you are requiring more than 1gb of active memory.
But that isn't correct. You could be using far more than 1GB of active memory and still not need any swap, maybe not even use any swap if you have swap.

It depends on the mix of anonymous vs. file mapped memory use. No matter how much file mapped memory use you have, non of that use will ever go into the swap file.

If your anonymous memory use gets to 3/4 or more of ram, you will almost certainly need swap space. But even at a lower level of anonymous memory use if the file mapped use is more active than some of the anonymous use, the kernel may be able to make the system faster by swapping out stale anonymous memory to allow more memory use by file mappings.

There are also rare cases where an individual process requests far more anonymous memory than it actually uses, causing the system to need swap space to exist even though it never actually uses that swap space.

Quote:
Generally on a dedicated function server you should *NEVER* need swap, if you do, you are doing something wrong.
In a narrow sense of "need" that may be correct. But a server (even more than a workstation) is likely to make good use of a little swap space even when there is plenty of ram. Most service processes use some anonymous memory at startup and shutdown that they don't use in between. Once the kernel figures out that those pages are stale (which might take half an hour on a moderately loaded server or days on a lightly loaded server) it can improve memory use a little by swapping those pages out.

Depending of the services you are running the benefits may be trivial to moderate. That doesn't qualify as "need" but generally qualifies as a good idea.

On the Linux servers where I work, the typical swap partition size is many GB. The typical amount of used swap space is 150MB. The typical swap in rate is zero. These are systems with 3GB to 12GB of ram, so the performance benefits of kicking out 150MB of stale anonymous memory are pretty small (but not zero). The big swap space is there because the memory loads are not directly managed. Different activities that each take most of ram typically run at different times, but could accidentally run at the same time. If that happens we want the system merely slower, not broken.

Last edited by johnsfine; 12-18-2010 at 09:44 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to prioritize the use of physical memory instead of swap? afreitascs Slackware 6 10-26-2010 04:20 PM
PAE Kernel (2.6.18) fails to swap with large amounts of physical ram youngdo Linux - Server 6 12-09-2009 09:03 AM
Swap space did not function when physical memory ( RAM ) is full rabbit00 Linux - Newbie 19 07-06-2009 09:18 PM
how to use swap more than the physical memory Santosh_d Linux - General 9 03-24-2004 02:51 PM
swap drive, physical memory glock19 Linux - General 6 03-08-2002 04:29 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration