Become a fan of Slashdot on Facebook


Forgot your password?
Upgrades Hardware

How Big Should My Swap Partition Be? 900

For the last 10 years, I have been asking people more knowledgeable than I, "How big should my swap be?" and the answer has always been "Just set it to twice your RAM and forget about it." In the old days, it wasn't much to think about — 128 megs of RAM means 256 megs of swap. Now that I have 4 gigs of RAM in my laptop, I find myself wondering, "Is 8 gigs of swap really necessary?" How much swap does the average desktop user really need? Does the whole "twice your RAM" rule still apply? If so, for how much longer will it likely apply? Or will it always apply? Or have I been consistently misinformed over the last 10 years?

This discussion has been archived. No new comments can be posted.

How Big Should My Swap Be?

Comments Filter:
  • What Has Changed? (Score:5, Informative)

    by eldavojohn ( 898314 ) * <eldavojohn AT gmail DOT com> on Wednesday October 01, 2008 @06:39PM (#25225907) Journal

    'Is 8 gigs of swap really necessary?'

    With a 750GB [] hard drive selling under $100, what has changed?

    Yeah, your 256MB of space was trivial when you had a 30GB hard drive ... and 8GB of space is still trivial with a 750GB hard drive.

    That said, I'll forward you some common information on paging [].

    Linux and other Unix-like operating systems use the term "swap" to describe both the act of moving memory pages between RAM and disk, and the region of a disk the pages are stored on. It is common to use a whole partition of a hard disk for swapping. However, with the 2.6 Linux kernel, swap files are just as fast as swap partitions, although Red Hat recommends using a swap partition. The administrative flexibility of swap files outweighs that of partitions; since modern high capacity hard drives can remap physical sectors, no partition is guaranteed to be contiguous.

    I'm no expert but the short answer to this is to look at your swap partition as your extended virtual memory. By saying that your swap partition should be 2x your main memory is like saying that you will never use 3x of what your main memory is (in this case 12GB). While that rule of thumb is a good one, there may in fact be applications today in the graphics and processing world that require insane amounts of memory. While Firefox is probably never going to reach that critical mass (nor will most average programs) it's probable that a few years from now it will be common place. I know it's insane to think of but 'ought to be enough for anybody' is not the phrase you want to throw around in the digital information world.

    It's those days when I'm playing Warcraft through wine, listening to streaming radio through Amarok, have 20 windows open behind it, idling a LAMP server for my development projects, running a vent client, some form of news aggregater, pidgin & an e-mail client hooked up to several POP3/IMAP accounts that I am happy I erred on the side of a whole ton of swap space.

    • by meringuoid ( 568297 ) on Wednesday October 01, 2008 @06:49PM (#25226063)
      Yeah, your 256MB of space was trivial when you had a 30GB hard drive ... and 8GB of space is still trivial with a 750GB hard drive.

      I have an Eee 901. It has 1GiB of RAM and 20GB of disk space. A swap partition on the 'twice your RAM' rule would be far from trivial.

      I decided to be bold and installed Hardy with no swap partition. It seems to work just fine so far; Firefox greys out for a few seconds sometimes while loading pages, which might have to do with my reckless configuration, but on the whole it's pretty snappy.

      As for my desktop PC, it has 4GiB of RAM. I followed the traditional rule when I installed on that. I don't think that swap partition has ever even been used.

      • by RiotingPacifist ( 1228016 ) on Wednesday October 01, 2008 @07:01PM (#25226229)

        consider using a swap file for your setup id recommend 256mb of swap, with 1.25gb of ram (apart from when i left wireshark running for toolong) ive not seen it creep above ~100mb for long.

      • by orzetto ( 545509 ) on Wednesday October 01, 2008 @07:25PM (#25226491)

        I have an Eee 901 [...] I decided to be bold and installed Hardy with no swap partition.

        There are better reasons than boldness for not using swap on an Eee. They use solid-state drives (except some 1000-series models and the 904), which are faster than mechanical devices but can be rewritten fewer times. To make sure your drives last longer, do the following []:

        1. Mount partitions with noatime, or relatime if you are using one of the very rare programs that use atime (mutt is the only one I know of);
        2. No swap partition, which would predictably have many more writes than the rest of the disk;
        3. Mount /tmp on tmpfs so that temporary files do not wear the disk.

        Sure, without swap and with tmpfs you will have less memory available, but I have an Eee 900A and I bought it as a presentation machine, possibly for some occasional work while travelling, not as a workhorse.

        • by Anonymous Coward on Wednesday October 01, 2008 @08:15PM (#25227027)
          what on earth is the point? have you actually looked at how many rewrites the disks get, and how the wear levelling algorithms work? your Eee will be years old, and worthless, long before the disk runs out of write cycles
        • Re: (Score:3, Informative)

          by PCM2 ( 4486 )

          They use solid-state drives (except some 1000-series models and the 904), which are faster than mechanical devices but can be rewritten fewer times.

          Actually, on my Eee PC 901 they're not even faster than normal drives. The stock Eee PC comes with one boot drive that seems to run at more-or-less "normal" speed, and one larger "data drive" that seems ... slow. The slowness is especially noticeable during writes. For example, when I stored my Firefox profile on the data drive, I could expect a 1-4 second pause every time I loaded up a Web page, during which the program would be unresponsive. Presumably this happened when Firefox was writing to its cache,

      • by kasperd ( 592156 ) on Wednesday October 01, 2008 @07:31PM (#25226553) Homepage Journal

        I have an Eee 901. It has 1GiB of RAM and 20GB of disk space.

        I suppose that is not really a disk but rather flash storage. Swapping to flash is not the best idea as it could cause the flash to last shorter than it should. So I'd say this is probably one of those cases where no swap is the correct configuration.

        • Re: (Score:3, Interesting)

          by Mr Z ( 6791 )

          Having a swap partition doesn't necessarily mean having a lot of swap traffic. Often what gets placed in swap are portions of the heap that got allocated, but won't be referred to for quite some time. It gives room for other types of pages (as I mention here []).

          That said, if what you're doing doesn't cause a lot of thrashing when there is no swap, don't add swap on your flash SSD.

      • Re: (Score:3, Informative)

        by apoc.famine ( 621563 )
        Actually, the graying out of firefox isn't related to swap. On my EEE 4gb it happens as well. I have 1gb of ram, and put in a 4gb SD card which holds my tmp, swap, and var directories. I have 160mb of ram free, and the swap isn't being touched.

        I'm not 100% sure, but I think firefox grays out when trying to crunch big script(s) - it might be pegging the processor, but I don't know for sure. I've been meaning to track down the issue, but have been too lazy to so far. If anyone knows the cause/fix, I'd love t
      • by PAjamian ( 679137 ) on Wednesday October 01, 2008 @07:54PM (#25226817)

        Linux will use swap sometimes even if you don't fill up your RAM. It can swap out idle programs and use the recovered RAM for file caching which gives a performance boost to the file system.

        • by piojo ( 995934 ) on Wednesday October 01, 2008 @10:16PM (#25228193)

          Linux will use swap sometimes even if you don't fill up your RAM. It can swap out idle programs and use the recovered RAM for file caching which gives a performance boost to the file system.

          Conversely, if you have enough ram for file caching and running applications, then you will get a performance boost from disabling swap (because applications would be faster if they weren't ever swapped out).

      • Re: (Score:3, Interesting)

        Kind of like running a LiveCD all the time.

    • Re: (Score:3, Informative)

      by srothroc ( 733160 )
      Just some stupid math, but if you figure that you had a 40 GB HD when you had 128 MB RAM, you'd need 256 MB for swap space; that's about .006% of your hard drive. Windows installs were also correspondingly smaller at that time.

      Now, if you suppose that someone has 4 GB RAM and a 750 GB drive, they'd be using 8 GB for swap space, which represents about .011% of their hard drive... and Windows installs, games, and applications are much bigger.

      HOWEVER, if you look at smaller drive sizes, which are still c
    • by ( 912690 ) on Wednesday October 01, 2008 @07:07PM (#25226307)
      The real question is; is that 750GB drive really 20 times faster than the older 30GB one?
    • by Sj0 ( 472011 ) on Wednesday October 01, 2008 @07:39PM (#25226621) Journal

      You present several arguements, but none of them are really very good.

      Honestly, why does the 2x RAM guideline make any sense? Why is it that when I upgrade my 1GB to 8GB, I suddenly need 16GB of swap space, even though my total RAM+SWAP was less than half of my current memory? That makes no sense. Why should I want to increase the amount of swap I'm using if I've never used half the RAM I've got in the life of the computer?

      How about we practice some Engineering? I know, it's slashdot, it's a tough thing to do, but bear with me.

      So you've got a computer, and you know what you do with it. Simply do what you'll do, and figure out the peak memory usage over a period of time. Add 50% or so to get a target memory value, and if your current memory exceeds that value and thus you've got more than enough to never have to hit swap, pick a small number like 256MB for your swap partition to satisfy applications which demand swap even when enough memory is available. If you don't have enough memory, then create a swap file to make up the memory shortfall.

      Seriously, some of the suggestions for swap are impractical. If you're using 24GB of memory in my hypothetical, and your hard drive can only transfer 16MB of memory at once, you're not using your computer anyway because it's too slow.

      • Re: (Score:3, Informative)

        by adolf ( 21054 )

        Because if you've already successfully chewed through 8GB of RAM, having an extra 256MB of swap available just in case isn't likely to be a very meaningful stop-gap.

        The other advantage of swap, which I've not seen anyone discuss here yet, is that unused programs and data will be flushed out of RAM to make room for more buffers and cache.

        Might not seem like a big deal, either, but: Suppose you've got OpenOffice and Firefox open, but you haven't used them for awhile. They're each using a few hundred megs of

      • by jamonterrell ( 517500 ) on Wednesday October 01, 2008 @10:44PM (#25228387)
        The 2x RAM guideline makes perfect sense, though as someone mentioned elsewhere, Oracle's guideline ( is better. The recommendation assumes that you need as much memory as you have. Early on in computing this was almost certainly the case, nowadays, memory is so cheap that a lot of people buy more than they need (me included). If in fact you have 4GB and you actually use the 4GB of memory regularly, then having an additional 4GB of swap space to store the stuff you aren't CURRENTLY using makes perfect sense. (Though it makes more sense on servers than on desktops :)
    • Re: (Score:3, Interesting)

      I'd agree that the relative size of 8G page space is probably smaller than a 512M partition a while ago... However, some corrections:

      Technically swap space is not page space, though the distinction is being blurred quite a bit. Swap space was used to actually swap out entire processes, while page space was used to page out memory, er, pages. I'll use swap here :D

      The wikipedia link is a little incorrect. In many cases a swap partition can be more efficient than a swap file at least in Linux. For one, there'

  • by 42forty-two42 ( 532340 ) <bdonlan@gm a i l .com> on Wednesday October 01, 2008 @06:43PM (#25225965) Homepage Journal

    The origin of the 'twice real RAM' came in the early days of windows, in which windows could not use any swap unless you had at least as much as real RAM. That's been gone for ages now - and you should actively avoid too much swap.

    If you allocate, say, 8G of swap for 4G of RAM, most of the time almost all of it will go unused. If it actually /is/ used, your machine has probably spent the past hour or so frantically swapping to try to accomidate this 12G request; ie, your system is completely unresponsive due to every program being mostly swapped out. The additional swap merely delays the out of memory event, and in the meantime you can't control the machine.

    Swap is still useful for holding data that's not part of the working set, in order to free memory for cache; but this shouldn't be very much RAM (256-512mb should be enough). It's also useful for software suspend on linux - if you have a laptop, make it a little bit larger than physical RAM. And always have /some/ - linux's memory manager doesn't like having none.

    • Oh, nonsense (Score:4, Informative)

      by Anonymous Coward on Wednesday October 01, 2008 @06:51PM (#25226097)

      2X RAM was the standard rule of thumb at Sun, for SunOS long before Windows was around.

      If anything, Microsoft ripped it off from Sun.

      • Re:Oh, nonsense (Score:5, Interesting)

        by Obfuscant ( 592200 ) on Wednesday October 01, 2008 @07:27PM (#25226501)
        Here's my understanding of the "rule".

        In early Unixes (SunOS, e.g.), the memory manager was dumb and preallocated swap space sufficient to swap your entire process out if it became necessary, and it really did want contiguous. Running out of swap was common, even if it was really never used, and the "rule" to avoid that problem was 2xRAM. Further, if you had two swap partitions, or a partition and a file, your process stayed in whatever swap it started in and did not split across both. You could be out of swap space and still have a completely empty swap file.

        Memory managers have gotten smarter, mapping smarter, and now swap is only used when it really is necessary. Pages that are not dirty don't get swapped, they get reloaded from the disk they came from. Pages that are swapped are often used soon enough that they never leave the RAM buffers.

        Yesterday, I had a user come to me saying he was getting an "out of memory" error from Matlab. Matlab is notorious for not garbage collecting when it needs to. His Matlab process had 800Mb of resident memory, even though he said he had just 300Mb of data. The kicker? Somehow, over the last couple of years, the swap file I had created to extend the 512Mb swap partition had gotten lost. Dunno where it went, just not there. He had 512Mb of swap, and most of that wasn't being used. Never noticed it until yesterday. His 2Gb of RAM was sufficient for what he was doing.

        It's a case of people who learned early just doing what they know works, telling youngsters the "rule" so they do the same thing.

        • Re:Oh, nonsense (Score:5, Informative)

          by Caduceus1 ( 178942 ) on Wednesday October 01, 2008 @10:32PM (#25228317) Homepage

          Yes, I believe it was the BSD memory manager (possibly earlier, V7 maybe) that had the 2xRAM rule. Less and you could have issues - more was wasted disk space.

          BSD was the foundation for SunOS (pre-Solaris 2.X), Ultrix, etc. so they all inherited this requirement - and from there the "requirement" became gospel on other systems.

          I've actually never heard the 2xRAM in relation to Windows, but it certainly predates it. I was setting up systems with 2xRAM when Windows was a DOS app... :)

    • by pete-classic ( 75983 ) <> on Wednesday October 01, 2008 @06:55PM (#25226145) Homepage Journal

      your system is completely unresponsive due to every program being mostly swapped out.

      Uh, report this to your vendor as a bug. No amount of swap space should cause your system's memory manager to make such lousy decisions.

      And, in fact, having an "unreasonable" amount of swap can actually pay off. If your system can swap out really stale memory to disk and use the RAM to cache stuff on disk that you might actually want, you're going to see a really big performance gain.


  • What Oracle Wants (Score:5, Informative)

    by stoolpigeon ( 454276 ) * <bittercode@gmail> on Wednesday October 01, 2008 @06:43PM (#25225967) Homepage Journal

    If you were running Oracle - here is what they recommend:
        RAM -> Swap Space

        1 GB - 2 GB -> 1.5 times the size of RAM
        2 GB - 8 GB -> Equal to the size of RAM
        more than 8GB -> 0.75 times the size of RAM

    I don't know if this would carry across to general computing - it seems to me if it's enough for an Oracle RDBMS server, it ought to do it for most things.

    • Re: (Score:3, Informative)

      for a server thats probably about right, on a desktop where stability is not quite as important id go with about half that

  • by Vexler ( 127353 ) on Wednesday October 01, 2008 @06:45PM (#25226003) Journal

    Reading through OpenBSD's FAQ:

    "The 'b' partition of your root drive automatically becomes your system swap partition. Many people follow an old rule of thumb that your swap partition should be twice the size of your main system RAM. This rule is nonsense. On a modern system, that's a LOT of swap, most people prefer that their systems never swap. You don't want your system to ever run out of RAM+swap, but you usually would rather have enough RAM in the system so it doesn't need to swap. If you are using a flash device for disk, you probably want no swap partition at all. Use what is appropriate for your needs. If you guess wrong, you can add another swap partition in /etc/fstab or swap to a file later."


  • Just test? (Score:5, Informative)

    by rasteri ( 634956 ) on Wednesday October 01, 2008 @06:45PM (#25226007) Journal
    Just make a note of your virtual memory use every hour or so (or just whenever you remember) for a few days/weeks. Then just give yourself maybe 2-3 times the peak usage.

    I imagine different people will need different amounts of swap space, so use a size that's right for you.
  • by bugg ( 65930 ) * on Wednesday October 01, 2008 @06:46PM (#25226019) Homepage

    If you're debugging your kernel or are helping people to debug your kernel, and are generating crashdumps either manually or as a result of kernel panic, you need your swap to be twice as big as the memory so it all fits comfortably (You can probably get away with X times bigger, where 1X2, but 2 is a safe number).

    To my understanding that's always been the reason for the rule of thumb about doubling the memory. If you can afford the disk, go for it, because you never know when you might hit a panic and need crashdumps. If you are in a live environment and are sure you will never, ever need or even want crash dumps, and the disk space is at a premium, you can size it based on need.

    Another thing to keep in mind is that as you have more ram, you have more pages, and the whole point of swap is to get pages to disk as well in case you need to free up physical ram quickly.

  • by Britz ( 170620 ) on Wednesday October 01, 2008 @06:48PM (#25226041)

    Whatever you do, you need to remember to setup you swap partition to as large or bigger than your ram in order to be able to use the "suspend to disk" function in Linux. On older laptops suspend is sometimes handled by the bios. Then you need a special partition. But nowdays Linux just suspends to your swap. And if your memory was full ...

    • Re: (Score:3, Informative)

      by FauxPasIII ( 75900 )

      For built-in suspend this is true. TuxOnIce [] offers, among other things, suspend-to-file support which eliminates the need to keep gobs of swap around if you don't want to.

  • by jmorris42 ( 1458 ) * <> on Wednesday October 01, 2008 @06:49PM (#25226069)

    Forget the RAM X 2 rule. Capacity of drives are way up, base RAM load is way up. Drive transfer speed isn't up very much. Doesn't really matter how much ram you have, long before you get a Gig of swap utilized the system is going to be trashing to the point of being unusable under any but lab conditions.

    Running with no swap can cause some problems, because it does help if the system can push out blocks of memory that aren't backed by a file and also haven't been used for awhile. Still on an all flash system with an adequate amount of RAM running without swap is probably the right move. On a machine with a spinning disc give it a 1GB swap and forget it.

    The exception being in cases where the a system is doing suspend to disc into the swap. I don't have any Linux machines that will do suspend to disc so don't ask me about any details.

  • by rcoyner ( 1376393 ) on Wednesday October 01, 2008 @06:50PM (#25226077) Homepage
    In the end, it depends. If you are running several memory intensive applications you're going to want more swap space. At the very least, you should have as much as your RAM because when you hibernate it takes all the pages in your RAM and puts it into the swap space before powering off your computer. I wrote about this a while ago: []
  • by hpa ( 7948 ) on Wednesday October 01, 2008 @06:55PM (#25226133) Homepage

    I personally prefer to put /tmp on tmpfs, and combine with a large swap partition (much larger than 2x RAM). tmpfs is a lot faster than a regular filesystem *even if it has to hit disk*, simply because it doesn't have to care about consistency. If the machine goes down, the data disappears.

  • 0 MB (Score:3, Insightful)

    by timeOday ( 582209 ) on Wednesday October 01, 2008 @06:55PM (#25226139)
    I have run linux systems without swap for years without trouble, including the laptop I'm on right now.

    On a system with adequate RAM, the primary effect of swap is to make the system bog down before it crashes when a runaway process tries to allocate a huge amount of memory.

  • by discord5 ( 798235 ) on Wednesday October 01, 2008 @06:55PM (#25226143)

    How big should my swap be?

    It really depends on what you're planning on doing with the machine:

    • If you're using XFS on large volumes (eg 10TB on a fileserver), you'll need a lot of swap for xfs_check.
    • If it's a desktop, you probably don't want to start swapping too much, so you want lots of RAM. I usually add as much swap as I have RAM. I gave up on the "twice the amount of RAM" rule years ago. If you're swapping that badly on a desktop you won't have a comfortable "desktop experience" anyway.

    It really depends on what you're doing. A simple firewalling machine will never need to swap. Low trafic websites and mailservers will probably hardly ever need it.

    Also, you can always add swap later if you resize another partition. It really isn't that much of an issue, so pick a value and adjust according to your needs.

  • by Databass ( 254179 ) on Wednesday October 01, 2008 @07:02PM (#25226257)

    Maybe we should be asking "should we even bother with swap files?". I took a class on that where we calculated the steps it takes to get the final memory address in a paged memory system. It was something like 36 steps per address! We had PDEs, PTEs, convert this, change that. I didn't grok all the steps, but I do know there were a lot of them. I know 36 steps per little itty bitty piece of memory is a lot, even if you are a very fast CPU, when you have to do this hundreds of millions of times.

    Back in the day, it made sense to convince your programs you had an extra 100 megs of RAM, because a lot of programs needed that and didn't have it in memory. Today, memory is more abundant than things we would really need it for at the non-industrial level. I don't personally have any non-industrial applications that will fill up 4 gigs of RAM. Even Vista + WoW won't take up all that.

    So, and my professor suggested this, maybe the ideal swap size is ZERO. What if your operating system just operated under the concept of "If you can't fit it in 4 gigs, tough. Just wait until memory is free. I'm not even going to bother to split memory into pages because I'm always going to use RAM, not a hard drive page. Case closed." We could save so much overhead and complexity if we just admit that we never need to pretend hard drive is RAM. With 4 gigs or more of RAM, why even have a glacial slow hard drive in the mix?

    • Re: (Score:3, Informative)

      by Anonymous Coward

      Either your professor is an idiot, or you had no understanding what (s)he was talking about.
      Swap is not the reason for paging. Memory fragmentation between programs is the reason for paging. Saying a program can't allocate memory because it has bumped into the next one, when there is a large amount on the other side is insanity. This is exactly like saying you can't write to a file because there is another file right after it on the hard drive. Paging has the nice side benefit of efficient swap (swappin

    • Re: (Score:3, Informative)

      by fifirebel ( 137361 )
      You are confusing swapping and virtual memory.

      Swapping requires virtual memory. The converse is false.

      All this scary PDE, PTE and other TLB stuff is what happens when a virtual address is converted to a physical address. That has nothing to do with swapping or paging.

      Now, you cannot seriously consider abandoning virtual memory and all that comes with it (inter-process protection, kernel protection from user-space errors amongst others), can you?

  • by killmofasta ( 460565 ) on Wednesday October 01, 2008 @07:07PM (#25226301)

    I have made hundreds of swap partitions for OS X, AU/X, Windows, Schmindows, and just about every flavor of Unix I came across.

    I would advise...
    For Windows, load Process Explorer, and look at the Commit Change Peak RAM. Nice...

    Now load a browser, a word processor, and Acrobat. OR Load the game you want to play.

    Make the partition the size of that peak RAM+10%.
    Make the swap size, the larger of the system cache or the minimum peak commit change. ( There is a brilliant trick here, but Id have to kill you...)

    System 1:
    1024MB ram.
    Peak is 70%.
    Swap partition is : 1916Mb, 64K Clusters.
    Swap file size is : 512~1668Mb
    Swap file size on OS Partition is 2Mb.
    ( Someone warned me about this, and I actually listened. Sure has helped when imaging drives )

    More Later...( It gets trickier for smaller ram values...) I am working on a 512MB system, a 384MB system, and a 256MB system.

  • RAM-based hard drive (Score:4, Interesting)

    by suck_burners_rice ( 1258684 ) on Wednesday October 01, 2008 @07:17PM (#25226403)
    I have 64 GB of RAM and my swap partition is the same size at 64 GB. I thought 128 GB is a little excessive. What I would really like is if someone would make up an IDE interface to RAM modules and build a large amount of such RAM into the form factor of a hard disk drive. Then, you could populate this RAM-based "hard drive" with the necessary data during startup, and use it for swap and for all of your system's various "temp" folders. This would make swapping (and temp stuff) extremely fast to access, and more importantly, it would eliminate the need to encrypt your swap and/or temp partitions, as the data would simply disappear when power is removed. So when the agents (including Agent Smith) come to bust down your door, all you do is pull the plug and voila! Your secrets are safe. :-)
    • Re: (Score:3, Interesting)

      by Tony Hoyle ( 11698 )

      .. or you could just install the RAM in the machine and remove the need for swap at all. tmpfs takes care of the rest.

    • Re: (Score:3, Informative)

      by Frogbert ( 589961 )

      Yeah that would be a great [] idea.

      And yes, those bad boys do raid together and they max out SATA transfer rates.

  • by thogard ( 43403 ) on Wednesday October 01, 2008 @07:19PM (#25226421) Homepage

    I've been setting up machines with no swap partitions for a few years. Swap partitions have a bad habit if collecting secure info you may have assumed was just in ram. All modern operating systems allow to you use a file or other blank space as swap means you don't need a dedicated partition. There is also the issues that if your starting to swap, where does it end? If your swapping on a machine with 4 or 8 gig of ram, will an extra gig help fix what ever is broken or just make the machine very slow until it gets around to telling the runaway program that there is no more memory. In the case of no swap, that tends to happen much faster. The only reason I see for swap partitions is that the OS will need a place to dump debug info if it crashes and the swap partition has traditionally been used for that.

  • Need More Info... (Score:5, Insightful)

    by Vrallis ( 33290 ) on Wednesday October 01, 2008 @07:35PM (#25226577) Homepage

    I also agree that the old "2 x RAM" standard is outdated.

    If you are a typical desktop user--browsing, email, games, etc, you will likely never swap. If you happen to edit photos a lot then you'll use a bit more. In these cases doing 4GB swap for 4GB RAM should be more than sufficient, and even then overkill.

    If you are a serous 'power' desktop user, heavy graphics / video editing or similar heavy-duty tasks, you will likely have significantly more RAM. If you ever did swap things would become so slow your productivity would be severely hampered.

    Were you talking about a server I'd say the same thing. Your swap space on an active server (thinking database or application server) is really just there to keep you operational should some process go haywire, long enough for you to fix it. If you are regularly swapping on a server then you need to upgrade your RAM or adjust your software on it.

  • by OrangeTide ( 124937 ) on Wednesday October 01, 2008 @07:41PM (#25226651) Homepage Journal

    It lets you leak more memory for longer, this is a necessary feature for running modern software.

  • by franois-do ( 547649 ) on Wednesday October 01, 2008 @07:41PM (#25226653) Homepage

    The "rule of two" is due to Knuth's demonstration : "When the memory is 50% full, there is necessarily one free block at least as big as the biggest already allocated block", or something similar.

    Today, I would say the swap partition is mainly useful to store the state of the computer when you put it in hibernation mode, that is a little more that the size of your RAM if you want to be really cautious, just in case.

    That being said, A GB of disk is so cheap compared to 1 GB of RAM - which is already cheap, now - that there is no problem in doubling that size for very special purposes (alternating 2 different "hot" graphic users sessions or operating systems without rebooting, for instance). Just my two cents.

  • by invisik ( 227250 ) on Wednesday October 01, 2008 @08:11PM (#25227007) Homepage

    Arguably RH is the authority on the subject... See their documentation here [].


  • by atomic-penguin ( 100835 ) <.ude.llahsram. .ta. .12eflow.> on Wednesday October 01, 2008 @08:29PM (#25227209) Homepage Journal

    Oracle has very specific requirements/recommendations:

    1 GB - 2 GB 1.5 times the size of RAM
    2 GB - 8 GB Equal to the size of RAM
    more than 8GB 0.75 times the size of RAM

    Our organization just bought 4 database servers with 32 Gb of RAM each. I personally setup and installed the servers. I told the DBA:

    This server has 32 Gb of RAM, if your database applications ever has to swap out 24 Gb, then something is seriously wrong. As a matter of fact, I would guess this much swapping would kill I/O throughput for any database application. However, if we have to put another swap partition in there for the Oracle installer; I have set aside enough free space on the disk to satisfy the installer demands.

    The DBA agreed with this, and we went with 8 Gb of swap. Haven't had any problems with the server or DB applications for more than 6 months. It is the most heavily utilized server in the entire organization.

    For a laptop, I would set the swap to equal or more of the RAM, only if you want to suspend to swap. Depending on the applications, I would say at least half the amount of RAM to double the amount of RAM, within reason. If you have 8 Gb of RAM on a workstation, you probably do not need 16 Gb of swap for everyday use.

  • by mario_grgic ( 515333 ) on Wednesday October 01, 2008 @08:40PM (#25227323)

    has a dynamically grown swap file currently at 64 MB.

    I have 8 GB of RAM and never page out even when I run dozens of memory hungry apps (photoshop, nikon capture etc).

    The general rule is if you are swapping pages out when running typical apps you use daily, get more RAM.

  • by Skapare ( 16644 ) on Wednesday October 01, 2008 @10:20PM (#25228227) Homepage

    ... and it works like a champ.

  • 32 bit (Score:3, Interesting)

    by rossdee ( 243626 ) on Wednesday October 01, 2008 @10:59PM (#25228529)

    Is there any point, with a 32bit OS, in having a swapfile bigger than 4 gigabytes?

    I just (today) installed a new hard drive, 1 Terabyte, so I moved the swapfile to that drive, but kept it the same size.(2 gigabytes)
    I have 3 gigabytes of RAM

  • by plopez ( 54068 ) on Wednesday October 01, 2008 @11:48PM (#25228905) Journal

    that matters. It's how you use it....

  • My 2 cents. (Score:4, Interesting)

    by Chris Snook ( 872473 ) on Thursday October 02, 2008 @12:05AM (#25229029)

    Until a few months ago, I regularly answered this question for enterprise Linux customers, so I humbly submit that my anecdotal experience is marginally more informed than most here.

    Memory capacity and bandwidth is improving orders of magnitude faster than disk throughput and latency, and this has been true for decades. If the workload stays the same, you should generally have a lower swap/RAM ratio on newer hardware than older hardware, because it's so much cheaper these days to add more RAM, and adding more swap can actually make your system slower when you finally start using it, because it takes much longer to page in 8 GB of data from disk than 4 GB.

    The kernel virtual memory (VM) subsystem is a briar patch of carefully-tuned code which, whenever altered, almost always causes a regression for some obscure combination of hardware and software that someone somewhere cares an awful lot about. This is not due to inherent bugginess, but rather the fact that the VM is essentially in the business of predicting the future, which is mathematically impossible to always get right. As a result, developers tend to be very conservative about VM optimizations, so the VM tends not to adjust its assumptions about hardware quite as quickly as the hardware itself changes.

    The upshot of all of this is that as time goes by, swap becomes more of a lifeline for worst-case memory shortages and less of an optimization to make the system behave as though it had more memory. This is not to say you should do without it completely, but the ratio tends to keep going down. For desktop use, I've been using a 1:1 ratio for a while, and honestly, that's probably too large for how I use it. Digging out of 2X swap takes *more* than twice as long as digging out of 1X swap, because you end up thrashing back through the stuff you've already paged in and out before you get to the rest. Think of the Tower of Hanoi problem as an extreme worst case. Beyond a certain point, you really want the kernel to refuse memory allocations and/or invoke the OOM-killer to kill off your misbehaving app and restore performance for the rest of the system.

    Whatever you do, you shouldn't go completely swapless unless you really know what you're doing. Having just a few hundred megabytes of swap on a huge 4-socket server gives you a buffer against out-of-memory conditions that could bring down the whole system. In this extreme case, it's actually *good* that swap is slower than RAM, because it stalls userspace page dirtying while waiting for I/O, leaving the CPU free for the kernel to scan for pages that should be paged out, faster than userspace can dirty them.

    If you're stuck on a small system you can't upgrade, having a high swap/RAM ratio might still make sense, but modern hardware tends to have much more and faster RAM and only slightly faster I/O.

    If you've got a carefully tuned database server that's reserving much of its memory for hugepages, you should start your calculation with the amount of *swappable* RAM, which is the RAM not set aside for hugepages. So, if you've got 16 GB of RAM, and 12 GB reserved in hugepages, you only want swap proportional to 4 GB of RAM.

    The proportion itself is still a delicate matter. On a desktop system where you may open lots of applications, and then leave some of them idle for days while using other resource-intensive programs, it may make sense to go as high as 1x. On servers where latency is important, you probably don't want to go higher than 0.25. If you've got a batch compute system where you feed it a huge amount of work and expect it to be done when you come back several hours later, it can still make sense to have upwards of 2x as much swap as RAM. It might be sluggish to give you a login prompt, but that doesn't necessarily mean it's thrashing inefficiently if you have a fairly sequential access pattern.

    If all of this confuses you, and your distribution recommends 2 GB by default at install time, odds are you'll do okay with that, at least for the near future. Once solid-state storage becomes mainstream, most of what I've said in this post will be completely obsolete.

  • by Zoxed ( 676559 ) on Thursday October 02, 2008 @03:32AM (#25230129) Homepage

    Why does everyone put their swap on a slow harddrive ? A Gentoo running mate of mine in the pub showed me how to map the swap file into RAM: runs much faster there.

    (Although suspend does not seem to work now :-(

You know, Callahan's is a peaceable bar, but if you ask that dog what his favorite formatter is, and he says "roff! roff!", well, I'll just have to...