Re: Newbie Question About Swap Partition

From: David Breakey (david_at_dbreakey.org)
Date: 08/25/04

  • Next message: Nico Kadel-Garcia: "Re: Backing up a LInux system"
    Date: Tue, 24 Aug 2004 17:25:15 -0600
    
    

    On Tue, 2004-08-24 at 12:33 -0700, Google Mike wrote:
    > I have standard RH9 Linux with standard ext3 filesystem.
    >
    > I have 512 MB of RAM and plan to go to 1GB of RAM tomorrow with a new
    > RAM chip. My swap partition is set to approximately double the RAM
    > size.
    >
    > 1. Do I need to type some command after adding RAM to manually
    > increase the size of the swap partition?

    The swap partition will never, ever just change size automatically; you
    will always need to manually trigger any changes to it.

    > 2. Will the swap partition automatically increase and I won't need to
    > type a command manually?

    No, it will not increase, or decrease; see above.

    > 3. Can I increase it without risk to whatever else is on the disk, if
    > I have available space?

    That depends on exactly how your disk is laid out; if you're at all
    unsure, I'd say no. Otherwise, find a local guru and ask them to show
    you (not 'do it for you'). Changing the size of the swap partition
    generally involves pulling out a partitioning tool, backing up your
    entire disk, and repartitioning the drive; unless you really need to, I
    wouldn't bother. It sounds like you already have a swap partition that
    is easily big enough for anything you'd probably need to do.

    > 4. What size should it be? Should it be RAM x2 + 64MB, or is there a
    > more preferrable setting?

    The magic formula used to be 'RAMx2', but that's not really a good way
    of judging it. The real question you want to ask now is, "Do I need more
    than 2GB of memory?", because that's what you've got with 1GB RAM and
    1GB swap. Remember, though, that accessing swap is many, many times
    slower than RAM. Chances are good you could probably reduce your swap
    partition and nothing would even notice, even now before you add the
    extra 512MB. Think of swap as 'emergency memory' which the system can
    use when it runs out of RAM so that it doesn't completely flake out.

    Assuming typical desktop use, an average Linux system, today, generally
    requires at least 256MB of total memory (that's both RAM and swap
    combined), with at least half of that being real RAM instead of swap;
    real RAM is always better than swap, when it can be afforded. With 512MB
    or more of RAM, you probably won't ever need more than 256MB of swap.
    However, this all depends on exactly what you do.

    If you run a lot of applications at once, or applications that consume a
    lot of RAM (eg: GIMP, editing a 4000x4000x32bit image), you'll want to
    set up a relatively large swap partition, to ensure that the system has
    plenty of combined memory for those times that it needs it.

    As a general rule, however, don't ever set up a swap partition that is
    more than double your available RAM; it's not that it will hurt
    anything, but it is pointless. If you have 1GB of RAM, and (therefore,
    following the swap=RAMx2 rule) set up a 2GB swap, you have a combined
    total of 3GB of memory. Before your system comes anywhere near consuming
    that 3GB, it's performance will have slowed to a crawl, as it spends
    most of its time paging memory in and out of the swap partition
    (remember, swap is hundreds, if not thousands of times slower than RAM).
    In fact, chances are good that by the time your hypothetical system has
    consumed a mere 1GB of its swap space, it will have slowed down to
    unusability, perhaps even acting like it has frozen.

    The general rule of thumb I'm seeing today is: set your swap partition
    to be equal to your RAM, assuming you have 512MB or more; also, don't
    ever bother making your swap partition larger than 1GB, especially if
    you have more than 1GB of RAM. And this is only if you're a hard-core
    power user who runs applications that consume memory like water. If not,
    a swap partition no larger than 512MB is probably more than sufficient.

    If you have less than 512MB, the old RAMx2 formula is probably good
    enough for most uses.

    Personally, I've got my swap set to 1GB, but that's because hard drive
    space is dirt cheap nowadays, so it doesn't really hurt. With 1GB of
    RAM, though, I've rarely seen it use more than 200Kb of my swap space.
    Ever. Even when I *was* editing those huge 4000x4000 images in the GIMP
    (to be fair, though, GIMP 2 does a pretty good job of paging itself out
    to disk without relying on the swap partition, so this may not be a good
    example).

    Remember though, real RAM is *always* better than swap, when you can
    afford it.

    Finally, I'd recommend using swap partitions over swap files, but that's
    just me. Swap files just strike me as being too easy to screw with,
    although that might just be my Windows bias seeping through.

    >
    > Thank you.


  • Next message: Nico Kadel-Garcia: "Re: Backing up a LInux system"

    Relevant Pages

    • Re: OT (slightly) swap limits
      ... influence your decision on how much swap was enough. ... processes due to lack of memory. ... I've run machines with 1Gig or more RAM with NO SWAP. ... Linux possible when before on Unix it wasn't? ...
      (Debian-User)
    • Re: How to set up a Linux machine that occupies the minimum memory footprint ?
      ... >> memory and hence causes the kernel to 'thrash' thus slowing down the ... 4GB physical RAM + 4GB swap area) the application will think that it can ... You've said in another message that your app is ...
      (comp.os.linux.setup)
    • Re: How to set up a Linux machine that occupies the minimum memory footprint ?
      ... >> memory and hence causes the kernel to 'thrash' thus slowing down the ... 4GB physical RAM + 4GB swap area) the application will think that it can ... You've said in another message that your app is ...
      (comp.os.linux.misc)
    • Re: fedora-list Digest, Vol 10, Issue 167
      ... Well, I have two 433 MHz Celerons and 288 MB RAM, and no performance ... > The memory usage is always around 400MB. ... I'd like to introduce you to the vmstat command. ... > I know that SWAP should be double the Physical RAM but I don't have ...
      (Fedora)
    • Re: FreeBSD data size tuning
      ... It seems there is a memory issue in 4.9 where they adapted 5.x things ... RAM and using 2500MB of swap on ide disk, ... With 1GB of RAM you should be able to run squid without any ...
      (freebsd-performance)