DiigIT | IT Community
No Profile Image
Welcome Guest
New User? Register | Login

How much SWAP i set if my server is having 8 GB RAM ( Main Memory )

By: rekha singh | 11 Mar 2010 11:57 am

How much maximum swap can Linux use.

I know this formula ( SWAP=2 * RAM SIZE ) is used to calculate SWAP Space. But really is there limit that you can not increase SWAP more than 4 GB.

What you will do if your server having 8 GB RAM, then can you suggest what will be the recommended RAM I have to select
 

Comments

There is no 4GB limit on swap......

You can have multiple swap files in use at the same time.

When you only have a little memory (I am suggesting up to 8GB) I would use 1:1.5 memory to swap

When you have lots of memory, 8GB or up, I would go 1:1 ratio swap to memory. This info doc indicates MINIMUMS

By: rekha singh | 11 Mar 2010

Not sure I agree with all that... of course, I've not run large RAM systems in production, only in stress testing, but honestly, if you are in a position where you NEED to run more than 4 GB of swap space, you should consider adding RAM or finding a new way (load balancing, cluster, etc).

In test at least, even systems with 512GB or more, I've run memory stress up to 98% RAM utilization with no more than 4 or 8 GB of swap and even then only about 50% of the swap space was used during stress testing.

Swap was more important (and the 2*RAM number was important) when systems had less than 1 GB RAM. Back when you were running on a server that maxed out at 512MB perhaps... Now a days, RAM is cheap.

Anyway, You're right, you don't need 2* anymore (geez.. imagine what that's like on a 512GB system... heh...) but realistically, as I said, if you have 4GB of swap on a 256GB system and you're hitting swap at ALL, then you need to rethink your hardware strategy a bit...

By: rekha singh | 11 Mar 2010

I think it's a good idea to keep in mind the fact that the SWAP=2 * RAM SIZE rule has been around as long as I've worked with *NIX systems (which is since 1988) and probably much longer than that. At that time I worked
on systems that used swap differently. When running a program, HP-UX wrote to swap first, then paged into memory. If you ran out of swap you didn't run anything else. Effectively, virtual memory was equal to swap. Then there was SunOS, which went to memory first and then to swap as needed. Effectively, virtual memory equaled real memory + swap, but the OS didn't handle it gracefully when you ran out. You crashed.

What I find kind of humorous about the difference in result, though, is that both companies were recommending SWAP=2 * RAM. Which only goes to remind us that sysadmin is as much art as science.

Bottom line, the amount of swap is related to the use, not to the amount of hardware you have on the machine. All you can do is set up the machine with something reasonable, start loading it and add swap if necessary.

In the case of redhat, they seem to use a memory management system in which the OS grabs all the memory but will surrender it when needed. For that reason, I mondified our Nagios routines so they don't alarm on low
memory until a certain amount of swap is in use as well. Unfortunately that makes it a little difficult to get "early warning" that you're going to run out of physical memory and start using swap.

By: rekha singh | 11 Mar 2010

That's not so much Red Hat is it is Linux memory management in general.

MemTotal: 4046472 kB
MemFree: 139840 kB
Buffers: 139572 kB
Cached: 2306640 kB
SwapCached: 4596 kB

FWIW, the Cached entry tells you how much of your ram is being used to simply cache recent data. That's what gets cleared out as real use increases. It doesn't, IIRC, include memory that's also cached in Swap.

The SwapCached tells you how much of the data that's currently cached also resides in the swap partition.

By: rekha singh | 11 Mar 2010

Leave a comment

Enter the text in the image
img
Can't read?
Type the characters you see in the picture below.


Close Move