Results 1 to 15 of 15

Thread: swap and ram

  1. #1
    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

  2. #2
    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...

  3. #3
    Join Date
    Aug 2009
    Posts
    77
    Quote Originally Posted by ttgt View Post
    i wonder what situation the data will save on swap and when on ram?
    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...

  4. #4
    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.

  5. #5
    Join Date
    Aug 2009
    Posts
    77
    Quote Originally Posted by petergrg View Post
    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.
    Think 64bit!

    2GB max might be true for 32bit architecture OS, although I haven't checked.

  6. #6
    Join Date
    Mar 2003
    Location
    chicago
    Posts
    1,781
    whoever told you that is clueless i have seen a server use 7 gigs of swap before.

    there is usually no reason to have swap bigger then 4 gigs.


    Quote Originally Posted by petergrg View Post
    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.

  7. #7
    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.

  8. #8
    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

  9. #9
    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.

  10. #10
    Join Date
    Jul 2010
    Location
    Thailand
    Posts
    891
    I think the objective is not to use swap at all because swap is sloooow.

  11. #11
    Quote Originally Posted by ThisOldMan View Post
    I think the objective is not to use swap at all because swap is sloooow.
    Agreed, you should avoid tapping into your swap, replacing intead with healthy amounts of RAM and good server tuning, other than that, yes in general it is fine to setup swap as double the amount of RAM

  12. #12
    Join Date
    Mar 2009
    Posts
    3,700
    Hi,

    if i do not setup swap,

    will system force ram to release space ?


    thanx

  13. #13
    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.

  14. #14
    Join Date
    Aug 2009
    Posts
    77
    Quote Originally Posted by ttgt View Post
    Hi,

    if i do not setup swap,

    will system force ram to release space ?


    thanx
    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.

  15. #15
    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

  1. Replies: 2
    Last Post: 08-02-2007, 12:05 AM
  2. Replies: 7
    Last Post: 07-21-2007, 05:11 PM
  3. Replies: 0
    Last Post: 07-05-2007, 01:04 AM
  4. Replies: 0
    Last Post: 06-05-2007, 08:03 PM
  5. Replies: 0
    Last Post: 05-14-2007, 10:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •