LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   Physical RAM and SWAP Memory (http://www.linuxquestions.org/questions/linux-server-73/physical-ram-and-swap-memory-850855/)

devUnix 12-17-2010 07:20 AM

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?

acid_kewpie 12-17-2010 08:45 AM

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

valen_tino 12-17-2010 08:45 AM

Quote:

Also, do we always need this configuration: RAM Size * 2 = SWAP?
See this link

devUnix 12-18-2010 08:23 AM

Quote:

Originally Posted by acid_kewpie (Post 4194738)
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!

devUnix 12-18-2010 08:30 AM

Quote:

Originally Posted by valen_tino (Post 4194739)
See this link

Thanks for it! I have got a very good understanding of RAM and SWAP reltionship now. Thanks!

johnsfine 12-18-2010 08:51 AM

Quote:

Originally Posted by devUnix (Post 4194647)
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 (Post 4194738)
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.


All times are GMT -5. The time now is 10:09 AM.