Follow Slashdot blog updates by subscribing to our blog RSS feed

 



Forgot your password?
typodupeerror
×
Linux Software

Ask Slashdot: Linux and Swap Optimization? 176

I found a nameless submission in the submission box that asks a fairly good question: "I'm installing Linux for the first time on Intel hardware (I've installed Linux for PPC and BSD for Intel and 68K) but I am confused on how the swap partition should be handled for optimum performance. The Linux Installation Guide says I should have my swap at least as big as my RAM and that the swap partition should not be bigger than 127MB. Also a "rule of thumb" answer I got from my BSD using friends is that my swap should be twice the size of my RAM. Since I have 128MB of RAM should I have two swap partitions? Also how will swap drive performance affect system performance? Would a Fast SCSI (20MB/s) swap drive be any different than a Wide SCSI (40MB/s) swap drive? There seems to be little information on how to 'tune' Linux swap for machines with 100+ MB RAM."
This discussion has been archived. No new comments can be posted.

Linux and Swap Optimization?

Comments Filter:
  • by Anonymous Coward
    The faster your swap disk is, the more system performance will be improved when swapping. Splitting your swap between multiple controllers (i.e., if you have two-channel SCSI, put a swap area on one drive of each channel) will also help, particularly with IDE. Several swap areas split between several controllers are better than one big swap area.

    Amount of swap: Disk speed counts here as well. If you have fast disks, swapping does not degrade your performance as much as with slower drives. In any case, if you find that you need 128 MB of swap normally, your real problem is that you don't have enough RAM. Get more. In practice, 64 MB swap should be plenty, but it depends on what the machine does. Even with too much RAM, it will swap out a small amount. This is OK. If you are swapping IN (and out) a lot, you need more RAM.

    If you have two controllers and two disks, go with two 32MB swap areas; if they are greatly different speeds, you may want to give them different priorities, experiment. If you have one controller, use one 64MB swap area. If you're really paranoid about it, add another 64MB swap area on another disk; that much disk space is an insignificant fraction these days.
  • by Anonymous Coward
    on a 450MHz system with 20 users acting as an afp file server with light loads :

    MemTotal: 156332 kB
    MemFree: 102704 kB
    MemShared: 13100 kB
    Buffers: 20896 kB
    Cached: 17636 kB
    SwapTotal: 34236 kB
    SwapFree: 28972 kB

    my swap is around 1/4 the total RAM and my machine has never been able to fill it up. When i copy 8GB from one drive to another the RAM often fills with HUGE buffers but the swap seems to remain constant. My advice : use 127 MB of swap if you have it, but you shouldnt need it. normally try for a swap partition which is 1/4 the total RAM size if you have 128+ megs of RAM.
  • by Anonymous Coward
    I would just like to comment on the need for multiple SCSI controllers for the use of multiple swap partitions. If your SCSI controller (or channel) is reaching maximum bandwidth because of multiple devices using it at once, then this is a valid consideration. However, please do not confuse multiple device/channel SCSI performance with IDE performance. There is just no comparison. The maximum theoretical bandwidth of an ultra2 channel is 80MB/sec right? have a look at the faster ultra2 disks out there and you'd be hard pressed to find one over 20MB/sec. What? why have a bus architecture that is capable of 4X the speed of the disks it serves? well, for multiple devices, of course. Theoretically, one ultra2 channel could service 4 ultra2 disks (assuming = 20MB/sec/disk) at each of the disks maximum throughput. So, it may not make a bit of difference to put the second swap partition on a separate SCSI controller/channel.

    by the way, the fastest ultra66 IDE disks I saw couldn't do more than 15MB/sec. considering the huge performance hits 2 devices on one IDE channel, why does ultra66 exist (or ultra33 for that matter)? marketing hype?

    just my $0.02...

    Dave
  • by Anonymous Coward
    Quantum has a surprisingly honest discussion on why UDMA disks are not as fast as one may suggest, the 33 MB/s (or recently 66 MB/s) transfer is just a small part of the whole handshaking process that is needed to transfer data, so all in all speed is much, much lower.

    SCSI on the other hand is designed for high speed and efficieny. Also 80 MB/s SCSI is not the fastest, SCSI 160 gives (not entirely surprisingly ) 160 MB/s. Given that the fastest SCSI disks can perform at 40 MB/s SUSTAINED you need only 4 of these in a RAID 0 to saturate the bus. At that point you have already saturated the 132 MB/s PCI bus in its normal configuration (32 bits, 33 MHz). Check the Multi Disk HOWTO for discussions on busses and speeds.

  • There are a few things to keep in mind.

    The first and foremost is that no single hard drive can transfer more than about 10meg per second (at least when I last researched it a few months ago, I haven't heard of anything faster than 10k rpm drives so I think it's still accurate).

    So, if using one hard drive the difference between the 20 MB/s and the wide 40 MB/s would make absolutely no difference - the 20 MB/s would never be exceeded.

    That figure (20 MB/s or 40 MB/s) is the capacity of the SCSI bus. SO, if you put three drives in the box, then the possible total transfer rate of 30 MB/s _would_ make start kickin' in.

    So don't waste your money on a Wide controller or Wide drives (40 MB/s) unless you plan to eventually have more than two drives on that controller.


    As far as swap priorities go, use the same priority for multiple swap partions on different drives and different priorities for multiple swap partitions on the same drive.

    For a single swap partition on each of different drives the idea is that with the same priority the kernel is supposed to automatically "stripe" the usage of the partitions (i.e. use all the drives at the same time and make the total transfer rate higher).

    For mutiple swap partitions on the same drive the idea is to have different priorities to different partitions so that it is "guaranteed" not to try to write to the parititions at the same time (since on the same drive it would slow things down overall since the drive can not write to multiple areas of the drive simultaneously).

    For multiple swap partitions on multiple drives you combine the above two. The first swap partition on each of the multiple drives should be given a priority. The second swap partition on each of the multiple drives should be given another priority.

    (And yes if you want more than 128MB of swap space you need to create multiple partitions each of size 128MB or below.)

    Lastly, the rule of thumb "swap >= twice the amount of physical RAM" assumes you'll swap and came about in the golden days when RAM was minimal and expensive.

    If you don't expect to actually be using all of the 128MB you might not even need swap partition(s) at all.

    Good luck,
    strcat!

    "One World, One Web, One Program" - Microsoft Promotional Ad
    "Ein Volk, Ein Reich, Ein Fuhrer" - Adolf Hitler
  • by Anonymous Coward
    Don't listen to the morons who tell you 1x memory, 2x memory, etc. It's bullshit. How much swap you want, on any modern OS (Linux, Solaris, etc.) depends on what you're planning to do. With less RAM, you often want more. With more RAM, you often need less.

    Basically, if you're liberal, you'll want to figure out how much memory you'll use at peak, multiply that by 1.5 to be safe, and make sure swap is at least that. More swap never hurts performance, so if you don't care about money, you may as well have an arbitrarily large amount.

    For a (minor) performance benefit, you'll want swap to be the size of the total memory you use at peak, instead of having memory+swap be that size. Linux has fairly aggressive memory management; during idle cycles, it often writes out a copy of a page before it runs out of memory. It keeps a copy in memory and remembers if it's 'dirty.' That way, if it suddenly needs more memory, it can dump those pages from memory instantly without needing to write them out.

    Likewise, if you accidentally allocate too little, you're also not too badly off. Like Windows, Linux supports swap files. Unlike Windows, you can add swap files dynamically as the system is running. Should you ever run out, you just make a swap file, and you're fine.

    If you're conservative, or on a lower-end system, figure out how much memory you'll use at peak, and go with that as a total for memory+swap. Add/increase swap files as you need more.

    Why use swap partitions instead of swap files at all? They're a bit faster than swap files.

    Personally, I have 64mb RAM, 64mb swap, and I've never run out, but I only do e-mail, zephyr and light browsing locally. If you do more, you may want as much as 256mb total. If you do 3d rendering, animation, or work with large graphics, then you probably know how much more you need.

    - pmitros
  • by Anonymous Coward
    Majordomo@www-klinik.uni-mainz.de is addy not
    Majordomo@www.klinik.uni-mainz.de

    subscribe linux-perf
  • by Anonymous Coward on Thursday July 08, 1999 @04:30PM (#1812285)
    It would seem to me that the amount of swap
    is really very dependent on the intended
    use of the machine. I administer machines
    being used as multi-user systems by physicists.
    Unfortunately, this means that occasionally, and
    quite unpredictably, I may have a user launch
    a REALLY big job(~350+ MB). Or I may have
    several launch moderately big jobs(10 users x
    ~50 MB). Needless to say the result would
    not be pretty if I followed many of the
    recommendations here.

    What is far more useful than a simple recipe
    would be some reasonable explanation for
    new users of WHAT swap does, how it works
    under linux, what user memory footprints tend to
    be like, and bringing it all together to give
    some notion of what your swap + memory needs
    are.

    For example, typical light users in my
    environments can be expected to be running
    netscape (footprint ~20MB), ghostview (~3MB),
    and some other stray programs (~5 MB). So
    my safe estimate on light usage is a 40MB
    memory footprint per user. It's not
    unusual for my more heavily used machines
    to have 20 such users going at a time, so
    I need to support a ram + swap in the 1 Gig
    range. All of this is based upon a cursory
    examination of the UltraSparcs I deal with.

    What would be helpful would be for someone in the
    linux community to start putting together
    some carefully researched information
    about program and user memory footprints.
  • /etc/fstab

    You partition the second drive to have a 128 meg swap partition and point the kernel at it in /etc/fstab. Your primary drive on on the first IDE channel would be hda (or sda for the first scsi device) your old drive would be hdb (if its the slave on the first ide chan).
    Lets say you have 64 megs o' swap on the second partition of hda yer /etc/fstab will have an entry
    /dev/hda2 swap swap defaults 0 0
    like so.
    If yer second drive has a 128meg swap on partition 2 youd change /etc/fstab entry to look like
    /dev/hdb2 swap swap defaults 0 0
    You could also just add an entry for the second swap partition then do
    #swapoff
    #swapon
    and that would give you 64+128=192meg
  • you can grab it here:
    http://www.klomp.org/mod_roaming/ [klomp.org]

    -- Does Rain Man use the Autistic License for his software?
  • Why should you put any swap space in when you have 128M of RAM? Here's why -- the kernel can agressively swap out programs and use that space for disk cache, which becomes a huge performance boost when your program footprints start approaching your memory size. I have a headless machine that only runs a few services (news, mail, web, etc) with 80M of ram, and it often swaps when I have less than half that RAM taken up by currently running applications. Disk is cheap, burn a little and get a big performance boost.
  • Actually, it does. Back when I still ran Slack 3.1 on my home box, I used RAID 0 to join 2 partitions on my 2 IDE hard drives (I know, I know) and used that as my swap space. It worked just fine.
  • Actually, that is a bad, bad idea. If you allocate away all your system RAM, and only have a swap file, all the paging goes through the VFS layer, which needs memory to do its work. You could (theoretically, I don't know if this is practical or not) introduce a deadlock condition where the code needed to manage VFS and the FS the swap partition can't allocate the memory it needs to do its job. I may be wrong, but it's certainly a possibility...
  • Your last comment sounds like a job for swapd. Search freshmeat for it, and give it a spin.
  • Ok, in Solaris 2.x, most of your 4GB of memory is swap using tmpfs. You're only using the disk when you run out of room in tmpfs.

    And, if you have only 2 drives and 4GB of memory, I suggest you spend a little cash on another drive.


    _damnit_
  • First of all, the ``twice the RAM size'' rule is a moronic leftover from operating systems which used swap in a backing storage manner. On these systems, the virtual memory size was equal to the swap size, with RAM serving as a sort of high-speed cache over that without contributing to the amount of swap. Meaning that there *had* to be at least as much swap as RAM for architectural reasons. In Linux, the total space available is the *sum* of the swap size and RAM size, so that rule of thumb, for what it may be worth, needs to be modified to: have as much swap as you have RAM.

    Of course, the problem with rules of thumb is that not all thumbs are the same.

    Ideally, you don't want any swap space at all. In practice you have to look at how much virtual space your applications need, and then decide how much of that space you can afford to represent with real RAM.

    If you need a peak value of 256 megabytes of memory to do what you want, and you have 64 megabytes of RAM, then you will obviously need 192 megabytes of swap space. If what you are doing won't run well unless all 256 megabytes are real RAM, then you will have to get 256 megabytes of ral RAM, in which case you then won't need any swap at all (but you can always have swap for the hell of it for for emergencies).

    Whether or not it's efficient to meet needs with a large amount of swap depends on the locality of memory references within the applications you are going to be running. Some applications simply won't run well if you don't have actual RAM, others might. Applications that have a small access pattern, but large memory usage (because, for instance, they have nasty memory leaks :) will benefit from a large swap space (the leaking ones will be able to run longer, if not better :). Applications that periodically access large areas of memory will need actual RAM. For example, image processing or scientific simulations with huge arrays.

    So there is no one-size-fits-all rule of thumb; you have to consider the nature of the application. First estimate the memory usage, trying to err on the side of too high rather than too low. Then based on the application type, determine how much swap is sufferable. Perhaps as little as one fourth of the total requirement needs to be physical RAM. Or maybe the whole thing has to be RAM.

    Also, simply set a low cutoff limit based on the RAM market. For example, these days, you might want to assume that there will be 128 megs of real RAM no matter what and proceed from there.
  • You are.
  • by Tarrant ( 1817 ) on Thursday July 08, 1999 @07:18PM (#1812295) Homepage
    There's no need to go above 128MB under any configuration except ones that are already performing very poorly.

    Think about it: What would you do with more than 128MB swap space? Swapping at all is very bad; swapping a couple hundred megs is pretty catastrophic!

    On low-end machines, a 128MB swap would be 2x or 4x the size of your RAM. That's plenty of extra room for X, Emacs, whatever bloated thing you're running.

    On medium-end machines, a 128MB swap might be double your RAM, and...well, why not?

    On high-end machines and servers, you don't want to ever swap. Disk is just too slow. However, the algorithms in the kernel are kinda tuned on the assumption that you have at least a bit of swap space. The buffer cache, for example, might not shrink fast enough when you need the RAM for some fast-growing process. So stick a small swap (like 128MB) on the machine to keep some balance in the algorithms, but hope you don't have to use it too much.

    Do you see a pattern? Just go with 128MB. It should be just fine.
  • The variable density of the data storage on platters makes the rotational velocity moot. On the outermost tracks, data is less dense than on the inner tracks. The image of the subdivision of a platter into sectors is a pizza cut perfectly into slices, and then concentric circles are cut through the slices.

    Each sector (the individual pieces of pizza from the above illustration) is able to contain the SAME number of bits of info, NO MATTER WHERE IT IS ON THE DISK. This is done to make the rate of reading and writing from/to the disks a constant no matter where on the physical platter you are.

    There IS a reason that putting the swap partition on the outter most sector increased performance...

    Because sectors are almost allways numbered starting on the outermost tracks of a partition, if you have only 2 partitions then you can optimize the swap performance. The first partition would be swap (note this if for smaller disks, where the /boot stuff is under the max cyl # barrier) and the rest would be application file system. When you install the OS, programs and data fill the partion from the outtermost tracks inward, which will be closest to the swap partition. As a result, the drive heads will never have to travel further than from the innermost sector containing data.

    This will not be all that effective however, if you have multiple partions that are all accessed frequently. If you have /usr and /usr/local on separate file systems, for instance, and you use programs/data installed in both directories equally frequently, then placing a swap partition between the other two partions is actually the better way to go.

    The assumption that rotational velocity has anything to do with it is wrong; the placement of the swap partion is correct for basic partitioning scheams.
  • Actually, your first point is incorrect (unless drive design has changed radically in the last couple of years). Here's an excerpt from my post (the rest is located above, concerning the topic postion on the disk).

    snippet begins------------------------

    The variable density of the data storage on platters makes the rotational velocity moot. On the outermost tracks, data is less dense than on the inner tracks. The image of the subdivision of a platter into sectors is a pizza cut perfectly into slices, and then concentric circles are cut through the slices.

    Each sector (the individual pieces of pizza from the above illustration) is able to contain the SAME number of bits of info, NO MATTER WHERE IT IS ON THE DISK. This is done to make the rate of reading and writing from/to the disks a constant no matter where on the physical platter you are.
    --------------------end snippet
  • Forgive me for I cannot help myself...

    My swap partition on a box with 128Mb RAM is a mere 32Mb and I've yet to see more than 2Mb swapped. So why waste the disk space?

    Yet with KDE, I regularly swapped up to 48Mb and beyond.

    Ok, so it's not NT (which bloody swaps even when no apps are loaded!) but why the huge differences? Is WindowMaker really that light?
  • In my never ending quest to try all the distros I can, I've made one partition for /home and regularly blown away everything else, including swap.

    The largest I've had my swap file is a 128Mb partition and with WindowMaker, I've never seen it use more swap than with 32Mb.

    You could well be right but in julesLand, it doesn't seem to be working that way!
  • ...because there are many platters. It's been a long time since hard disks have been on a single disk. Not only that, but they're double sided. So you end up having 6 "beginnings" for a hard disk of 3 platters...it no longer seems like such a big deal where your swap partition is.

    <tim><
  • Hmm...I agree with all you said, but you don't say why I was wrong. Let's say my disk has 2 platters, and double sided. So 4 effective sides. Let's say it's a 1 gig disk (I don't know whether any drives actually exist with this configuration, but this example is to demonstrate a point, not be technically accurate).

    Each effective side (ES, let's call it) has a beginning and an end. As you say, data is written from the outside in. But you have 4 different beginnings and endings with 4 ES's, each of 250 megs. So I can either put the swap at the first cylindar, or at the 250st megabyte boundary, or the 500th meg boundary, or at the 750th meg boundary. You'd have to do some calculations to figure out exactly which cylander this is at (since most disks aren't exactly 1 gig in size) but I think it'd be the same.

    I have no technical background in this area, so forgive me if I'm missing something totally obvious. Let me know if I'm wrong.

    As for why benchmarks show that reading/writing at the beginning of the disk is faster, it's because it *is*. But that's b/c we're comparing reading/writing at the beginning of the disk to anywhere else on the disk So of course, the second way is slower. However, I think that there exists more than one fast location on the disk--at the beginning of each ES.

    <tim><
  • also, putting the swap on a different controller and hard drive than the root filesystem...

    ive heard of people getting up to 10% system higher system performance with this method
  • You should really check to see how much memory your application is using and make sure you have enough RAM to cover it.

    If you are going in to swap then use about twice the amount of swap as you have memory and spread the partitions across as many disks/channels as you can.
  • If you set the swap priority to two swap partitions to be the same in Linux 2.0 and later it will stripe accesses to them. By default however, it assigns swap priorities in decreasing order according to fstab
  • by maynard ( 3337 ) on Thursday July 08, 1999 @04:25PM (#1812305) Journal
    Unlike most, I'm one who believes in investing as much disk to swap as you can afford. 2xRAM is my minimal swap space.

    With Linux kernels previous to (I believe) 2.0.36 you must make each swap partition no larger than 128M, though you may have an arbitrary number of swap partitions or files (and yes, Linux can use swap files in the filesystem instead of individual partitions, but at a performance penalty).

    Older 2.0.x, 1.2.x, and 1.0.x kernels must use individual 128MB swap partitions or files (actually, I seem to recall that 1.0.x kernels didn't support swap files, only partitions), but don't know if the larger swap partition support is limited to 2.2.x kernels or the later 2.0.36/37 kernels. /usr/src/linux/Documentation/Changes in 2.2.10 only states that the 128MB limit is gone, but doesn't list the new physical limit -- I've used up to 1024MB in one swap partition so I know that it can get pretty big. I wouldn't be surprised to find that the limit is 2048MB to conform with the 32 bit file size limit in ext2fs simply for parity with swap files in mkswap.

    Now for why I like lots of swap: You don't have to use it, but when you need it you REALLY need it! Your VM space is only as large as core and swap. Yes, I know the kernel can address anywhere within the 4GB boundary, but the total number of usable pages is limited to your physical RAM plus swap space! This is important to consider if you ever want to run lots of processes which sleep until asynchronous I/O events wake them up. If you want to start lots of processes and let them go off to sleep, having plenty of VM space makes sense. The machine will only thrash if there's memory contention among processes in a run state, so it's safe (and desirable) to let sleeping processes page out to swap while the machine uses physical core for running code.

    Also: consider the possibility of a small application using huge datasets. I run into this at work all the time. We have clustered machines each with 1/2GB of RAM and 1GB of swap. As long as each process only keeps dirty pages of the dataset in core, one can have multiple program instances crunching through different datasets even though together they're exceeding total physical core. Since these programs are stepping linearly through the data, instead of randomly seeking different pages like in a program doing long jumps, this can actually work well. Memory contention occurs not when you exceed total physical ram, but when running processes request pages that have been flushed to disk!

    If you're careful and selective about how you use the extra swap space you can wildly exceed physical core without significant performance loss. Food for thought.
  • I configure our big multi-user compute servers, and I am a firm believer in giving them lots of swap. There are three ways it can be used:

    1. to swap out all the inactive daemons, etc when a user process(es) comes close to using all of
    physical RAM. This can use up to 30M or s of swap on a typical system,

    2. for large stopped jobs (or interactive jobs waiting for input) -- it is sometimes nice to be able to have thee or four processes as large as physical RAM, even if only one of them can execute sensibly

    3. For the very rare user with a LOT of time and a problem that won;t fit in physical memory

    and no we can't buy more memory -- it won't fit.
  • I don't know much, but having two swap partitions on the same drive sounds bad. Linux may be smart enough not to do this, but it is conceivable that it could try to write to both partitions simultaneously, thus reducing performance.

    For maximum performance out of your swap space, you probably want it closer to the beginning of the disk. Of course, if you don't do much swapping to disk then filesystem performance may be more important to you, so in that case the swap partition should go closer to the end of the disk.

    You probably won't really notice a difference either way, though.
  • I have no problem to force swapping (or actually paging :-) on a 96MB-single-user-client :-)

    And memory gets even more important with a multiuser-system. My personal "internet-connected" computer eg has 48mb ram, 128MB swap, 30 users and needs around 70mb swap after one week or so even without X. (ok, squid, qwsv and up to 20 screen-session eat quite a lot :-)
  • Please take a look at the linuxperf website:
    http://www.nl.linux.org/linuxperf/ [linux.org].

    If you want to help with the site, subscribe to the linuxperf@nl.linux.org mailing list by sending a message to Majordomo@nl.linux.org [mailto] with "subscribe linuxperf" in the body of the message.

  • I've wondered this too. Especially since I don't own a machine that has less than 128 MB RAM.. most have in the range of 160-192... and every time I install Linux, sizing the swap partition has always been a big question... of course, now that question will be made easier now that the newer kernel supports larger swap files.

    Note: The linux folks out there need to adjust what they think is a reasonable machine, and provide some guidelines for us who like max things out in a box. I can see the swap guidelines applying to people putting Linux on discarded Pentiums, 486's and non-G3 powerMacs... but there needs to be some guidelines for those of us who buy/acquire/build machines that have wicked fast CPUs, normal Hard Drives (even though they may be of capacities barely heard of a few years ago) and enough money to buy decent amount of RAM (Esp with 128 MB DIMMs going for around $100 a pop, it's easy to get large amounts in a desktop machine).

    So basically, after reading all the posts, the concensus is: Use 128 MB no matter how much RAM you have if you're using a single user machine, and don't really worry about it (assuming the use of an old kernel that only allows a 128 MB swap file), or the same size as your RAM if you're using a newer kernel.

    On server level machines, or machines that are to be used as servers, you need to do a little more analysis based on how the machine will be used.

    Anyone want to verify this?

  • One thing about swap that the previous posters haven't mentioned is to put your swap partitions in the lower cylinders of the drive, as they are capable of transferring data the fastest due to their location on the inside of the disc. I've got three discs with 128MB each of swap space and each is in the lower cylinders in my 512MB server.
  • by Taco Cowboy ( 5327 ) on Thursday July 08, 1999 @03:51PM (#1812312) Journal
    To get better performances for Linux machines, subscribe to the Linux-perf mailinglist.

    To subscribe, send email to majordomo@www.klinik.uni-mainz.de and put "subscribe linux-perf" (without the quotes) in the message body.
  • What programs are you using that shouldn't have titlebars? Window Maker seems to unerstand any hints that my programs give it. X11amp/xmms doesn't have title bars when I run it. Thats good enough for me.
  • I have found that my system, which has 128mb of ram, uses very little swap. 64mb should be fine, I currently have a 128mb swap. ("Very little" is 15% maximum)

    Sincerely,
    Nelson Rush

  • This has been cited several times in the previous discussion -- though some think cyl 1 is near the spindle and others think it's near the edge of the platter. The basic principle is that there are more sectors/track at the outer edge of the platter(Zone Bit Recording technology) and the sequential media rate is faster(though you will suffer some from rotational latency on the outer tracks -- it's a trade off)

    The real answer is that it's manufacturer dependant. The SCSI/IDE command set doesn't specify when I seek where the head will wind up physically. Right now I have queries in with both Seagate and Quantum over this issue because I'll be tuning a new server in the next few days.

    --

  • My recipy is this: 2xPhysical Ram for swap. If possible put each 128Mb swap partition on a diffrent disk.

    Assign the same pririty to each partition on a diffrent disk....

    ie:

    3 disks with 6 partitions...



    the first partition on each disk at priority 1 then the second on each disk at 2...

    Hop this helps!

    "There is no spoon" - Neo, The Matrix
    "SPOOOOOOOOON!" - The Tick, The Tick
  • There is plenty of reasons for going above 128MB swap. I have (well, the department here has, but I take care of them) a cluster of dual-PII:s with 256MB physical memory and 1GB swap each. I have seen many programs here eating around 600-700 MB of memory, the top notation was a Matlab script using close to 1 GB of memory. Yes, the script was carefully written to avoid thrashing. On the other hand, I have also seen programs using "only" about 400 MB that thrashed like h*ll.

    Yes, we're about to buy 1 GB of memory per machine, we really need it. Problem is that with these fscking PC:s you can't have more than 1 GB. We don't really want to buy a Sun Enterprise or an Alpha, since we're trying to move to all PC:s, so I guess we'll have to wait for the Xeon machines to become common.

    Our department is into research in coding theory and cryptography among other things, and the simulations for this kind of stuff are huge. One of our professors want to run a program which needs 4 GB of memory and 20 GB swap, and so far we haven't found any machine which can manage that.

  • One thing you can do if possible is put your Swap on a different harddrive and if you have 2 swap partitions give the one on the separate drive higher priority.
  • Anyone who thinks they can go without swap space is kidding themselves or not running Netscape :)

    In all seriousness my rule of them is:

    Twice the amount of RAM or 256M whichever
    is smaller.

    My primary workstation has 256M of RAM and 256M of swap and I have actually allocated all of my RAM and half of my swap before. They occasions this happens are rare, but imagine if I didn't have the swap there!

    I used to run Linux on a P90 with 16M of RAM and 32M of swap and I can rember programs crashing because of running out of memory. I don't ever want to deal with that again.

    If possible use a high speed drive, but the most signifgant factor is haveing plenty of RAM. I will never build a box again with less than 64M and anything for development use will have a good 128M if not 256M.

    -Alan
  • Ssshhh. Don't tell Mindcraft about this.

    --
  • by Firehawk ( 7687 ) on Thursday July 08, 1999 @05:21PM (#1812321) Homepage

    So if I'm running a 2.2.x kernel and a 64Mb swap partition, and say I wanted to make it 128Mb on the second drive, what would I need to do to change it?

    make a new partition on the new drive (use fdisk or whatever), make that drive type 82 (correct me if I'm wrong but the correct type for linux swap anyway), format that drive (mkswap?) and swapon it (or put the appropriate entry in /etc/fstab).

    there you go. easy peasy


  • If I remember correctly, there's a sysctl thing to turn off the overcommit. I just can't remember what it is off the top of my head. See the kernel docs :)
  • I think even if you have 128MB+ RAM, you still want swap. If you have at least some swap, inactive processes can be swapped out in favor of cache when there is heavy disk activity.

  • I always found that partitions at the end of a disk were fastest to access... Maybe I was mistaken.
  • I had problems with Solaris 2.6 where I couldn't assign a priority to the swap areas. Compounding the fact is that Solaris has a 2GB max swap size per parition. This makes it difficult to have 2x physical RAM as swap on a system that has 4GB of memory and only 2 disks!

    Oiy!

    James

  • 128MB seems to be more than enough for the server I'm running (with apache, ftp and >10 simultaneous telnets running gcc and debugging...). Admittedly, not the most mission-critical or demanding of tasks, but it might give you swappartitionformatting folks an idea of what is possible. It seems as if linux can, when it wants to, do some rather impressive garbage collect...
  • by trims ( 10010 ) on Thursday July 08, 1999 @04:08PM (#1812327) Homepage

    You asked three seperate questions, so I think I'll answer them in order:

    First off, the 127MB limit was for the older 2.0 series of kernels. The new 2.2 series (and dists based on them) has a much higher limit (I can't remember exactly what is it, but it's ALOT bigger (maybe like 1GB or more)). So, you can make a single swap partition of 256MB or so. If you are using a 2.0-based dist, you should make multiple partitions, each no bigger than 127MB.

    IIRC, linux is like the newer Solaris 2, IRIX, and HPUX systems in that swap space is added to physical RAM to come up with the Total Virtual Memory allotable on the system. Under older BSD4.2-based systems (I don't know about current Free/Net/OpenBSD stuff), swap space equal to physical RAM was used to "shadow" the physical memory (and improve swap performance), and thus your Total Virtual Memory was equal to the amount of swap space you had.

    For Linux 2.2, the rule of 2x physical memory is perhaps a bit overkill. I prefer the Solaris guidelines: you should have at least 128MB of total swap+physical for a typical end-user system, with 256MB for a developer/power user, and 512MB for someone using high-end graphics (the X-server gets big) or doing serious work. The point here is: swap space is slow. You should have enough swap space to hold applications that you aren't currently using, but huge amounts aren't useful (unless you have an application that likes to map large amounts of Virtual Memory, but doesn't actually use it). For most of us, I think no more than 256MB of swap is best.

    Swap being slow, putting your swap drive on the fastest possible disk is a good way to enhance performance. In your case, the performance characteristics of the drive are more important than the interface. Thus, a new drive (6.5ms / 10,000RPM) with a FastSCSI interface is preferable to using an older drive (perhaps 9ms/7200RPM) with WideSCSI. Striping swap is also a good idea, though you should use drives of similar speed.

    Also, note that linux can swap to a file, as well as to a raw partition. However, swapping to a partition is faster, and preferable.

    -Erik

  • I've been using a machine without swap drive for several months. I have 128MB RAM. I had the swap drive on old Maxtor 170MB drive that finally croaked.
    Yes, Netscape is the only app I use that seems to take memory and not give it back. Eventually I have to shutdown Netscape (or wait for it to crash) and then re-launch it...
    When swap space is in need the machine definitely begins to crawl.
  • You're not just whistling dixie! WindowMaker can call me back when they figure out how to make it understand hints. I'm tired of it slapping a titlebar on everything by default. I use ICE for now.

  • There is a daemon out there that will dynamicly allocate swap files as needed. This would be a reasonable solution for casual users.
  • by Grifter ( 12763 )
    I have RedHat 6.0 and 192megs of RAM... I have 200mb swap partition on another Hard Drive... I also run GNOME, and barley ever see it use all my RAM or even touch my SWAP... execpt when I use VMware, then it uses about 10mb of SWAP. A 50 - 100 mb partition is all you need.
  • Er, if you have two swap partitions on the same disk just use different priorities and Linux will fill one up before trying to use the other. If you have them on different disks, use the same priority so that it load balances between the disks (even better if you have them on dual SCSI channels like I do :-)
  • Well I have 256MB RAM and I haven't swapped yet. That's with a 33MB X server, 35MB Netscape, KDE, a couple 10MB mySql severs, and all the "normal" services.

    It only used 60MB with all this running and doing a full kernel compile with -j on my SMP box. (load up to 35, yikes). I did get some "gcc: vfork: Resource temporarily unavailable" messages during the make -k modules, but I had plenty of swap left so it must have been processes or something. Had to limit the concurent jobs to get it to go.

    I'd say, tentatively, that if you have 256MB RAM you probably don't need more than 128MB unless you're doing some serious number crunching. And, you'll probably run into other issues also. I've got two 127MB partitions on separate SCSI channels just to be sure...
  • According to the mkswap(8) manpage that comes with RedHat 6.0, "The maximum useful size of a swap rea now depends on the architecture. It is roughly 2GB on i386, PPC, m68k, ARM, 1GB on sparc, 512MB on mips, 128GB on alpha and 3TB on sparc64." It notes that this is for the new swap area style, which it claims to be supported since 2.1.117. (I don't know if the support is in 2.0.37, but it could be.) It also notes that 8 swap areas are presently allocated, so it's not unlimited. (It can probably be changed fairly easily by recompiling the kernel with a different limit, if it's just a static array.)

    All the guidelines for sizing your swap space based on your RAM size are misleading. On some old Unix systems (SunOS 4, I think), physical memory HAD to fit in swap (to do a core dump) and you usually wanted some extra. I think this is the origin of the "double the RAM size" recommendation for swap space. Under Linux (and I think Solaris and many other systems), the swap space is used for overflow for whatever doesn't fit in physical RAM. Your total Virtual Memory (VM) is the sum of your physical RAM and all the swap areas.

    The best way to size your swap space is to decide how much total VM you want, then subtract your physical RAM. If you have 64 Meg of RAM, and you feel that's enough VM, nothing says you need to create a swap partition. If you want a gigabyte of VM, add enough swap to make up the difference. It all depends on what you want to do with the computer, and how much disk space you're willing to allocate.

    Forget about RAM-to-swap ratios and just focus on total VM. Consider that an old Linux system with 16 Meg of RAM and 32 Meg of swap (double the RAM) had 48 Meg of total VM. Such a machine has less total VM than a newer machine with 64 Meg of RAM and no swap. Your limits will be determined by your total VM, not the ratio.

    Ideally, you'd have enough RAM for your total VM needs and no swap -- it's the fastest. Realistically, you'll want far more than average occasionally, so it's best to have at least some swap. Since disk space keeps getting cheaper, allocating a few hundred megabytes doesn't usually hurt much...
  • Some people have sugested distributing swap partitions across disk drives. Now imagine one of these drives fail. It might look like pulling out a SIMM while the machine is running. I assume the system would collapse in this case. Has anyone tried such a scenario?
    I'm building a small server here and all i want is reliability not speed. So how would it look like having a swap file on a raid5 partition?
  • hpfs did something like this too. It stored the directory structure and other fun things that needed to be read often in the middle of the disk, which could reduce seek time by up to 50%. I've always kinda wondered why e2fs doesn't do something similar.
  • All right. I run several servers at work, and a dual-boot box at home. The only thing I have to say is this: I have a measly 64MB of memory at home, and yet I have only a 16MB swap file. I used to have no swap file at all (the horror! the horror!).

    Guess what? I've run out of memory once in the last two years. Once. That was when I was trying to use SNiFF+ to parse the 2.2 kernel...

    I'm not advising you to use as little swap as I am. It's probably too little, especially considering the way app requirements are shooting up all around these days. However, if you're setting up a workstation here, fuggeddabout the multiple F/W LVD SuperSCSI VII Widgetco hardrives and just set yourself up a nice, comfy 64MB partition anywhere on the drive you want. I'm betting it doesn't get used 99% of the time anyway.

    Servers, on the other hand, are a different story...:)
  • > I'm one who believes in investing as much disk to swap
    > as you can afford. 2xRAM is my minimal swap space.

    I've got a AIX boxes with two- to eight-gig of real memory. There's no way I could justify putting in 16-gig of swap space. Nor would I ever need 16-gig of swap space. My applications would come to a grinding halt if ever that much memory was swapped-out. Even on 10k rpm SSA drives, it takes a long time to write 16 gig of data.

    While your argument has merit, encouraging folks to have at least twice as much swap as physical RAM all willy-nilly is irresponsible. Disk space may be cheap now days but it certainly ain't free. (I wish it were; so many MP3s, so little disk space.)

    Folks need to examine what their RAM is used for and what their swap will be used for. In my case, I'm running Oracle. Most of the RAM is used for Oracle to cache data and not for the application itself. In my case, under 340 meg of RAM is actually a candidate for swap and thus I've set aside 512 meg for swapping. And I don't think that has ever been touched.

    As the amount of memory in computers expands, old rules (swap must equal RAM; swap must be 2x RAM, etc.) need to fall aside to common sense.


    Matt

  • I don't understand why anyone would bother running with no swap space. I have about double my physical ram on my box at home(64 meg ram, 128 swap), and I believe my box at work has more than double(128 meg physical, can't remember how much swap)... I'm at home right now, and I seem to be using 10 meg of swap, probably left over from something I did the other day(seeing as how it never seems to deallocate). I also remember my box at work reading about 40 meg of swap used(it has 128 meg physical). Do I remember what I was doing that made it shoot up? nope :p. Why use this obese amount of swap space when so much is unused? Simple... I don't have the 120 meg drive my old 386 with running 1.2.13 had. I can get away with more than 8 meg physical, 16 swap :). Hard drive space is cheap... I was over at pricewatch today and a 17 gig ide is 180 bucks... just over 10 bucks a gig, or a buck per 100 meg... so if you have 128 meg of ram, it's gonna cost you 2 dollars and 50 cents for swap. Even if I don't use it, I aint gonna miss it... I spend more than that on lunch anywho...
  • when a program allocates memory, linux will free buffers and cache until enough is free, and only start swapping if it still doesn't have enough.
    Remember: Free memory is wasted memory!
  • MemTotal: 517528 kB
    MemFree: 4308 kB
    MemShared: 24236 kB
    Buffers: 11744 kB
    Cached: 384104 kB
    SwapTotal: 64492 kB
    SwapFree: 48736 kB

    I would have posted 'free' output, but it didn't fit right. Anyway, I have on the average, 110mb ram used on this 512mb machine. Usually about 8 xterms open with 10000 lines scroll back (not that much memory actually), netscape with a 30mb memory cache (no disk), still goes just fine.

    I usually don't see swap until a few days of uptime and to be quite frank, I don't know why it would touch swap with this much ram (usually 400mb left over before buffers/cache)
    --
  • Just a couple of additions to this:

    1. if you have multiple swap partitions and explicitly set the same priority in your fstab, the kernel will stripe the VM amongst these partitions, increasing performance quite a bit. You should _not_ make a softRAID array of your swap partitions.

    2. "Swap space is slow so put your swapspace on your fastest disk" is true, but could be misleading: the slow thing in harddrives is the seek time, not the transfer tiem. So you should put the swapspace on your least used drives in general (unless there is so much difference between seek times from the fastest and the least-used that it makes sence--ymmv).

    Also, you could have a cron job that checks for the amount of free swapspace, and adds|removes
    swap files as necessary. As in, say you have 128MB of RAM (as you do). You create a 256MB swap partition, and [if your free swap drops below 32MB you create a new 64MB swapfile (with a lower priority than your swap partition--that's the default), and if your free swap grows beyond 112MB you remove the last swapfile] (cron the []). It works, and it could save your day sometime...
  • Correct me if I'm wrong, but isn't the whole point of shared libraries and such the idea that the second time somebody loads up the 800 pound gorilla app (Netscape, Emacs, GIMP) that they share executable space with the first instance? Now, natch, that doesn't do diddly for the dataspace (like those monster global circulation model datasets with the 192mb initialization files...) but for most "normal people" (whatever that is) this isn't an issue. And those of you running the monster 3d models have NSF grants to get you a few extra sticks for your RAM sockets.

    --
    Poor man's supercomputer: 64-node Beowulf using white box commodity PC's, Node 65 with 19" monitor, 3x24-port switches, wiring, total cost, less than $50k. Less racks and that monster power/cooling requirement. Think about it.
  • "man mkswap" says the limit for SWAPSPACE2 is architecture dependent:

    "It is roughly
    2GB on i386, PPC, m68k, ARM,
    1GB on sparc,
    512MB on mips,
    128GB on alpha
    and 3TB on sparc64."

    It also mentions that the kernel grabs two bytes of memory per page of swap, with the result that you might end up using 2Mb of physical for a 2Gb swap file.

  • A couple of questions:

    Is it ok to use a logical partition?

    Should you use a partition allocated near the middle of your drive?

  • Beginning of the disk?

    There is no clearly defined beginning to a disk. However, location wise on the disk's surface, it would make more sense to have the swap on the tracks closest to the centre of the disk, however, IDE disks use a variable track density and so this philosophy is actually incorrect. Therefore, in conclusion, it makes no different where on the disk the swap goes (as long as it is ofcourse a contguous allocation :-)

    just thought I'd point that out.

    I can see the advantage to having swap partitions on different disks, but what about adjusting the system buffers. The kernel uses a lot of buffering on my PII (128 Mb RAM) - perhaps there is a way to fine tune the way in which RAM is used also?

    -- "Don't try to be a great man, just be a man."
    -- Star Trek, First Contact
  • Heck, it might already be answered in an FAQ. Every time I check out news on comp.os.linux.hardware, there's some thead about it.

    Anyway, it depends on how much memory you have in your machine and what you plan do run on it. Here's my rule of thumb. For 8 MB up to 64 MB RAM, make a swap partition twice the size of the RAM. For larger RAM, just make swap 127 MB, since it's the limit for a single partition. If you have more than that amount of RAM, 127 MB swap is still fine - remember, you've got lots of RAM.

    (One person's opinion was just go ahead and start off with 127 MB swap no matter how much RAM you have because it's too hard to increase the size after it's been created. I wish I had heard this before I configured my machine.)

    However, if you really need to have several LARGE programs running at the same time (Netscape and StarOffice and KDE and... a few other big things) then you need more RAM than 64 MB (try 192 for starters). If you really need all that swap, adding more is only going to slow things down more, even if it's on another disk - after all, a drive is slower than RAM...

    Still, I'd like to know myself what rules of thumb there are for large memory machines (256 MB and higher). I can't imagine the rules for swap in small RAM machines continues to hold.

  • Actually, no. Yes, the disk is moving faster, but the physical size of the bits are increased. Think of an old record player spinning at 33 1/3 RPM. The same length of sound was on the outer groove as on the inner groove. That implies that a 1 second sound bite takes up the same proportional amount of the groove. It works out to 10.8 degrees per second, whether you are on the inner groove or the outer groove.
    The same applies to a hard disk (not CD-roms, most of them do have a variable spin). A hard disk spins at a fixed rate of speed. There are the same number of sectors on each track, therefore it will take the same amount of time to read a sector on the inner track as on the outer track.

    This being said, there could still be some performance improvements on locating the swap file/partition at different areas of the disk. For example, placing it as close as possible to the most-often accessed data would certainly reduce the time it takes the head to seek to the appropriate track.

    A good rule of thumb is to place a swap file on the most used partition of the least used hard disk (assuming a file and not a partition). For a swap partition, place it as close as possible to the most used partition on the least used hard disk.

    I don't know how the ext2 filesystem allocates space, so I can't state whether the swap partition should be close to the outer edge of the ext2 filesystem or the inner edge. Perhaps someone who knows could respond.

    Jonathan Bayer
  • I run a PII-400MHz 2.2.10 system, which is essentially single user. I have 128 MB RAM, and 128 MB swap space. I've never seen Linux use more than 1 MB of swap space, even when compiling the kernel. While running X. And Netscape. And X11Amp.

    Oh course, if I were running a server, I'd keep the 128MB, just in case. But I don't. Next time I reinstall Linux, I'm reducing the swap to 32MB (just in case...).
  • I know this question was about Linux, but I wanted to put my 2 cents in about swap and Solaris as I often run into admins who are ardent supporters of the 2 x RAM rule. My experience is that a lot of people overdo swap on Solaris. The best way to gauge your need of swap is through trial and error. You need to look at what you are going to do with the box and you need to be familiar with the applications. Solaris 2.x deals with anonymous memory in a more efficient manner (it relieves the need for swap space when a process demands more space). The tools you can use to figure out your needs would be /usr/proc/bin/pmap, swap -s, vmstat and df. Sure bets that you will need sizable swap space are databases that rely on shared memory. Often their requirements exceed physical memory. (Check out the Solaris Performance and Tuning from Cockroft and look at Sunworld's [sunworld.com] swap article from January of `98.) The moral: KNOW YOUR APPLICATIONS. TEST, TEST, TEST! Run the application and peek at it with pmap. How much does it memory does it take? Is that what the peek is? Then do this with the other processes on the system and add them up. Look at swap with vmstat and df -k. Do you have a lot of /tmp and /tmp is swapfs? If you do, then maybe you have too much swap. Also, be sure to trim your system of unneeded processes. Why have automountd running when you don't automount? Why have nfs or rpc running if you don't need them? You will find a winning combination after trial and error. Nothing beats experience and testing in sizing a box.
  • by Paul Doom ( 21946 ) on Friday July 09, 1999 @04:48AM (#1812353) Journal
    There is one beginning, and one end. With multiple platters, the disk doesn't write one platter until it is full, then go on to the next.
    It writes in parallel. That, plus higher media densities, plus higher rotational speeds == faster disks.

    Put your swap on the lowest numbered cylenders that you can if you want the fastest swap. I have yet to hear of a modern drive whose cylenders are not marked starting from the outside of the disk working into the center. There are two reasons the outside of the disk is faster.

    1. Rotational Speed -- More media passes the heads in one rotaion on the outside tracks. The media density is constant accross each platter, so the amount of disk real estate passing under the heads at any position is relative to the heads' distance crom the center of the spindle. If you think of each track as a line, then the length of each track is 2 * the_distance_from_center * PI.
    All this means the disk's maximum throughput is realized when readin/writing to the outermost tracks.

    2. Relative position -- It is obvious that the majority of the data on the disk resides near the outside edge of the disk. Also it is obvious that an equal sized partition will will take up more physical cylenders if it is positioned toward the center of the disk. More physical cylenders = more average distance for the heads to travel when seeking from one block to another when reading/writing non-contiguous blocks.
    This means that the lowest average seek times for a given partition will be realized if that partion is located at the outer edge of the disk.

    If you think that position doesn't make a difference, I have bonnie (a disk benchmarking program) data to back my words up. On some drives, the difference can be huge. That is why the Mindcraft benchmark, where they had both OSes on the same drives, was such a joke as far as disk IO was concerned. Can you guess which OS was on the outside of the disks (first cylenders)? (I'll give you a hint, it is not the OS that allows you to put its / partition at any location on the disk. Another hint, the OS's name starts with an 'N')

    Two more things that others have said, and I would like to reiterate and add to. Put swap on multiple disks, even if there is a disparity in disk speed from one to another, and even if you only want 32MB of swap. And SET THE SWAP PRIORITIES TO AN EQUAL NUMBER BETWEEN SWAP PARTITIONS ON SEPERATE DRIVES! Some folks seem to think Linux does RAID0 for swap automaticly, but it does not. You must set the priorities or swap will be written in a serialized manner. (i.e. -- Filling up one partition before starting to fill the next.)

    And finally, no matter how much RAM you have, have at least a little swap. Why? Every inactive process Linux swaps out makes more room for disk cache and buffers. On a box with 512MB that you are using as a workstation, 32MB of swap is probably fine. Linux has a real memory management system, don't tie its hands by not giving at least a little swap.

    And that is my sermon for the day.

    -Paul
  • For some reason I thought that changed with the 2.2 kernel.
  • In my experience, putting the swap file on the outer edge of disk has increased performance. The disk is moving faster under the head at the edges of the disk. Just a small tip.

    LL
  • Ok, here's another swap question... when I boot up I get the following message when swap is added...

    Adding Swap: 104416k swap-space (priority 2120)

    This started when I went to a kernel level higher than 2.0.0. When I was at 2.0.0 and lower, I get a swap priority of -1.

    Any idea why this might be happening?

    My /etc/fstab swap partition is defined as such...

    /dev/sda2 swap swap defaults 1 1

    Thanks!

    david

  • Excellent. I've always wondered about swaps since I've seen confusing information about this almost identical to what the original poster saw.

    And now a follow-up question:

    Can you/how do you make changes to your swap setup after your system is already installed?

    I think I went with the "recommended" 2x RAM size way back when my machine only had 32Mb and one HD. Now I have 128Mb and I've upgraded my primary drive and have the old one set up as a slave for temp space for CD burning.

    So if I'm running a 2.2.x kernel and a 64Mb swap partition, and say I wanted to make it 128Mb on the second drive, what would I need to do to change it?
  • Placing swaps between other partitions is again a throw back to the days of less powerful machines. Back when disks had the speed of Fred Flinstone in his foot powered car, the time for a disk head to move between data and swap was considerable. Thus the advice was to alternate data - swap -data so that heads would move less when disk paging. Having a data - data -swap configuration could lead to a preformace hitch if the heads had to transverse the extra data partition in the middle. Now days as drives get faster, this consideration is minimal. Theoretically, one can still get a performance advantage by alternating types, but if preformance is this important you are better off just buying more RAM.

    -Bigdaddy
    "You can't get a blue screen on a monochrome monitor!"
  • >HA! First reply to second post! Isn't that great >or what?

    First reply to the first reply to the second post!
  • It depends. You are forgetting that transfer rate has only minor impact on random disk reads/writes (as swapping). Much more slower (orders of magnitude slower) is SEEK time.

    So minimazing seek time (like, putting swap in the middle of the disk - but it really depends on your partition configurations and access) will yield much better speed improvements (esp. when disk is busy, as it almost always is when you start swapping)

    much things affect this, as RAID stripping for example, so YMMV.
  • In my experience, having a small amount of swap (say, 8-16 mb) helps even if you wouldn't necessarily need it. It let's kernel swap out programs that are never used and in general makes the memory usage behave better.
  • by bbk ( 33798 ) on Thursday July 08, 1999 @03:59PM (#1812362) Homepage
    Put one swap partition on each drive you have. The kernel will use whichever drive is less busy to swap on, spreading out the system load. They don't have to be the maximum size. Make whichever one is on the fastest disk have the highest priority.

    You don't necessarily need 2x the size of your physical ram in swap - this is a throwback from the days when RAM was very expensive. 1x the amount of ram is perfectly fine, especially if this is going to be a single user machine - lots of swap is only useful when you either have a lot of users that are idle (i.e. stay logged in when they aren't there) or programs that take up more memory than you can afford.

    I've also heard of ideas like putting small swap partitions inbetween normal partitions, so that the disk heads don't have to move as much. Anyone have luck with a setup like that?

    Also, AFAIK the 127MB limit is a kernel 2.0.X an older requirement - 2.2.X supports bigger swap partitions.
  • 2. Relative position -- It is obvious that the majority of the data on the disk resides near the outside edge of the disk.

    That's 'cause of centrifugal force, right?

  • here are my suggestions for swap files:

    1. if you got more than one drive, spread them across as many drives as possible

    2. partition your hard drives so that the swap partition is either on the outer tracks (faster data transfer) or in the middle (possibly faster access time?)

    3. use fast hard drives if possible (7200 / 10K RPM)

    4. buy more RAM - (ram is MUCH faster than a hard drive) ram prices are about half of what they were a year ago, and it may still be going down.
  • I didn't see this mentioned here, but swap space is used up before the machine fills up the physical memory. This is useful so you have a couple of megs free to run a new program, instead of having to wait to swap crap out first.
    You can tune this by echoing 3 numbers to /proc/sys/vm/freepages. I can't remember where the documentation for this is, but it specifies the limits of when to start swapping and when there's so much memory free it can move it back out of swap even if its not yet been requested.
    I like to set these numbers big to force swapping out sleeping processes and leave plenty free RAM to speed up starting netscape or emacs, whatever.
  • For the record, tmpfs is not used for swap space and /tmp can be mounted on a real file system instead of mounting it on swap (ramdisk).
  • Memory is so cheap that I think there's no excuse to be using *any* swap space. Check your memory usage every so often, and if you're using swap space then buy more memory.

    That said, I agree with the other poster that swap space can be useful for long-term idle programs. And a decent sized swap area is cheap insurance against some program taking up a lot more VM than you expect - I've occasionally run out of VM (thanx, Netscape!) and it is not pretty. But your active applications should never hit the swap disk.

    Of course, this assumes that you're using a recent motherboard and additional memory is available. I still occasionally use a 386 maxed out with 20 MB of RAM. In that case I do have a very large swap partition (when compared to the amount of RAM) and accept the performance hit.
  • I would hope that such university and corporate environments are using real system adminstrators (or students supervised by experienced sysadmins). They will know how to tune swap and real memory for their specific needs.

    My point addresses the vast majority of SOHO users who either have a single user, or at most a family or small department. They should be hitting swap infrequently, if ever.

  • I've heard you can get some extra performance
    out of swap partitions at the lower cylinders
    of the hard drive. More so with the larger
    drives coming out these days.

    Can anyone confirm these rumor/theory?
  • That recommendation comes from Unices that tye a page of swap to each page of ram. Linux (and Solaris) do not work this way. They don't preallocate swap space to the existing physical memory. Any swap space increases your total virtual memory.

    Another issue comes from how the swap is accessed. Some Unices, such as Solaris, automatically alternate between their various swap partitions, resulting in distributing I/O over all the swap devices. It is my understanding that Linux uses them linearly by filling one, then the next. I have not tested this, however. If this is the case it reduces the performance penalty of putting more than one swap partition on a single physical drive.

    As a general rule, I configure a swap partition (or several :) even on machines with a lot of memory. That allows the operating system to page out extremely idle processes (such as that big vi session you opened last week and forgot about) and use the freed physical memory for what would otherwise be a low priority task, such as mapping a couple of additional active files to memory.
  • by dlc ( 41988 ) <dlc.sevenroot@org> on Thursday July 08, 1999 @04:01PM (#1812371) Homepage

    That was one of my first concerns when I first installed Linux as well. I tried it first without a swap partition (Caldera 1.1 mentioned that a swap partition "might be necessary with a low amount of RAM"), since I figured I would be OK without it, and the resulting machine wouldn't run. I had to repartition and reinstall a few times to get it right. Good pratice. :)

    My current Linux machine has 192 M of RAM, and I've gotten away with using one single swap partition of the max size (127 M). I've never had a memory problem, and I have a tendency to run a lot of server stuff (for example, an LDAP server, a mod_perl copy of Apache for development, a mod_roaming copy of Apache to host my department's Netscape profiles, MySQL, and several other custom services), not to mention the many programs I use in the foreground at any given time (several copies of Netscape, several xterms (some running Emacs!), same-gnome, Gnumeric, etc).

    With 128 M of RAM, you probably won't use a swap partition too much, so one should be sufficient. A swap partition is really most essential on low RAM machines (16 M or less) running X or serving a lot of users.

    I say put it as the only partition on a fast disk (maybe a small dedicated SCSI drive... you must a few old ones lying around).

    darren

  • Heh, try browsing several different sites, most of which use java/javascript, and then see how fast your swap space fills up.

    I've got 2xPII400 and 256M, with 246 now allocated:
    MemTotal: 257788 kB
    MemFree: 4872 kB
    MemShared: 61856 kB
    Buffers: 41004 kB
    Cached: 122304 kB
    SwapTotal: 120480 kB
    SwapFree: 120480 kB

    I'm a little miffed at how much memory is hogged for buff/cache, since I'll start swapping out apps I'm using, in favor of the cache. Although, it seems to behave a little better if I let the swap go to 2/3 megs, then swapoff/swapon. What I'd like to see is a tunable parameter that allows me to say don't swap until X amount of memory is allocated to apps, instead of cacheing very large files that I'll only open once.
  • Hard drive space is cheap... I was over at pricewatch today and a 17 gig ide is 180 bucks... just over 10 bucks a gig, or a buck per 100 meg... so if you have 128 meg of ram, it's gonna cost you 2 dollars and 50 cents for swap. Even if I don't use it, I aint gonna miss it... I spend more than that on lunch anywho...

    Sure, but is it worth the performance? I specifically bought a bunch of RAM so that this machine would be fast. I'll probably get at least another 256 for this machine, just to boost performance. Besides, I'd rather use the 17G for DEVO mp3s ;)
  • Go ahead and increase the swap size.. The reason you don't see more than 2 MB of swap usage is not because you have unbelieable light software - it's because you have too small swap size.
    I myself used to have a "small" swap too, and linux almost never swapped more than 2MB. Then I increased it to be 160MB (I have 80MB memory), and even as we speak Linux has swapped out 26MB. This is because Linux behaves differently if it has lot's of space to swap on or if it hasn't. If Linux hasn't got a space to swap on and the memory becomes full, it simply throws some unused stuff "out". If it has enough swap space, it swaps in the same situation. And since when the stuff is again required it's faster to load it from the swap than from the disk (yes, I know, the swap is located on the disk too) this is the preferred method.
    --
  • Everybody likes to come up with their magical number or multiplier for swap. They don't really make sense. If RAM + swap = total mem, then just make sure you have enough swap to increase your total memory to that needed to run all apps you think you will be running concurrently. i.e., bring up every single think you *think* you might want to run at the same time, and then check you memory usage. Make your swap = used memory - RAM.

    I really don't understand the 2x multiplier. Um, if I have 500 MB of RAM, that means that I need 1 G swap!!?? Right! The more RAM you have, the LESS swap you should need. Should be something like:

    swap = .5 RAM maybe
    or
    swap = N + .5 RAM

    Striping is cool...you can do that with swap under NT too...heh, NT even gives you one big stripe of useless data down the middle of your partition for "recovery". That's what I call New Technology...
  • /etc/limits is where you can place your system limits.

    You can limit how many processes can be run, how much memory can be used (total I think).

    -xk
  • If you have 128M of ram, for now, create two 64M (or 128M if you can spare the space, but I wouldn't) swap partitions on two different drives. If you have only one drive, make it a 128M partition near the beginning ...

    Partitions:

    /boot
    SWAP
    ... others ...

    ... this way your kernel files are always in the first 1024 cylinders but your swap is at the fastest part of older disks (newer disks use scattering to make all reads and writes the same speed).

    If you use two disks, and assuming the load on both is about the same, set the priorities to be equal in /etc/fstab:

    /dev/hda2 swap swap defaults,pri=1 0 0
    /dev/hdc2 swap swap defaults,pri=1 0 0

    This way the Linux kernel automatically uses both partitions simultaneously for faster reads and writes. If your hard drive isn't doing anything else, you'll get twice the speed out of this.

    Again, with 128M of ram, you only need 128M of swap, even for most mid-level server apps. If you want to run Slashdot on your PC, you might need more :) ...

    ... leave some unpartitioned space in the middle of your drive to add swap to later if you need to ... (or to quickly partition and back up data to if another partition craps out).
  • Yep did it...

    Linux: dd if=/dev/zero of=/dev/hda1
    almost all of the swapped processes died with strange signals but the systep keep running on

    Linux with swapfile: rm -f /swapfile
    the file is no more here but the disk space is not freed 'till next reboot. system works fine...

    HP/UX: lvreduce -L 1 /dev/vg00/lvol2
    biiiig mistake - system dumps regs and dies

A Fortran compiler is the hobgoblin of little minis.

Working...