Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



Forgot your password?
typodupeerror
×
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.com'> on Wednesday October 01, 2008 @06:39PM (#25225907) Journal

    'Is 8 gigs of swap really necessary?'

    With a 750GB [newegg.com] 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 [wikipedia.org].

    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 42forty-two42 ( 532340 ) <bdonlan@@@gmail...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.

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

  • 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."

    HTH.

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

  • 256M (Score:2, Informative)

    by bluefoxlucid ( 723572 ) on Wednesday October 01, 2008 @06:47PM (#25226027) Homepage Journal

    If you need more than like 512M of swap, you need more physical RAM.

    Seriously though, maybe like 10% of your physical RAM; but if you reach a point where you need to access a lot of swap in a short time (say a graphics intensive program, or a Web browser that has 2 gigs relevant data in swap), your machine will slow to a crawl.

    This is why I use like 128M swap and swapd on Ubuntu.

  • 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: http://www.bytetrap.com/blog/2008/06/02/swap-space-linux/ [bytetrap.com]
  • 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.

  • by srothroc ( 733160 ) on Wednesday October 01, 2008 @06:52PM (#25226103) Homepage
    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 common in the modern day -- I know plenty of people who just use 120 GB or 200 GB drives; not everyone likes all their eggs in one basket.

    8 GB swap on a 120 GB drive represents about .07% of the drive. On a 200 GB drive, it represents about .04% of the drive. Still and order of magnitude larger than was required back when "swap space should be double your amount of RAM" was a standard rule of thumb.

    Just some thoughts.
  • 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.

  • Re:None (Score:5, Informative)

    by hey! ( 33014 ) on Wednesday October 01, 2008 @07:00PM (#25226211) Homepage Journal

    Well, I do occasionally need more than 2GB of RAM, without there being a memory leak. I've been running GIS programs, an IDE, a couple of RDBMSs, and then I fire up the old compression program...

    Which brings me to my point. The question "how much swap do I need" is probably meaningless, even for a given amount of memory. There are people who find 2GB with no swap fine, and others, like me, who probably could get by with 2GB of RAM and maybe 512MB of swap, and others who might need more.

    I think the 2x RAM rule of thumb has one virtue: excepting certain exotic kinds of systems, it's fairly safe that anybody who finds themselves needing more than that is probably feeling a world of pain that can only be fixed by getting more RAM. On the other hand, in most cases 2x RAM amounts to a trivial amount of disk. Probably most people could get by with 25% of RAM, but the value of thinking about whether that is true for you is very likely less than the cost of the disk space.

    Common sense applies. If you have some kind of scientific computing device with a gazillion bytes of RAM, your swap requirements might not be related to your maximum RAM requirements at all. If you're running some kind of operating system that launches a bunch of rarely used garbage, you probably ought to think about your swap. I had awful problems with Vista until I figured out the page file Windows created had something like eight thousand fragments. I was actually better off getting rid of the page file

  • by Anonymous Coward on Wednesday October 01, 2008 @07:04PM (#25226275)

    Yeah, hibernate actually DOES mean "use no electricity". Perhaps you mean "suspend"?

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

    i assume you dont hibernate, thats the only reason i have 1x my ram in swap. Although using something like "hibernate" instead of ubuntu's tool will happily compress it so i could really get away with about 60-70%

  • by FauxPasIII ( 75900 ) on Wednesday October 01, 2008 @07:06PM (#25226291)

    For built-in suspend this is true. TuxOnIce [tuxonice.org] 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 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.

  • Re:What Oracle Wants (Score:3, Informative)

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

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

  • by Estanislao Martínez ( 203477 ) on Wednesday October 01, 2008 @07:13PM (#25226367) Homepage

    The point of swap space isn't to kick in when you run out of physical memory. The point of swap space is to allow the kernel to make use the most efficient use of your RAM, by swapping out the contents of infrequently accessed memory pages, and putting that memory to better use, like caching frequently accessed disk blocks.

    If you have no swap space at all, any memory pages that your processes are hardly using have to stick around in memory forever, even if you'd get better performance by swapping the contents out and using it for caching disk blocks. So seriously, you should add some swap space, at least as much as your RAM.

  • by sirwired ( 27582 ) on Wednesday October 01, 2008 @07:19PM (#25226431)

    8GB swap on a 120GB drive is 7%, not .07%. On a 200GB drive, it's 4%, not .04%, etc.

    SirWired

  • by Elrond, Duke of URL ( 2657 ) <JetpackJohn@gmail.com> on Wednesday October 01, 2008 @07:20PM (#25226449) Homepage

    "Hibernate" does not mean "use no electricity."

    Actually, "hibernate" is no different than "off" from an electricity use perspective. When you hibernate with Linux (or even Windows), the contents of memory are stored to disk and the machine is powered off just as if you had performed a normal shutdown procedure.

    At this point, a hibernating system is using exactly as much power as a system that is off. For an ATX system this is not zero since the power supply has to provide some power for the on/off button to function as well as to power the USB ports.

    Suspending your system, on the other hand, does use more power since the RAM must be continually refreshed, though most of the other components are off.

  • 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 [ubuntu.com]:

    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 sr8outtalotech ( 1167835 ) on Wednesday October 01, 2008 @07:29PM (#25226537)
    If you're running Windows, use perfmon and see what the usage is under heavy load and scale accordingly.
  • by Gazzonyx ( 982402 ) <scott...lovenberg@@@gmail...com> on Wednesday October 01, 2008 @07:38PM (#25226605)
    tip:
    Lower the amount of RAM Linux uses by changing vfs_cache_pressure to > 100. This will make the kernel dedicate less RAM for caching dirents (directory entries) for quicker lookups. For instance, to cut the amount of directory caching in half, double the pressure by doing:
    'echo 200 > /proc/sys/vm/vfs_cache_pressure'.

    HTH
  • by apoc.famine ( 621563 ) <apoc.famineNO@SPAMgmail.com> on Wednesday October 01, 2008 @07:39PM (#25226615) Journal
    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 to hear it.
  • by kasperd ( 592156 ) on Wednesday October 01, 2008 @07:47PM (#25226725) Homepage Journal

    what I do is get the OOM killer to take action and kill some processes sooner.

    Just killing processes more or less at random when the system runs low on memory is not a good idea. (I know it is not completely random, but there surely ain't any guarantee that it will make sane decisions). What you really want is for programs to get an out of memory error when trying to allocate memory, and then they can shut down as gracefully as possible. (Would be neat if the choice of who get the first ENOMEM was chosen by the heuristics that would otherwise kill the process, but I guess that has not been implemented). Guaranteeing that you will never need to kill a process because you are out of memory means the kernel will have to not commit to more than can be backed by memory and swap. However since actual usage tends to be somewhat lower than what is actually committed to, that would be a bit wasteful. This is the main reason why it makes sense to have a large swap partition that is mostly unused. Just so you have backing for the amount you need to commit to in order to optimally use the physically available memory.

    You typically wouldn't want to make use of most of that swap. So once any significant amount start getting used, you'd want to start giving ENOMEM errors. And that should help ensuring that the swap will only be used for a short time. There are a few pieces of data in virtual memory that are only used under very rare circumstances, and those it is nice to have on swap so they don't take up precious memory. So the aim is not to have zero swap in use, just some low number of pages that are really not needed in memory.

    Is there any kernel out there that gets all of this right? I don't know. But at least those I know about can be tweaked to do pretty well.

  • by rcw-home ( 122017 ) on Wednesday October 01, 2008 @07:55PM (#25226829)

    I am thinking of reducing the amount of swap on my primary compute server

    For best performance, don't reduce your swap below the amount of RAM you have, unless you want to get rid of it entirely. The reason is that Linux 2.2.x and later will, when your disks are idle, preemptively copy your physical memory to swap - that way if you do run out of RAM, all Linux has to do is reuse that RAM for other things - your application's virtual memory has already been written out to disk. This can't work as well if the swap space isn't there for it.

    With 2.0.x and earlier, I would have recommended you pick the amount of virtual memory you think you need, subtract the amount of physical memory you have, and set up that much swap. With 2.2.x and later, I recommend you pick the amount of virtual memory you think you need, and set up that much swap.

    For what it's worth, Windows NT derivatives do the same thing.

  • by kelnos ( 564113 ) <bjt23NO@SPAMcornell.edu> on Wednesday October 01, 2008 @07:59PM (#25226869) Homepage
    It's tunable on Linux at least... you can set /proc/sys/vm/swappiness to something between 0 and 100 -- default is 60, lower values make the VM swap less aggressively. Not useful for average users, but we can handle it.
  • by rk ( 6314 ) * on Wednesday October 01, 2008 @08:05PM (#25226935) Journal

    Guess how many times I've thanked 8 lb 6 oz baby Jesus that I had the foresight to separate the two?

    My guess: At LEAST three. :-)

    I have three partitions on my system:

    • /
    • /home
    • /usr/local

    Home stores all my stuff, /usr/local stores all the stuff I download and build from source, and / is the stuff the distribution I use (currently Slackware 12.1) gets to muck with.

    When I want a new distro, I can nuke and pave / with impunity, and depending on the age of things in /usr/local, they may need to be recompiled, and that's about all I need. Every now and then, /home and /usr/local get moved to a new, bigger drive, which is a lengthy, but fairly painless process. I don't clean out; I can't justify spending hours figuring out what I can purge and what I can't when storage is so cheap. I just buy a bigger drive, and the old smaller one becomes the new /. If the old system drive fails, it's no biggie. The new one gets its critical files backed up. If I lose it, there will be some pain, but I keep the "If I lose these files, I'd rather just die" stuff burned to disk, copied to my virtual server 1000 miles away, and on my USB keychain drive.

    Multiple partitions FTW.

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

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

    -m

  • by Anonymous Coward on Wednesday October 01, 2008 @08:28PM (#25227183)

    They have this technology already
    http://www.tomshardware.com/reviews/gigabyte,1111.html

    Can't find the other product that actually fits in 5.25 inch drive bay, but it was 10x's the cost a few years ago.

    I picked up 4 of these cards for $60 on ebay 3 years ago, and then sold on ebay for twice that each.

    However these cards have battery backup, but this could be removed. =]

  • by thisissilly ( 676875 ) on Wednesday October 01, 2008 @08:28PM (#25227195)
    noatime includes nodiratime. nodiratime is for when you want atime on files but not dirs.
  • by atomic-penguin ( 100835 ) <wolfe21 AT marshall DOT edu> 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 TheNetAvenger ( 624455 ) on Wednesday October 01, 2008 @08:30PM (#25227223)

    Why would I want that? If Windows crashes, I want it to restart and quickly, not waste my time dumping memory.

    Agree, but having a pagefile the size of RAM in Windows is not for crashes as the parent suggests.

    Having a pagefile the size of RAM in Vista for example, lets the OS do writethrough to the pagefile, so when you hibernate, it is faster, as it is a snapshot that doesn't have to be written to the HD.

    I only recommend this for laptop users that want that extra second or two of speed when sending the computer to hibernate though.

    If you have 4GB of RAM, a swap file is not needed 99% of the time for most users with today's applications. The only exceptions is gamers running multiple instances of large games, or using applications that are dealing with multiple GB of data, then you should have a 1.5 to 2x RAM pagefile or more according to the amount of data you are processing.

  • by TXG1112 ( 456055 ) on Wednesday October 01, 2008 @08:31PM (#25227235) Homepage Journal

    Base 2. Storage numbers using base 10 are for disk manufacturers that are filthy liars.

  • by duguk ( 589689 ) <dug.frag@co@uk> on Wednesday October 01, 2008 @08:32PM (#25227241) Homepage Journal
    I guess I'm one of the few people who uses windbg [microsoft.com] to do this then?

    Try it out, it's amazingly useful for debugging BSODs.
  • by Anonymous Coward on Wednesday October 01, 2008 @08:33PM (#25227251)

    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 (swapping out pages instead of entire processes).
    Having /some/ swap is helpful because often you have data in RAM that you are not actually using, but is not file backed, so you can swap it out to disk and use that memory for something useful, like disk cache for your active set.
    Also, all of those addressing steps are only needed on a full cache/page miss. If this is happening often, your system is thrashing. Think spending 10,000 times the time waiting for page loads than doing address look-ups, or more.
    In any case, suspend to disk requires at least as much swap as you have RAM to store your suspend image.

  • by fifirebel ( 137361 ) on Wednesday October 01, 2008 @08:36PM (#25227277)
    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 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 supermanwashere ( 1376171 ) <daviddpruitt@noSPam.gmail.com> on Wednesday October 01, 2008 @08:43PM (#25227359)
    Actually stuff stored in RAM isn't safe either. If you remember a couple of months back an article was posted were researchers were able to recover contents from RAM more than 10 minutes after power was shut off. The only way it's safe is if you write something to all locations in RAM. Additionally you wouldn't gain significant speed. On a server most of your stuff is already in RAM when the system is running. On a desktop you would be better off prefetching, 1 GiB RAM costs around 300 times what 1 GiB HD space costs (1 gig RAM $30, 1 gig HD space $0.05 more or less).
  • by BrokenHalo ( 565198 ) on Wednesday October 01, 2008 @08:57PM (#25227513)
    Indeed, the cost of RAM is now such that it makes sense to simply buy enough to make sure that swap is rarely used. But by the same token, where drives if 1TB or more are no longer uncommon, it doesn't hurt to allocate a couple of gigs of swap for special occasions, and find something else to worry about.

    If you find your apps leaking to the extent that they swap a lot, simply consider alternative applications, or at least reload them more frequently.
  • by lucas teh geek ( 714343 ) on Wednesday October 01, 2008 @08:58PM (#25227519)
    compiz fusion greys out a window when the app owning the window is being unresponsive. assuming the Eee is running compiz, that would be your cause.
  • by Mr Z ( 6791 ) on Wednesday October 01, 2008 @09:25PM (#25227761) Homepage Journal

    It's base 2 when dealing with RAM and base 10 when dealing with disks. Pretty consistently. It's generally base 2 when dealing with throughput.

    Pop quiz:

    Throughput: How many bits per second peak can a 14.4kbps modem move? 1.544Mbps T1 line? 10Mbit Ethernet?

    Disks: How many bytes are on a 1.44MB floppy? A 2.88MB floppy? A 650MB CD-ROM?

    Answers:

    Throughput: 14,400. 1,544,000. 10,000,000. Hmmm... so much for base-2 throughput numbers. And yet, when you see the "kB/sec" rate in your browser download dialog, that is most likely in a 1024 byte/sec quantities.

    Disks: 1,473,560 (1440 * 1024, a mixture of base-10 and base-2), 2,949,120 (2880 * 1024, again a mixture), and 681,984,000 (purely base-2, derived from 333,000 sectors * 2048 bytes/sector / 1,048,576). And yet when you look at disk capacities from most computer software, it's reported as purely base-2 sizes.

    So, what's consistent about this again? RAM seems to be the only thing that gets it right most of the time, though I do remember seeing plenty of adverts for Commodore 64s that listed them with 65K of memory back in the day.

    And for the real brain bender: If we agree that bits should always use power-of-2 meanings and everything else should use power-of-10, what do we do when the two collide, such as when talking about areal density? (That's bits per square meter.)

    That said, whoever came up with the names gibibytes, mebibytes and kibibytes must have wanted us all to sound like we have a speech impediment or something, as the pronunciation for these sounds worse than baby talk. I'll stick to saying gigabytes, megabytes and kilobytes and their understood power-of-2 meanings where it makes sense, knowing full well that it has deep flaws. It's just an unfortunate circumstance, but most of the time it thankfully doesn't matter.

    --Joe

  • by sweetnavelorange ( 1192975 ) on Wednesday October 01, 2008 @09:25PM (#25227767)

    The kernel could be made more efficient, and *many* drivers made simpler, if the whole concept of "page fault" ceased to exist.

    Page Faults [wikipedia.org] are not about swap, they're about Virtual Memory - which a different (though related) thing. You should read up some more.

  • Re:Just test? (Score:3, Informative)

    by petermgreen ( 876956 ) <plugwash@NOsPaM.p10link.net> on Wednesday October 01, 2008 @09:30PM (#25227821) Homepage

    Remember to set permissions on swapfiles, letting any user read them is not a good idea as they may end up containing sensitive information (e.g. passwords).

  • by Anonymous Coward on Wednesday October 01, 2008 @09:34PM (#25227861)

    Separate /var too. If the system goes down, active partitions are at the highest risk of corruption. /home /var and /tmp are the only things that are active. /etc only changes when you reconfigure. Anything else should only change during software a upgrade.
    You did make /tmp a tmpfs didn't you?

  • by PCM2 ( 4486 ) on Wednesday October 01, 2008 @10:15PM (#25228177) Homepage

    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, history, etc. Moving the profile to the boot drive cut that time in half. Also, when downloading to the data drive over a 6Mbps cable line, I can't saturate the line. The drive is the bottleneck. Some people have suggested that Asus's drivers for the controller may be flawed. All I can say is, don't believe [all of] the hype about SSDs.

  • 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).

  • by LO0G ( 606364 ) on Wednesday October 01, 2008 @10:19PM (#25228213)

    It's probably trying to make room for open office's code.

    Because you don't have a swap partition configured, the system can't swap out your data so it's trying to find memory the only place it can - it's discarding the code segments for firefox.

    But of course when open office wants to run it needs to swap in the code for the open office which means it needs to find some memory to throw away. And that means it throws away the memory for firefox.

    And when firefox wants to run it needs to find a place to put the memory for the firefox code. Because it can't page out your data, it finds the memory in the only place it can: it throws out the memory used by openoffice and uses it for firefox.

    wash, rinse, repeat.

    There's a reason that most modern OS's have swap partitions (or paging files).

  • by adolf ( 21054 ) <flodadolf@gmail.com> on Wednesday October 01, 2008 @10:23PM (#25228245) Journal

    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 RAM. You then decide to, say, start editing a DVD (or some other disk-intensive thing). With enough RAM and enough swap, the unused programs will be swapped to disk, and the RAM freed by doing sowill be used to cache as much of the DVD as possible. This makes the editing process quicker, and less CPU intensive.

    In other words, swapless systems (or those with limited swap) are cache-starved.

  • 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 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 (http://ask.slashdot.org/comments.pl?sid=982541&cid=25225967) 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 :)
  • by dsg123456789 ( 1315293 ) on Wednesday October 01, 2008 @11:34PM (#25228809)
    This is not a good idea. Paging enables all sorts of other behavior besides swapping, such as security and virtualized processes (the standard on all O/Ses). It also allows more esoteric things, like letting user applications use more of the address space, and paging hardware is really optimized, plus, compilers help make decisions to improve the use of the CPU's caching hardware. Paging is a good thing.
  • by Frogbert ( 589961 ) <frogbert@gma[ ]com ['il.' in gap]> on Wednesday October 01, 2008 @11:43PM (#25228873)

    Yeah that would be a great [gigabyte.com.tw] idea.

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

  • by Anonymous Coward on Thursday October 02, 2008 @12:06AM (#25229031)

    From the boot CD:

    `mv /mnt/hd /mnt/hd/old'

    Install, then mv your home directory back. Now you don't need the foresight from college days to realize you'll need 25 GiB for MP3s! Plus now if you have the disk space, you can keep the whole old FS and bring over conf files and binaries as you discover you need them, and even `chroot' into it if you like.

  • by cookd ( 72933 ) <douglascook.juno@com> on Thursday October 02, 2008 @12:09AM (#25229045) Journal

    Perhaps for a very specific definition of "swap", you might be correct, but swap has a more general meaning. Your definition seems to be full process swapping (where swap = suspend process, send all code and data to disk). That certainly is pretty rare, and is generally a last resort. Since it is so rare, the verbs "page" and "swap" generally get conflated and discussed together. On most systems (pretty much all systems with virtual memory support), swapping/paging definitely happens way before memory fills completely, as you could see using any system monitor like top (Unix) or TaskMan (Windows).

  • by Ashtead ( 654610 ) on Thursday October 02, 2008 @12:52AM (#25229277) Journal

    ROMs, EPROMS, EEPROMs, and other static or non-volatile memory devices tend to be advertised as having some 2^N number of bits in them. Even if they most commonly are organized and used as words of 8 bits.

    This tends to be reflected in the part numbers, which frequently have a strong relationship to the number of bits of storage in the device. EPROMs in the 27xx series and EEPROMs in the 24xx and 28xx series are the most likely. For example, the 2764, 27C64, 2864, 24C64, etc., all have 64K (65536) bits of storage, although available and used as 8192 by 8, and the 24256 and 27256 have 256K (262144) bits in them, organized and used as 32768 by 8. There are several other sizes of these memories with corresponding part numbers.

  • Re:Here's how big (Score:5, Informative)

    by BitZtream ( 692029 ) on Thursday October 02, 2008 @01:20AM (#25229465)

    So I'm a FreeBSD guy rather than linux, but I'm going to assume that Linux also supports 'limits' that define the maximum a program can utilize before its denied access to more resources. You won't get a normal app on my FreeBSD boxes to use more than 256M of ram, they aren't allowed. There are 2 exceptions, the PostgreSQL server on one of the machines, and the bot that connects to that database. They both deal with large datasets on regular basis so they are allowed to use more ram. Now mind you, these machines are used for my personal development projects and they aren't really 'servers' in the sense that they see real load. My instances of apache don't NEED a lot of ram, some do.

    My point is that there are other protections in place that prevent an app from 'running away' and taking a properly configured machine down.

    Second, swap can be VERY useful even if you NEVER run out of ram. The OS can swap apps that have used memory but aren't actually doing anything with it out, and leave that memory available for file/disk caching, which can make performance FAR better than if you kept the idling apps in memory and had less available disk cache. Some apps avoid buffering things in memory because its both easier and most times more efficient to use the disk and let the OS manange the buffering. I've seen NT based OSes aggressively swap out things that aren't in use just so there is more memory available for disk cache, and it makes sense cause there is a lot of crap the kernel and other apps load up that is very RARELY needed, if ever.

    So while you can ( and did ) point out the potential pitfalls of using swap, your examples don't apply to any modern OS. I'm excluding Windows from that statement cause lets face it, its not exactly modern at the core. Modern kernels are FAR better at deciding what to swap than you are in almost every case, just like compilers can do a far better job of optimizing applications that most developers can. Yes some can do better, but its not likely you are, and certainly not the guy asking this question.

    In short, if you're going to try to get technical with why you wouldn't want to use swap, at least use examples problems that weren't solved years ago.

    And for reference, you configure your swap poorly if you do what you say.

  • Re:32 bit (Score:3, Informative)

    by BitZtream ( 692029 ) on Thursday October 02, 2008 @02:02AM (#25229713)

    Yes.

    Just because an app can only use '32bit' addressing, doesn't mean the OS does. For instance my '32 bit' processor has '36 bits' of address space. So I have the capability in the processor to address 16 full 32 bit address spaces, even though the OS doesn't let any one app have more than 32bits worth of address space.

    Unfortunately, I run XP which won't let me get even to 32bits for all apps combined, but thats another story.

    Second, when you take 'virtual memory' into account, you can have a 'virtually' unlimited amount of applications that all think they have access to 32bits worth of address space. For instance say I have 3 apps that have memory leaks in them. These 3 apps for whatever reason must run for long periods of time without restarting. They really only use a gig each of active memory, but because they leak all the time, they consume a lot of wasted memory. This wasted memory will never be used again, so the OS can swap it out as needed and continue to let the buggy apps run until they can be patched, hopefully they will complete their long run cycle before exhausting swap as well.

    A better question is, do you really want to deal with those situations? Most of us have no need to. I don't, I know that. And for many people, if they actively need to use 2gb of swap, your dealing with some process that is going to be so painfully slow that you'll probably be willing to plunk down the money for more ram than deal with waitting on the disk light to turn off sometime next May. My swap is set to 8gigs on my XP machine, not because I want/need the swap space, but because I use it as a buffer for free space. When I get low, I turn off swap and reboot and have an extra 8 gigs of space for porn until I can drive my lazy ass to the store to get more tissues and a bigger drive. Not the ideal solution, but it makes me cleanup old crap when I get low on space most of the time and provides an alternative that is just inconvient enough that I don't use it 99.999% of the time.

  • by TheLink ( 130905 ) on Thursday October 02, 2008 @03:05AM (#25229999) Journal
    If you're using ADSL, sometimes what you end up with is TCP/IP over PPPoE over ATM over DSL (whoopee).

    Your DSL could be 6144kbps but since ATM cells are 48 byte payload with 5 byte header, your theoretical max TCP/IP speeds would be significantly less than 6144kbps. PPPoE also has some overheads but it does allow for larger packets.
  • by Anonymous Coward on Thursday October 02, 2008 @04:03AM (#25230279)

    8 gigs on a HDD will take 100-800 seconds to read off.

    If you need that much, buy another 8 gigs of memory.

    THAT'S why you don't double memory as swap.

    1/2 to 1 Gig is plenty. If you start using a lot of it, get more memory.

  • by Antique Geekmeister ( 740220 ) on Thursday October 02, 2008 @04:03AM (#25230281)
    Duplicating filesystems with dd does not allow resizing, myshandles database files that are in the midst of atomic operations, and only gets that data that has actually been written to disk. The fact that modern Linux kernels keep as much in possible paged out in RAM, to improvde access times, means that you can rely on nothing having been written to disk unless you go through additional, complex and service interrupting steps. It also doesn't compress well, since any unused bits on unused blocks also wind up read and included in the duplication. No, dd is not a good backup or data transfer tool in most circumstances.
  • by dovienya ( 50316 ) on Thursday October 02, 2008 @05:01AM (#25230529) Homepage

    says:
    "The most important factors in determining swap space size are the requirements of the system's software applications. [...] If you are unable to determine swap space requirements from your application vendors, use the following general guidelines based on your system type to allocate swap space."

    Workstation with about 4 Gbytes of physical memory: 1 Gbyte Swap

    Mid-range server with about 8 Gbytes of physical memory: 2 Gbyte Swap

    High-end server with about 16 to 128 Gbytes of physical memory: 4 Gbyte Swap

    http://docs.sun.com/app/docs/doc/817-5093/fsswap-31050?l=en&a=view

  • Re:Loopback Swap. (Score:3, Informative)

    by petermgreen ( 876956 ) <plugwash@NOsPaM.p10link.net> on Thursday October 02, 2008 @06:01AM (#25230795) Homepage

    afaict there is no need to bother with a loopback device on modern linux you can just mkswap and swapon the file directly.

  • by TheRaven64 ( 641858 ) on Thursday October 02, 2008 @06:33AM (#25230943) Journal

    Each userspace process has its memory divided in to pages. These are typically 4KB. Each process has its own set of page tables, which map each of these pages to a real page in RAM. These entries are 32 bits, with 20 being used to indicate the address of the physical page. The remaining 12 are flags. One of these is the 'present' flag. If this is not set, then the operating system will receive an interrupt and have to set up the mapping correctly before it can proceed.

    If you have a 32-bit OS with two processes, each using 2.5GB of their 4GB address space, then some of this will have to spill over to swap space. Each process will have (for example) 0.5GB of its RAM swapped out to disk. When it attempts to access this, it will be paused while the OS writes some pages that haven't been used recently out to disk and then loads the requested page back in.

    A 32-bit OS just means that each process can only have 4GB of address space and that you can only have 4GB of total RAM. There are some slight fudges to get around this too - on anything more recent than a Pentium Pro, you have Page Address Extensions, which gives you 36 bits of physical address space, so you can address 64GB of RAM, but pointers are still 32 bits, so you still only get 4GB of virtual address space per process.

  • by Bert64 ( 520050 ) <(bert) (at) (slashdot.firenzee.com)> on Thursday October 02, 2008 @06:59AM (#25231043) Homepage

    Those "1.44MB" disks actually had a 2MB capacity, and the actual usable capacity depended on how they were formatted... Some places sold them as 2MB disks, some didn't...

  • by Anonymous Coward on Thursday October 02, 2008 @09:16AM (#25231903)

    In windows it's a good idea to set a fixed size for the swap as it avoids fragmenting the swap file, which I can assure you it does, at least in XP.

  • by Amouth ( 879122 ) on Thursday October 02, 2008 @10:06AM (#25232449)

    on top of fragmentation - if you set it to "let windows manage" instead of setting a fixed pagefile size windows has a very very bad habit of only allocating what it needs at the current moment with no flex space..

    Meaning..

    evry time it swaps something to disk it has to look up and allocate more space (this causes the fragmentation and takes time)

    every time ti swaps something from disk to memory it frees up the space for the File system (takes even more time and opens others things to fragment by releaseing things if 4kb peices)

    in the even that it is a true swaping of pages.. it will allocate space on disk then write from memory to disk the current page then read from disk the page it wants then it frees the space on disk.. so not jsut swaping memory but eating disk time to do it.

    having windows manage pagefile is just asking for slower preformace if windows ever decieds to swap.. which it does alot even if you arn't running alot of programs that eat memory as windows likes to do system and program cacheing - so you run somethign and quit.. windows will leave it in memory so it doesn't have to read it back next time.. only issue is it doesn't treat this special compared to other things and will page this cache just like anything else..

    if you set a fixed size.. then all of the allocating and freeing of disk space goes away.. which makes swaping alot faster in windows.. not to mention that it helps prevent fragmentation of the swap space.. which just compounds the speed issues

  • by phision ( 836909 ) on Thursday October 02, 2008 @10:55AM (#25233085) Journal

    No swap partition, which would predictably have many more writes than the rest of the disk;

    The firmware of the SSD will do the job to avoid wearing a particular cells of the flash memory, no matter of the partitioning. The partitioning of the SSD is purely logical.

  • by anomaly256 ( 1243020 ) on Thursday October 02, 2008 @11:21AM (#25233411)
    Have you ever tried to use an app that needed 12gb of memory, when 8gb of it is swap????? You'll be sitting there FOREVER waiting for it to do anything as it's moving 8gb of crap to disk. Basically, if you hit this point, you don't need more swap, you need more RAM! 2gb of swap is plenty. Regardless of setup or application. If this runs short, buy more ram and use a 64bit OS.
  • by PitaBred ( 632671 ) <slashdot@pitabre ... g ['.dy' in gap]> on Thursday October 02, 2008 @12:32PM (#25234479) Homepage

    The OS doesn't just randomly "throw away" memory. There is no mechanism for doing so, asking programs to relinquish RAM they previously allocated. What the OS IS doing is dropping file caches from memory, stuff Firefox has read for rendering pages, and leaving them just on the disk. But that's not Firefox's memory... that's the operating system's memory. It can't throw out OpenOffice memory at all. The ONLY thing an OS can do is say "no, you can't have more memory" when a program wants more, or kill the program entirely. It can't find "safe" places to reclaim RAM.

    Go take an OS design course, or at least read up on it. There is nothing in your post based in fact.

  • by joe_plastic ( 704135 ) * <stephen@pollei.gmail@com> on Thursday October 02, 2008 @01:04PM (#25234999) Homepage Journal
    posix_fadvise [opengroup.org] and posix_madvise [opengroup.org] seem to be standard posixy way to give hints to the cache. madvise(..) and fadvise(..) also exist granted some of the kernels don't properly use the hints.

interlard - vt., to intersperse; diversify -- Webster's New World Dictionary Of The American Language

Working...