Find the answer to your Linux question:
Results 1 to 6 of 6
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Realistic SWAP space sizes

    Reading the OLD swap standard that is quoted everywhere on the web :

    "The size of your swap should be equal to twice your computer's physical RAM for up to 2 GB of physical RAM. For physical RAM above 2 GB, the size of your swap should be equal to the amount of physical RAM above 2 GB. The size of your swap should never less than 32 MB."

    This doesn't seem reasonable with large servers and new kernels. I have a system with 64GB of memory in it and based on this formula I should have a 66GB swap partition ((2 x 2GB) + (62 x 1GB)).

    Running RHEL5 on mirrored 146GB drives with 64GB of memory, I don't ever expect to touch the swap space. Setting aside 66GB (45%) of my disk space for something I don't ever plan to use seems ridiculous.

    I was told that a Kernel dump should never exceed 2GB.

    I was also told that you should never set aside more than 2GB for swap unless you have special circumstances that require a large amount of swap.

    I was also told that Linus Torvalds once said something like "You should use the same amount of swap space as you have physical memory up to 2GB, but no additional swap space after 2GB of physical memory."

    I have done brief searches to try to determine the sources for the 3 statements above but haven't found them yet, but I believe them to be true.

    Any light you can shed on the subject would be appreciated as I'd like to have a firm reference point to base my future server installs upon.

  2. #2

  3. #3
    That post is similar to mine, but I am asking additional questions and mentioned things I was told (which I hoped to be corrected on or to have vindicated by another source). Thanks for the link though, I'll continue to read both posts.

    I was hoping to get some people offering up ways to calculate how much swap I really need to for people to send me links to pages where experts have recommended "no Swap" or "2GB max swap" etc....

  4. $spacer_open
  5. #4
    There is no "magic formula." If you are not satisfied with taking someone else's suggestion, then you need to get an understanding of how Linux uses swap (which is not identical to other *Nix's), what applications YOU are running, and how the two relate.

    This is circa 2004, and I would say that swap has become even more obselete since then.

    If I have a 64GB system that I needed top performance out of, I would have no swap and change the swappiness to 0. I can always add swap later. (And assuming my apps run easily inside that 64GB. I can only see something like large DB servers running TB-sized tables going through that - and that also can be controlled via DB tuning.)

    For smaller systems (2-8GB RAM), I still create ~1GB swaps just for reasons mentioned in the article above. I typically see less than 100MB going into swap, even after months of uptime.

    A 4GB *desktop* system after 45 days of uptime (used everyday) - with the default "swappiness":

    Tasks: 169 total,   3 running, 166 sleeping,   0 stopped,   0 zombie
    Cpu0  :  1.7%us,  1.2%sy,  0.0%ni, 96.5%id,  0.6%wa,  0.0%hi,  0.0%si,  0.0%st
    Cpu1  :  2.1%us,  1.7%sy,  0.0%ni, 96.0%id,  0.2%wa,  0.1%hi,  0.0%si,  0.0%st
    Mem:   4018640k total,  3829492k used,   189148k free,    56544k buffers
    Swap:        0k total,        0k used,        0k free,  2180796k cached
      4:40pm  up 45 days  3:50,  8 users,  load average: 0.23, 0.27, 0.21
    cat /proc/sys/vm/swappiness 

  6. #5
    As a coincidence, these systems (8 & 16 core x86_64) will be running a large DB Cluster with very large tables on an external storage array.
    I am installing and tuning the OS for it's needs and will let the DB experts tune the system settings more for the DB's needs.

    Nice article link by the way

    Most servers I install/configure have 4 - 8 GB of RAM and don't run Oracle so I am looking for swap information to cover those systems as well.

    I'm also not sure if the number of processor cores would have an effect on how much swap to allocate either (1 - 32 cores) in an x86_64 environment so I guess that is another question. I would assume "NO" at this point since the kernel shouldn't use swap differently when more cores are present, but I don't claim to be an expert on kernels or swap.

  7. #6
    Just Joined!
    Join Date
    Mar 2005
    Lincoln, NE
    2GB of swap is plenty. Here's why:

    • The OS itself will not have enough utilities/daemons running to come close
      to occupying 2GB of swap w/ rarely used pages.
    • The reason for having 64GB of memory on servers _is_ for cache/buffers to
      store recently used pages from disk, and in the case of a database server,
      buffered transactions and cached disk writes.
    • A server will be running a handful of programs that will be using the
      majority of the memory in the form of cache/buffers. These programs may have
      some pages that can be swapped out, but-- using a DB server as an example
      again, the DB program executable _itself_ isn't what has the big memory

    This would be different in the case of a desktop system with 1GB of memory where you might be running several dozen userspace programs. 2GB of swap in this usage scenario makes sense as many of the programs may be idle and having their unused pages in memory is wasteful. Those pages are better used for cache and buffers.

    Having 66GB of swap is a complete waste of space, especially on a server. What
    could you possibly be swapping (ok, paging out-- subtle clarification) that is
    even close to that big? I'm willing to bet all of the services/daemons,
    programs (even many instances of the same program), etc on the entire server don't add up to 66GB (their data files don't count as they would never end up in swap).

    I think 2GB is plenty and I doubt it would ever be fully utilized. If that
    _just_ doesn't seem like enough, then make it 4GB. 66GB of swap is just

Posting Permissions

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