Results 1 to 15 of 15
Thread: swap and ram
-
01-19-2011, 08:47 AM #1Web Hosting Master
- Join Date
- Mar 2009
- Posts
- 3,700
swap and ram
Hi,
for dedicated server,
i would setup swap as 2X of ram,is it ok?
i wonder what situation the data will save on swap and when on ram?
thanx
-
01-19-2011, 10:58 AM #2Junior Guru Wannabe
- Join Date
- Aug 2009
- Posts
- 77
In general, that is fine, although not always... it depends how much RAM you have?
If you have very low end 512MB RAM dedi, I'd go even 4 x that (2GB swap).
For 1 - 2GB RAM, 2 - 4GB swap is just fine.
If you have high-end 24GB RAM server, I wouldn't spend more than ~ 8GB on swap.
So, it depends...
-
01-19-2011, 11:04 AM #3Junior Guru Wannabe
- Join Date
- Aug 2009
- Posts
- 77
Linux first uses all available RAM, for programs, page cache, etc... Depending on the workload, if there's memory shortage some memory pages will be pushed to the swap. If they're unused for a long(er) time, they'll stay there. That's fine.
But, if you have real memory shortage, trying to run more at the same time than you have available memory, pages will keep going to swap, and returning from there back to memory, slowing down the whole system because of additional swap I/O.
It is always better to have enough memory, and swap only as the last resort, for a short lived temporary overloads or similar...
-
01-19-2011, 11:38 AM #4Newbie
- Join Date
- Jan 2011
- Posts
- 23
I am not sure, any way I heard from some one that the maximum swap space which can assign is max upto 2 GB and if you assign more than that, it will remain unused for ever.
Actually the 2X rule of swap is for systems with 1 GB RAM or less.
-
01-19-2011, 12:15 PM #5Junior Guru Wannabe
- Join Date
- Aug 2009
- Posts
- 77
-
01-19-2011, 12:45 PM #6Web Hosting Master
- Join Date
- Mar 2003
- Location
- chicago
- Posts
- 1,781
-
01-19-2011, 01:10 PM #7Junior Guru
- Join Date
- Apr 2008
- Location
- Austin, TX
- Posts
- 202
2x swap is a good rule of thumb.
However, if you're using that much swap, things will be very very slow.
-
01-19-2011, 01:28 PM #8Web Hosting Master
- Join Date
- Mar 2009
- Posts
- 3,700
Hi,
if my set the swap to 1G only with 4GB ram,
will it have less io issue than 4G or 8G swap ?
thanx
-
01-19-2011, 02:26 PM #9Junior Guru Wannabe
- Join Date
- Aug 2009
- Posts
- 77
ttgt, if you have system tuned in a way that swap is not needed, it doesn't make difference if you have 1GB or 4GB of swap. If the system is not swapping, those 1 - 4GB are just lost disk space (but everything will work fine and fast).
OTOH, if you're pushing memory to the limit, once again it's not terribly important if you have 2, 4, or 24GB of swap. Your system will be slow, because your apps will wait for disk I/O which is much much slower than CPU/RAM.
If you have 4GB of RAM, I'd say go with 2GB swap and don't worry about that, unless you get into trouble. Even in that case, you'll need to tune your workload (applications etc...) NOT your swap size.
-
01-19-2011, 06:06 PM #10Web Hosting Master
- Join Date
- Jul 2010
- Location
- Thailand
- Posts
- 891
I think the objective is not to use swap at all because swap is sloooow.
-
01-19-2011, 07:41 PM #11Newbie
- Join Date
- Jan 2011
- Posts
- 10
-
01-19-2011, 08:55 PM #12Web Hosting Master
- Join Date
- Mar 2009
- Posts
- 3,700
Hi,
if i do not setup swap,
will system force ram to release space ?
thanx
-
01-19-2011, 09:49 PM #13Web Hosting Master
- Join Date
- Jul 2010
- Location
- Thailand
- Posts
- 891
Not sure if the os will run without swap being setup. I have seen some Xen vps which do not have swap, though. Don't actually see much use for swap.
-
01-20-2011, 03:37 AM #14Junior Guru Wannabe
- Join Date
- Aug 2009
- Posts
- 77
Yes, you can also run without swap, everything will work fine. You just have to be extra careful not to get into OOM (out of memory) condition, because that would end up in deadlock (or kernel killing your processes to recover).
Typically, you'll need to test how much memory apache wants to use and set MaxClients directive so that even with apache connections at max you're not close to exhausting all the memory. Or switch to php-cgi setup, which uses much less memory than typical apache + mod_php setup, and also memory usage doesn't change depending on the load.
With 4GB RAM, running without swap on Linux should be possible and easy.
-
01-20-2011, 05:07 AM #15NetOps Guy
- Join Date
- Jan 2005
- Location
- San Francisco/Hot Springs
- Posts
- 991
The amount of swap really depends on a few things, but having less than 1X the physical ram is not a great idea for a few reasons; you need at least 1x to store a kernel core dump, you may have one process that runs large and you'll need to swap out large stuff to keep the system running. Having less swap is really not worth the potential pitfalls.
AppliedOperations - Premium Service
Bandwidth | Colocation | Hosting | Managed Services | Consulting
www.appliedops.net
Similar Threads
-
XEN VPS | 128 RAM/.5Mbps BW/256 SWAP $10/mo | 256 RAM/1Mbps BW/512 SWAP $20/mo LIFE!
By Senad in forum VPS Hosting OffersReplies: 2Last Post: 08-02-2007, 12:05 AM -
XEN VPS | 128 RAM/.5Mbps BW/256 SWAP $10/mo | 256 RAM/1Mbps BW/512 SWAP $20/mo LIFE!
By Senad in forum VPS Hosting OffersReplies: 7Last Post: 07-21-2007, 05:11 PM -
XEN VPS | 128 RAM/BAND./CPU/256 SWAP $10/mo | 256 RAM/BAND./CPU/512 SWAP $20/mo LIFE!
By Senad in forum VPS Hosting OffersReplies: 0Last Post: 07-05-2007, 01:04 AM -
XEN VPS | 128 RAM/BAND./CPU/256 SWAP $10/mo | 256 RAM/BAND./CPU/512 SWAP $20/mo LIFE!
By Senad in forum VPS Hosting OffersReplies: 0Last Post: 06-05-2007, 08:03 PM -
XEN VPS | 128 RAM/BAND./CPU/256 SWAP $10/mo | 256 RAM/BAND./CPU/512 SWAP $20/mo LIFE!
By Senad in forum VPS Hosting OffersReplies: 0Last Post: 05-14-2007, 10:26 AM