Slashdot Mirror


Swap File Optimizations?

fastswap asks: "I've got a pretty standard computer with reasonably fast drives. I've got an old 2GB-but-fast drive, and a spare channel on the motherboard. Does it make sense to install the 2GB drive on its own controller and use it for a dedicated, fixed swap file? I figure if the computer's using the swap file, then in the current setup with the swap file on the primary controller, then it's contributing to hard drive thrash exactly when one doesn't want it to (i.e. when the machine needs the swap file). If it is better to have a dedicated swap file on its own controller, is the same true for other operating systems with similar approaches to virtual memory? Since drive space is so cheap now, should the swap file be fixed size anyway rather than letting Windows suddenly get the urge to resize the thing?"

30 of 177 comments (clear)

  1. Erm by Anonymous Coward · · Score: 2, Funny

    Swap file? Modern operating systems use a page file. Get out of your Loonix mind set, hippie.

  2. swapping? by ArmorFiend · · Score: 3, Interesting

    Do people still swap? Seriously, I can't remember when I heard my prime dueller do the rumble, and its only got 512 megs of ram.

    1. Re:swapping? by Hythlodaeus · · Score: 3, Informative

      As is often the case, games are making some of the greatest demands on hardware. Many current games fill 300 or more MB by themselves, and right now I'm sitting on 225 MB with Mozilla, Word, and mIRC open.

      --
      For great justice.
    2. Re:swapping? by ColaMan · · Score: 5, Funny

      Close Word and you'll probably gain 100MB :-)
      No, seriously.
      I don't know what the hell kinda easter egg's in Word - I know Excel had a flight sim , maybe Word's got a 5 minute video of BillG rolling naked in a pile of money and whores.

      --

      You are in a twisty maze of processor lines, all alike.
      There is a lot of hype here.
    3. Re:swapping? by jonadab · · Score: 2, Interesting

      > I can't remember when I heard my prime dueller do the rumble, and its only
      > got 512 megs of ram.

      I make it a point to have enough RAM that the system almost never has to use
      the swap space, but I consider it vital to have the swap space there as a
      safety net, because occasionally something uses a whole lot of RAM (e.g., I
      might write a quick-and-dirty use-once-and-throw-away Perl script to process
      some data, and it might store them in a Really Big Hash while doing so, or I
      might have to work with an image in Gimp that's intended to be printed at
      600dpi at 8x10 inches, and I might forget to turn down the length of the undo
      history and perform several memory-intensive operations on the image), and
      the Linux kernel has a tendency to react rather badly to running out of both
      memory and swap space. So, as cheap as drive space is, I like to have plenty
      of swap space available for such occasions. Usually, it's 0% used and 100%
      available, but I consider it an important safety net. I like to have several
      gigabytes of swap space, Just In Case.

      However, if you're using the swap space often enough that you want to optimize
      its speed by putting it on a separate controller, I recommend more RAM instead.

      --
      Cut that out, or I will ship you to Norilsk in a box.
  3. Fixed size... by Motherfucking+Shit · · Score: 4, Interesting

    The general advice that I've picked up is that, at least in the *n?x world, you should create a swap partition which is double the size of the machine's physical RAM. For example, if you're sitting on 512MB of RAM, a 1GB swap partition is appropriate.

    You only mention Windows towards the end of your question so I can't tell whether or not you're looking for a Windows answer. I've always allowed Windows to resize its swap file, but within a small window. This machine (Win2K) has 640 megs of physical RAM, and the swap file is set at 1280 minimum, 1960 maximum; that gives Windows "double the real RAM," but not a license to take over the whole drive. Seems to work well for me.

    I've never tried putting the swap on its own channel or controller - or even on its own drive - under any OS. Like you, I'd be interested in hearing whether or not this is worth the trouble.

    --
    "BSD: Free as in speech. Linux: Free as in beer. Windows 10: Free as in herpes." --Man On Pink Corner in #52607549.
    1. Re:Fixed size... by zatz · · Score: 3, Informative

      I think the recommendation of "at least twice physical memory" makes sense only with a VM system which employs a one-to-one mapping between allocated pages and disk blocks. I do not believe either Linux or Windows works this way.

      --

      Java: the COBOL of the new millenium.
    2. Re:Fixed size... by Brandybuck · · Score: 2, Informative

      I've never tried putting the swap on its own channel or controller - or even on its own drive - under any OS. Like you, I'd be interested in hearing whether or not this is worth the trouble.

      I still do this, but with 1G of RAM, I never swap anymore. Back back when I had a 100MHz system and 32M RAM, putting the swap on another harddrive made a significant difference. That was with Linux. Since Windows uses a swap file instead of a raw partition, so it might not make much of a difference.

      --
      Don't blame me, I didn't vote for either of them!
    3. Re:Fixed size... by WSSA · · Score: 3, Informative

      Don't let Windows resize the swapfile - that's a surefire path to fragmentation, fragmentation = slowness.

    4. Re:Fixed size... by Just+Some+Guy · · Score: 2, Informative
      FreeBSD, on the other hand, explicitly recommends having at least twice as much swap as real memory. From tuning(7):
      The kernel's VM paging algorithms are tuned to perform best when there is at least 2x swap versus main memory. Configuring too little swap can lead to inefficiencies in the VM page scanning code as well as create issues later on if you add more memory to your machine.
      --
      Dewey, what part of this looks like authorities should be involved?
  4. Dedicated by yosemite · · Score: 2, Informative

    It is better

  5. Yes, seperate drive and fixed size by viware · · Score: 5, Interesting

    My experience has always been to give windows a fixed page file, at twice the RAM size (ie. 512MB RAM so 1024MB page file). Further, a separate physical drive is the best scenario, or second best is a separate partition.

    It is important to note that WindowsXP will use the page file whether you've got plenty of RAM or not.

    1. Re:Yes, seperate drive and fixed size by Quarters · · Score: 4, Informative
      It is important to note that WindowsXP will use the page file whether you've got plenty of RAM or not.

      You can instruct XP (and probably 2K) to not page the executive and to use more memory as cache space. This reduces the amount of paging significantly.

      HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contro l\Session Manager\Memory Management
      *Change DisablePagingExecutive to 1
      *Change LargeSystemCache to 1
      *Reboot

    2. Re:Yes, seperate drive and fixed size by Zeriel · · Score: 2, Informative

      Well, back in the good old days when 4MB was "more RAM", you generally only had a machine with relatively large amounts of RAM if you were processing a similarly large amount of data.

      Joe User would have a machine with 4MB RAM and 8MB swap for his word processing and Ultima 2 or whatever.

      Stan Scientific would have a machine with 32MB RAM and 64MB swap because he probably was going to eventually have to deal with datasets larger than 32MB (if you've done ANY scientific computing over historical datasets, you know what I mean).

      Basically, more RAM implies you should be swapping less, for a home system.
      But for a server or high-end processing computer, more RAM implies you need vast amounts of RAM in general, and swap doesn't hurt.

      --
      "America has done some terrible things. But I know that Americans don't cheer when innocents die." -Dave Barry
    3. Re:Yes, seperate drive and fixed size by JeFurry · · Score: 3, Informative

      You can instruct XP (and probably 2K) to not page the executive and to use more memory as cache space. This reduces the amount of paging significantly.
      HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contro l\Session Manager\Memory Management
      *Change DisablePagingExecutive to 1
      *Change LargeSystemCache to 1
      *Reboot

      True, but doing this disables standby and hibernate modes, since the kernel can't be unloaded any more. If that's not a problem for you, go ahead of course, but it's worth being aware. I did this, and kept finding my system going into standby on request, but never resuming, and it took me ages to find out why...

      --
      -- What goes up must come down. Ask any SysAdmin.
  6. Separate swap under linux. by derrith · · Score: 4, Informative

    I've done this under linux, say get a 2-6GB drive and use it as dedicated swap. I tend to do this with scsi servers when I'm patching together old gear. Say an 18GB root drive and then the smaller drive as dedicated swap. leaves everything open. And if the swap drive does get thrashed, no big deal. It's quite effective and works well in my experience.

    --
    why does the porridge bird lay his eggs in the air?
  7. Dedicated is better; linux lets you RAID it by Anonymous Coward · · Score: 2, Informative

    Dedicated is better.

    However, you will never get true swap performance using Windows.

    To do that you need a real operating system. Linux will let you put one swap partition on each controller, set them to the same priority, and it will automatically spread the access between them, getting a RAID-like speedup in your swap access times.

    Also, remember to put swap partitions (if you are using files you are hopelessly fucked) on the end of the disk, so that they will be on the outer sectors where the transfer rate is fastest.

  8. Linux Swap Space Mini-HOWTO by sICE · · Score: 3, Informative

    This Linux Mini-HOWTO might be of interrested to some /.ers, it describes how to share your Linux swap partition with Windows.

  9. Good Results by harryk · · Score: 3, Interesting

    I too am in a similar environment as yourself. I took it one step further, and also setup the temp variables to use the same drive.

    I've noticed significant performance increases since doing, not to mention that I've freed up some space on other, more important drives.

    Good luck!

    --
    think before you write, it'll save me moderator points.
  10. Swap: Don't boot XP without it by WarPresident · · Score: 3, Interesting

    An old, surplus, dedicated swap drive on its own channel: $0.00

    A RAMdrive from system memory: Under $100

    A solid state disk drive you shove into a PCI slot with a bunch of SDRAM on it: Priceless

    For everything else, there's, Hey! Why would I pay more than a grand for a PCI bandwidth capped solid state drive when I can fill my memory slots and use RAMDrive at DDR bandwidth?

    --
    Here come da fudge!
  11. no sense in that by zatz · · Score: 3, Insightful

    First, if this is a workstation for one person, not an application server, then you are not likely to feel performance is acceptable when paging does happen, regardless of the device where swap resides. Just because your OS installer insists that you allocate swap space doesn't mean you should use it often.

    Second, transfer rates have increased about ten-fold since that drive was manufactured. (Access times haven't.) While it is ideal to have swap space on its own spindle and controller, it doesn't make much sense to optimize details like that but use such a slow disk.

    Just make a swap file on your system disk and forget about it. If the rest of the machine is new, it should have enough physical memory that swap is mostly irrelevant.

    --

    Java: the COBOL of the new millenium.
  12. Absolutely!!!! by OC_Wanderer · · Score: 3, Informative

    From Windows XP back to Windows 95, gurus have suggested a fixed size of 2 or 2.5 times the size of your RAM. I keep it at 3 times, because I have CRS disease and can't remember the exact size. Better safe than sorry, since I have the room.

    Swapping on a separate drive is faster than swapping on the same drive. I've tested that. I also put the "temp" directories on the separate drive, as well as the data directories for my applications. This includeds the mailbox for Outlook Express and the temporary internet files for Internet Explorer.

    There's a big bonus to setting up like this, besides performance. There's less to backup from C: drive!

    [Contrary to popular belief, not all nerds and geeks use OSS.]

    --
    -- There is no spoon. Only fork.
  13. two drives and 1 controller, with striped swap. by Elivs · · Score: 2, Informative
    I have two ide drives and 512M ram. I have the first 512M on each drive as a swap with linux stripping the swap. (See "man 2 swapon", "man swapon", "man 5 fstab" and set the priorities of each partion to be the same) I did this on the assupmtion that the bottleneck is likely to be disks's read/write speed, not the controller.


    Like you I'm also not sure if it makes much difference but my system certainly seems to often be swap limited. I currently have KDE3, several gnome apps, a browsers with 4 windows (20+tabs), 2 virtual desktops, and I often use octave to process high resolution images. Changing from one app to another can cause the machine to swap for a few seconds if I've haven't used the first app in a few hours/days.


    Elivs


    Clearly if I used windows I wouldn't have these problems as I could never leave apps idle for days while doing another task.

    /me Ducks as an "MS wireless mouse" flies towards me...

  14. The HD sounds like a good idea by PurpleFloyd · · Score: 5, Insightful
    As far as using the HD goes, it sounds like a good idea, albiet with some conditions:
    • If you're planning on spending any money on this, it would be better off going towards more RAM.
    • If the drive isn't as fast as your primary HD, it may not be as good a deal as you might think. Remember that the non-DMA access modes used by older IDE drives, can eat up your CPU and thus any performance gain. Of course, this isn't an issue with SCSI if that's what you're using.
    • If you use an app that has its own scratchpad requirements, you might want to put that on the drive rather than your Windows swapfile. Photoshop comes to mind immediately as an example of where this would be a good thing; it might also be good for dumping processed video onto (although if you're doing major video work, you should have a fast, preferably RAID-0, scratchspace, along with more reliable storage).
    As far as a fixed-size swapfile, it should help some in Windows; when you defrag, it will help to keep your swapfile coherent as much as possible. Of course, if the swapfile is the only thing on the drive, it won't matter too much. If you do go for a fixed size file, make sure to make it larger than you ever think you'll need - it sucks to run out of memory when you're doing a lengthy, complex operation. One rule of thumb (not as valid these days) is to set your swap to 2x your physical memory. Another, which I use, is to simply take the most memory you'll ever think you'll use and then add a 50% safety factor. Remember to resize this if you ever start working with really large stuff - high-res video, 3000 x 3000 pixel Photoshop images, etc.

    Finally, remember that idealy, you never want to hit swap at all. If you're experiencing problems with thrashing, you should probably either pare down your system (do you really need to run that IM program all the time? all those systray utilities you never use?) or simply bite the bullet and get more RAM. Even the fastest hard drive can't touch RAM for speed, and seeing your system hit the pagefile for routine tasks means it's time to put a new stick of RAM into the beast.

    --

    That's it. I'm no longer part of Team Sanity.
  15. One Word Answer: No by silverfuck · · Score: 5, Informative

    Okay, so this is too late for all but the most sad of slashdotters to read it, but here goes:

    If the drive is 2GB, then don't be so sure that it is fast - it may have been when it was bought, but that was 6 or so years ago at least. I would be very suprised indeed to see more than 4-5MB/s sustained read and 2-3 write; there have been a lot of advances in the last few years.

    My current setup (1GB physical RAM) has 2GB set aside for each of Win2k and Linux in seperate partitions right in the middle (this will speed up average access times as the heads will have the least far to travel on average from any random point over the platters) of the raid array (and hench middle of both disks, as it is RAID-0), which I know to be fast - benchmarking has pegged it at greater than 110MB/s sustained. Windows will hit the swapfile no matter what (just try setting the swap to 0, even on a well-heeled system, and watch it complain at bootup/logon), so it gets 512MB to play with just at bootup and can go all the way to the end of it's swap partition if it wants. Linux, well, that's another story (currently support for the raid array is patchy, so not running linux - the partitions are still there, though, waiting for filsystems!), but as everybody knows, linux is very aggressive about swapping stuff out and using physical RAM as a disk cache, so again I expect it to hit the swapfile after a few days (hours?) running, but be perfectly happy with 2GB.

    --
    You know you've been IMing too long when you almost say 'lol' out loud to a non-geeky friend...
  16. Performance considerations by jcasey · · Score: 2, Informative

    If thrashing is causing degradation, I would seriously consider increasing RAM before improving on the swap drive.

    Check the performance specs for that 2gig drive first. If you are connecting an older, slower drive, you may actually worsen performance. For best performance, use a drive that can supports whatever performance features your mobo offers ( UDMA-66, Serial ATA, etc... )

    IF using Windows 2000/XP you can spread your page file accross multiple hard drives.

    --
    X
  17. Putting swap in a RAM disk makes no sense by mlq · · Score: 4, Informative

    Putting swap in a RAM disk makes no sense what-so-ever.

    1. Re:Putting swap in a RAM disk makes no sense by Strange+Ranger · · Score: 2, Informative

      Parent is not informative. Provocative maybe. In order to be informative, the parent's statement needs a supporting explanation, including what OS.

      RAM disks are fast, Windows requires swap no matter your physical RAM size, so why not put it on a RAM disk?

      What are us dummies missing mlq? Please elaborate.

      --

      Operator, give me the number for 911!
  18. Yes, definitely by BoogieChile · · Score: 2, Insightful

    I've always gone for the extra channels when I'm buying a motherboard. Windows and apps live on one drive, swap/temp files and data on the other.

    Real world experience - Rally Championship 2000 - swap file on the same drive as the game - loading times were long - 30 seconds or more. The indicator bar would move for a bit, stop for a bit, move for a bit, stop for a bit...

    Change the swap file to the other drive and the level loading time went away. 18 seconds.

    And the progress indicator keeps moving all the way with no pauses.

    Think of it as the difference between having to do everything one handed (read this bit off the drive, track all the way across the platter to the swap file, write that bit there, track all the way back across the platter for the nexct bit of reading, etc, etc, etc), and having two hands (read with the right, write with the left)

  19. There's no pat answer... by pointbeing · · Score: 2, Insightful
    Apparently we're dealing with Windows, so I'll chime in ;-)

    Depends on your PC and what you do with it. Putting the swapfile on the outside edge of the fastest disk that does *not* have Windows on it is generally the best idea. If you're concerned about dissimilar PIO or UDMA transfer rates, if your IDE controller supports multiple media transfer rates (most IDE controllers built after about 1998 do) you don't have anything to worry about. There's no reason I can think of to have multiple pagefiles on a Windows machine unless it's a server or you're heavily into A/V.

    Re size of the paging file: A static swapfile is always going to perform better than a dynamic one - provided the static file is big enough. Here's whatcha do -

    Use Performance Monitor to measure swapfile use over a week or two. You'll be able to tell exactly how much paging file you need from that. Take a couple hundred MB onto that number just for grins and make it a static pagefile.

    Paging to disk is always slower than using real memory - but some applications (one of them being Internet Explorer) *require* a swapfile. My XP box is a dual processor 1GHz machine with 384mb of memory. It's usually just used for surfing the web and a bit of word processing, but I've never seen more than about 10% of its 768mb static pagefile in use.

    Hope this helps -

    --
    we see things not as as they are, but as we are.
    -- anais nin