Slashdot Mirror


How Much Virtual Memory is Enough?

whitroth asks: "Ten years ago, Received Wisdom said that virtual memory should be, on the average, two to two-and-a-half times real memory. In these days, where 2G RAM is not unusual, and many times is not that uncommon, is this unreasonable? What's the sense of the community as to what is a reasonable size for swap these days?"

10 of 544 comments (clear)

  1. Depends by beavis88 · · Score: 4, Interesting

    My rule of thumb these days is 1.5x RAM, unless you're at 2GB, in which case I go with 2GB swap as well. This is for *gasp* Windows, though.

  2. Re:If you have enough, none by MyDixieWrecked · · Score: 5, Interesting

    not creating a swap partition at all is a bad idea, imo...

    you never know when some runaway process is going to eat all yer RAM and need to use swap... no matter how much RAM you've got.

    I typically just make a 1 or 2 GB swap partition since I've got more than enough space to spare. I mean, back in the days when 128MB of RAM was considered a lot, and a 5GB drive was considered huge, no one would consider using 20% of their storage space for swap. Now, it's not unusual to have 300GB of storage, so what's 1% of that being used for swap?

    I've also got a serious collection of 2-6GB harddrives kicking around, now, so I've been using them for swap. It's really pointless to have a 4GB partition for data, so I just use the entire 6GB drive for swap on some machines.

    my primary server right now has a 4GB swap partition and 1.25GB of RAM... a piece of bad AJAX code that ran overnight wound up using all the RAM and had some seriously detrimental effects on the performance of the server. it took 25 minutes to ssh in in the morning and when I finally got in, I found that the load averages were at over 100 (I've NEVER see that before).

    my point is that even if you have a LOT of RAM, it's still handy to have some spillover available.

    --



    ...spike
    Ewwwwww, coconut...
  3. Re:If you have enough, none by edmudama · · Score: 5, Interesting

    If you've got a 300GB primary drive, it's foolish to use a 5GB drive for your swap. While you gain the benefit of having that drive separate from the primary (and potentially not contending for the bus), those drives are so far apart technology wise that you'd probably be better off with a swap partition on your most modern disk.

    That 2/5/6GB drive may have a 20MB/s sequential rate at OD and half that at ID. Modern drives more than double that sequential performance (or triple), which is what's critical when swapping in/out a large job. Many drives in that generation don't support UDMA either, and talk with PIO, meaning you get no data checksum on your transfers.

    You can span generations when you're using a cost reduced modern drive (fewer heads, same formats) but the drive that was stretching to make 5GB across 6/8 heads will be a real POS compared to modern drives performance wise.

    Thrashing is bad, but thrashing to a slow disk I'd think would be worse. It is even compounded since that 5GB drive is probably PATA, meaning you're going to have your swap drive and primary drive sharing a cable, which will basically nuke most of the savings of 2 disks since they'll be reselecting master/slave at almost every command.

    --
    More data, damnit!
  4. Re:No swap at all by georgewilliamherbert · · Score: 4, Interesting
    If the server starts to swap, you've lost the battle. But randomly killing things or locking up is losing the war.

    It's fine to set off alerts and alarms if you're paging. You should set off alerts and alarms if your servers start paging. Randomly killing things instead? Insanity.

    You can never build reliable services for users/customers unless you can handle random or accidental error conditions gracefully. Swap space is a cheap and easy key way to do that.

  5. Re:Rules of thumb are dumb by Feyr · · Score: 4, Interesting

    all this swapping talk is giving me nightmares.

    a few years ago, we had a customer with multiple colocated servers complaining that sometimes they crashed for no apparent reasons.
    after much debugging, we figured out one of their script was leaking memory. eventually consuming all ram (2.5G) + all swap (1-2g).

    now the real problem is this. those were LIVE processes so the system was constantly paging back and forth, using 90%-95% cpu just to swap the damned things in and out and starving the actual processes.
    linux 2.4, linux 2.6 (early 2.6). same deal. amazingly, the distro made a difference, redhat was pure hell, debian slightly better (though still not acceptable)
    freebsd was much smarter, it just killed the offending processes.it sure wasn't ideal, but at least the server was still serving its clients

    to this day, i never put more than 256m as swap even on servers with 4G of ram. that's where we had the least problems.

  6. Re:If you have enough, none by fuzz6y · · Score: 4, Interesting
    you never know when some runaway process is going to eat all yer RAM and need to use swap... no matter how much RAM you've got.
    You never know when some runaway process is going to eat all yer RAM and swap combined, no matter how much swapspace you've got.
    a piece of bad AJAX code that ran overnight wound up using all the RAM and had some seriously detrimental effects on the performance of the server
    too bad you had all that swapspace for it to run rabid across. if you'd had no swap at all, 1 of 2 things would have happened:
    1. the kernel kills the process because of a low memory condition
    2. an attempt to allocate memory fails. The application then handles this somehow. Since we've established that it's a lousy application, I'd guess it handles it by crashing.
    Either way, the Dude^W server abides.
    Naturally if you actually had that much physical RAM, the process would have still gone nuts, but your server wouldn't have had to thrash its disk for every process except the prodigal son, so the performance hit probably wouldn't have been noticeable.
    --
    If you're going to be elitist, it would help to be elite.
  7. Are you using tmpfs or not? by hpa · · Score: 5, Interesting

    One thing to consider is whether or not you're using tmpfs for /tmp. For performance, I recommend using tmpfs for /tmp, and basically treat the swap partition as your /tmp partition. It may seem counterintuitive, "why would it be faster than a filesystem when it's backed to disk anyway, and my filesystems caches just file if need be?" The answer is that tmpfs never needs to worry about consistency. On the kernel.org machines, we have seen /tmp-intensive tasks run 10-100 times faster with tmpfs than with a plain filesystem. The downside, of course, is that on a reboot, tmpfs is gone.

  8. Is swapping obsolete? (was:Rules of thumb are dumb by Jeremi · · Score: 4, Interesting
    To this day, i never put more than 256m as swap even on servers with 4G of ram. that's where we had the least problems.


    That raises the question: is swapping obsolete? Or to put it more explicitly, has the speed difference between modern CPUs and hard drives become so large, and RAM so cheap, that it's better to consider running out of RAM to be indicative of a software failure? That way you end up with a system where one or more processes may fail (or be terminated) but at least the machine remains usable and doesn't swap itself into non-responsiveness.


    In my experience, the answer is yes: with 2GB of RAM in my machine, I never need to swap, and in the few instances where swapping did occur, it was because of buggy software (memory leaks) and manually terminating the offending processes is what I needed to do resolve the memory shortage. So why not just have the OS do that automatically?


    Or to put it a third way, is there any situation where swapping is helpful, anymore?

    --


    I don't care if it's 90,000 hectares. That lake was not my doing.
  9. gig of RAM costs 50 times more than a Gig of HDD by da5idnetlimit.com · · Score: 4, Interesting

    And is 1000 times faster ?

    So, to answer the original question :
    Optimal amount of Swap ? 0 !

    Even my old PIII 1Ghz takes 2 gigs of ram. Newest system we have at the office takes 64 Gigs.

    => right now I consider the Linux systems @ work as having a problem if they use swap...

    Adding just a wee bit of RAM to your system and seeing swap disappear means your perfomance just exploded on this particular task...

    Best Regards,

    D.

    --
    It takes 40+ muscles to frown, but only four to extend your arm and bitchslap the motherfucker
  10. Re:gig of RAM costs 50 times more than a Gig of HD by mrball_cb · · Score: 5, Interesting

    We've found that 512 Megs of swap is more than enough for our 2 and 4 Gig machines. Why even have swap? Here is an example:

    1) On a system with zero swap, when apache gets slammed (say you get to the top of digg or slashdot), apache starts consuming lots of memory to handle new inbound requests. When it runs out, the machine grinds to a halt because it can't allocate more and requires a power cycle. (Setting a low max children really only helps if you are happy denying traffic to the people who are trying to see your site...it's best to plan for capacity and put quite a few servers load balanced).
    2) On a system with any appreciable swap (IMHO, more than 128 Megs, up to 512 Megs), if you're monitoring the system (watch -n 1 df -h, for example) and all of a sudden it starts using swap, the machine is on the edge of dying. This gives you an early warning that maximum machine performance/throughput is occurring. You can restart apache or shut it down or similar, you can do something to temporarily lower or remove load from that machine. This doesn't give you *much* time, but it gives you some.

    In our real world experience, at digg and slashdot loads you have about 10-15 seconds to stop apache once it starts swapping. After that, the performance degrades so bad that the machine becomes catatonic, the same as #1, requiring a power reset (obviously because virtual memory on HD is magnitudes slower than RAM, as numerous others have suggested). The key here is that you must realize that some swap is good for allowing unused programs to be swapped out, such as login terminals that just sit there. It's great for detecting problems, but if your heavy app is the one utilizing swap, your machine is about to crash anyway.