Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×
Hardware

Do Modern PCs Need Swap Space? 37

chill asks: "The price of RAM has plummeted lately. On Price Watch I've seen 256 Mb PC-133 DIMMs for as little as $16 + shipping. Now that every machine I own has 768 Mb - 1.5 Gb of RAM, the question arises -- do I -need- swap space? I'm not talking about running large databases or enterprise machines, but the home PC/Workstation -- word processing, spreadsheets, presentations, some minor coding and that sort of thing." With memory so cheap, there is reason to wonder about the necessity of swap. Does a machine with 1-2G of RAM really NEED swap space if they are not running intensive software? Have any of you seen machines in production with the swap explicitly turned off?
This discussion has been archived. No new comments can be posted.

Do Modern PCs Need Swap Space?

Comments Filter:
  • No (Score:2, Informative)

    by Anonymous Coward
    You don't really need swap space, but it might still be useful. If you have a lot of programs open, and are not using them, they will be swapped out and more RAM will be available for disk cache and buffers (all of the filenames on my computer are cached right now, so I can search the entire filesystem in a few seconds). Of course, when you try to switch to one of the swapped-out programs, it might take a few seconds to load, so it's a trade-off.
  • Just in Case (Score:3, Interesting)

    by Bryan Andersen ( 16514 ) on Saturday September 15, 2001 @02:16PM (#2303387) Homepage
    I'd say keep a swap space just incase you run out of memory. Linux dosen't handle running out of memory gracefully.
    • Linux dosen't handle running out of memory gracefully.
      Does anything? I've seen Solaris machines out of memory (and swap, actually) where I couldn't do anything to fix them as I couldn't track down the process(es) using all the RAM as I couldn't even start a program like top!

      Like he said, it's good to have that "comfort factor", even if you never use it. However, there are some uses for swap like:

      • Crash dumps; some OS's (eg, Solaris) put kernel dumps in the swap space. Reasoning being, if you don't want to save them, it gets cleared up quickly after boot
      • tmpfs. Again, Solaris uses virtual memory (ie, RAM + swap) as tmpfs and mounts this on /tmp (and /var/run on Solaris 8). As tmpfs is faster than normal disk (there's less need for consistency), it can be faster than using a ufs volume.
      Unless you have a very good reason not to have swap, enable it. As another poster says, will you really miss 512MB in a 50+ GB hard drive?
      • % kill -9 $RANDOM

        Thatll fix your problem, eventually.
        • Especially if $RANDOM==1, although I don't know if that qualifies as 'fixing' the problem!
        • I've salvaged an otherwise hosed Linux machine that had run out of RAM from a bash prompt. It's been a while, but I used the fact that while I couldn't run new programs like top, or even ls, I could still use file-name completion at the prompt. I recall I used this in the /proc directory to get bash to tell me all the PIDs, then for each suspect (it was an out of control netscape in this case) I did something like "cat /proc/123/cmdline", which I guess did work. (I don't know why cat worked but ls didn't. As I said, details are sketchy now.)
          • Heh, out of control Netscapes. Most of the workstations at my universitys [neu.edu] lab have at least three of those going at it. People never realize that the proc is still running even though the window went squish.
    • But you're just increasing the threshold, not really solving a problem. Imagine you have a machine with 256MB of RAM and 256MB of swap. If you have a memory leak that eats up 256MB, then it's probably eventually going to eat up all 512MB. You still end up having to face the problem.

      Sure, it helps a little (and I still use swap space on my Linux boxes too), but it's really just a delay.

  • You've never needed swap space. It's never been a required item. But, if you don't have it, it's YOSF (Your Own Stupid Fault) if you run out of memory. Besides, there's something to be said about a computer with more than 512Mb of RAM that gets the kernel message "Out of memory" or "insufficient memory". In today's world of ever cheaper hard drives, why not just give in and allow for a Gb of swap "just in case"?

  • Harddrives are cheap too. Just set up a good 256 MB of swap space, it's not like you have an 800 MB drive in your workstation with 1.5 GB of RAM. (Do you?)

  • Maybe not too much (256 Mb should be fine). But Linux really does not deal well with running out of memory; basically, even if the process that is using the memory dies, your machine is pretty much unusable - reboot is required, if the kernel doesn't do it for you. :)

    It's better to have it and never need it than need it and not have it. One server here has 768 megs of PC133 and 2.5 Gigs of swap. Even workstations with 512 Mb of memory get at least 256 megs of it.

    Memory is cheap, but so are disks. I would always have some amount of swap around just in case, unless you really really really need the space.
    • If you're going to have any swap space at all, you'll need to have at least as much as your current physical RAM - in fact, most people would recommend running with twice that.

      This is becuase the 2.4 kernel likes to keep a copy of it's entire working set in swap. It's terribly inefficient, but it's not likely to change before the 2.5.x series.
      • If you're going to have any swap space at all, you'll need to have at least as much as your current physical RAM - in fact, most people would recommend running with twice that.

        The poster didn't say Linux, just a PC. What if he wants to use FreeBSD or Solaris?
  • I personally turned off swap since I've been running the same system for so long that the size of my swap is now inadequate compared to my 3/4 gig of ram. At some point Linux had serious problems since it had an overcommit type of handling of swap and at I found that the swap would slowly fill up and then the kernel would panic even though I had lots of ram.

    t.

  • RAM disk for your swap file. teehee
    • RAM disk for your swap file.

      Im liking that idea...Anyone know of any hard drive emulating type devices, where I could just throw in a few sticks of the unused ram I have around here? (made a bulk ram purchase and ran of of slots/boxes for the ram) Then it would make at least an excellently fast/expandable swap drive, or i guess a volatile standard ramdisk (wouldnt be to hard to load the OS onto it automatically at each boot).
      • I've tried to work this out in my head, but the numbers just don't work out. It seems to defeat the purpose.

        Things are swapped out to free available ram either because a process has been sitting around for awhile and doesn't need to occupy the space that could be used for something else, or because the loaded programs occupy more memory than your physical ram can hold.

        If you have the memory, and the slots (this is my problem lately... amazing) why not just use it for main ram?
  • Yes, keep swap space (Score:3, Informative)

    by Controlio ( 78666 ) on Saturday September 15, 2001 @06:29PM (#2303988)
    Swap space is more of a secondary precaution. No one NEEDS it in a RAM-intensive PC, but it's just a precaution in case you DO fill up your RAM.

    The issue here isn't necessarilly what you have open... it's more of an issue of leakage. Memory leaks plague even the best of computers. Two programs I use frequently, Photoshop and SBNews, have vicious memory leaks in them. I have 256M RAM in my P3-500 box (yeah yeah I know), and after a good session in either one of those programs, every program I open will swap like crazy until I reboot. Hell, even after a week-and-a-half of not rebooting Windows, the system will start swapping due to many little memory leaks that exist everywhere, and not just in programs... but the OS as well.

    So the swap file is more of a precaution than anything. There's no need to go make a 3G swap file for a computer with 1G of RAM... but it is a very good idea to keep at least a small swap file around for those unexpected occurrences where you might need it. Hell, make a sub-40M swap file if space is tight. It's better than watching your system tie a rope around its neck and jump off your desk in the middle of a very important project.

    So do you need it? No. Is it wise? Of course. If space is of the essence, make a tiny one... just make sure it's around for redundancy purposes. Chances are that once you find out you should have had one, you won't be in the best of moods as that project you just spent the last three hours on gets sucked into the void.
  • If you want to see if you need a swap space in your normal day to day usage, make a ram drive and mount the swap space there.

    Under win9x, there is a ramdrive system file that will do the job in config.sys. There are similar programs for 2k and xp. If you find that you never see an out of memory error then you've solved your problem,a nd your computer goes a teeny bit faster.

    Modern OS's are pretty smart about it anyway, while they may grab a large chunk of the HD for a swap space, it's mainly to get a contiguous spot of drive so access is faster, and it hardly uses any of it. When it does, it puts little used memory spots in it, such as schedular tasks, which are checked once a minute, first, before it starts putting larger tasks, such as MS word docs, into it.

    Lastly, code bloat is followed by data bloat. A program which, if careful, would need only 5MB of ram may well absorb 5x or more just because the programmers know there is always going to be enough swap space. You may find, with the ram drive, that you still run out of memory because apps are taking much more than you think they would. Word, when working on a 5k doc may well use more than 50MB, then save it back down to 5k when you're done editing. So, in short, you may be fine, but check your system utilities for a memory usage meter. It should show you physical memory useg, swap space used, swap file size, etc. See what apps need the most memory. Also remember that on days like tuesday when one might open 30 windows of their browser that you might run out of space.

    -Adam
  • by AtariDatacenter ( 31657 ) on Saturday September 15, 2001 @10:53PM (#2304489)
    Just wanted to give you something to compare to. I administrate and have administrated quite a number of UNIX servers. The largest having 24 CPUs and 24GB of RAM. (Smallest is 1 CPU, 64mb of RAM.)

    In the corporate UNIX world, you still want a swap device to act (depending on OS flavor) as your primary dump device. So when the OS panics, it has a place to write the kernel to for later analysis.

    As well, having a swap device can give you some extra breathing room. If you've got alarms to measure your memory utilization, that's great, but if you have a good array of swap devices to rely on, you're in even better shape because you can take a transient spike in memory usage.

    Say, for instance, on Solaris, where /tmp is a memory based filesystem. A user decides to put lots of log files and binaries in there. Or, the usual rampant unpredicted memory bloat of an application. Or more processes of a memory intensive application running simultaneous (without the benefit of shared memory).

    To translate that over into the PC world, I'd say a swap device would be a good buffer just in case you try to do something with a program that decides it needs lots and lots of memory to do the task. (Or you've gotten so comfortable, you're running 50 applications at once.)

    Necessary? No.
  • Do you compile your own software or rely on others to do so for you? Linking _large_ applications will frequently take massive amounts of memory.

    But most people out there haven't compiled anything larger than the linux kernel which has been careful about their namespaces.

    Hopefully the GCC crew will get their act together and do more block and global optimizations. The graph setup for those will be immense.

    As networking speeds increase, you'll need more and more memory to buffer connections. TCP reliability isn't free. IPv6 jumbograms may exacermate the requirement.

    .TROLL
    If you need to ask, you're not bright enough to do anything complex anyway -- say a crashdump when you screw up doing kernel devel.
    • What I didn't post in the "Ask Slashdot" question was details about the setup I was working with.

      Yes, I compile quite a few of my own apps -- including entire systems using http://www.linuxfromscratch.org for my main system. Very educational.

      More details: Workstations only, not servers. I have set up several ThinkNIC systems to boot via ethernet/NFS. They have 256 MB of RAM, and a 4 Mb flash disk that is used for caching certain temporary files. The rest of the setup mounts all the partitions via NFS -- except swap. While swap CAN be done via NFS, I am trying to work around it altogether.

      The applications running on the systems are not normally memory hogs. This is a classroom setup, so students logon/logoff hourly and the workstations are rebooted daily. This means I have less to worry about with minor memory leaks building up over time.

      The network is switched, fast ethernet and all apps run locally, using the RAM and CPU of the NIC.
  • It's your decision to weather you need swap.... on rare occassions, I have used more than 10% of my swap space on some of my boxes. I once compiled perl, it wanted a huge amount of swap space online to do the compile. You don't NEED it, but its not a bad idea. I have noticed minor performance diffrences between a system with the sawp off, and a system with the swap on, I don't remember the diffrences, except that the memory usage was more erratic on the one w/o swap space.
  • I've notice that Both Photoshop 6.0 and Photoshop Elements won't run without 512mb of swap no matter how much RAM you have. And here you have me who locks my SWAPfile at 256 MB on it's own partition. It's getting to be a real pain. Really, even with the memory hog that is Windows, Doyou really need 512MB of Swap when you already have that amount in RAM? Most files generated don't get even 1/2 as big as that unless youre making an Ad for a BUS full sized.
    • This is generally true except for the fact that Adobe products, and in fact just about every graphics program I've ever seen (INCLUDING the vector-based ones) use bitmap-based drop shadows.

      I won't get into the math of it, but suffice it to say that it's computationally intensive to do drop shadows of a large scale. This can be sped up by taking more space.

  • by PD ( 9577 ) <slashdotlinux@pdrap.org> on Sunday September 16, 2001 @08:36PM (#2307233) Homepage Journal
    Numerous people here have suggested that you need swap to prevent the problem of running out of memory.

    Now, for the sake of argument, let's pretend we have two machines, identical in every way, except that one machine has 320 MB of physical RAM and no swap, and the other machine has 64 MB of RAM and 256MB of swap.

    Are people suggesting that the machine with 64 MB RAM and 256 MB of swap can handle more than the other machine? If not, then why should there be any need to mess with swap if you've got a gig of RAM to play with?

    • No, no-one is saying it can handle more.

      Imagine your two machines are arranged like this: one has 320Mb physical and no swap, and the other has 320Mb and 256Mb swap.

      We suggest that the latter can handle memory leaks etc. a little better than the former; and, most significanlty, that given how cheap disk space are, and the huge size of disks in modern PCs, the cost diffence between the two works out at almost nothing.
      • Sure, I agree with that. But the article is about the cheap prices of RAM, and why not just do away with swap. On my machine I've got 320MB of RAM and 512 MB of swap. I never run out of memory. If I put a gig of RAM on my box, then I shouldn't need swap, because that's more capacity than I currently have.
  • by trims ( 10010 ) on Sunday September 16, 2001 @09:10PM (#2307314) Homepage

    Something that no one has noted about, and which is the primary reason to continue to have swap these days, is the difference in behavior between the reserved and allocated memory space of a process.

    As a previous poster pointed out, from a system standpoint, there is no difference between having a machine with 64MB RAM/256MB swap and one with 320MB RAM/no swap. If both machines have 320MB of memory being actively used by a processes, the next call to allocate memory will result in an "no available memory" error.

    What people are missing is that when a process starts up, it reserves a chunk of memory for use. Now, while the process runs, it allocates (or uses) a this reserved memory. In some cases, it exceeds the reserved amount, in which case the kernel allocates more of it. But in many applications, the allocated memory never surpasses the initial reserved amount. But the reserved amount is what counts for calculation of available free memory by the kernel. Thus, for most processes, there exists a chunk of memory that isn't going to be used by that process, but cannot be used by any other process. If you have a swap space, this chunk is "swapped" out (in reality, nothing is written, just the address space is allocated in the swap space).

    Look at this scenario:

    Process X reserves 100MB of memory, but only ever allocates 50MB. Process Y reserves 100MB of memory, and allocates the full 100MB.

    For a machine that has no swap space, the user can run an equal number of X as they could Y. All processes would run at full speed (no degredation due to swapping).

    For a machine with swap space equal to the amount of RAM, you can still run the same number of X as Y. However, all X run at full speed, while half of Y must swap in and out. Thus, performance is considerably slower.

    What this means is that for a fixed amount of RAM, more of your processes can run at full speed if you have some swap. In addition, since extra RAM is freed up by using swap for the "reserved" memory, it is available for buffering, etc.

    Bottom line: having some swap is good. Look at the documentation for your applications to estimate how much you need, but these days, I would consider the minimum to be 256MB swap for any machine with at least 128MB of RAM.

    -Erik

    • This is an excellent post and also details the reasons that many memory management systems do a "on write" type of allocation. For instance, if you allocate 1GB of memory, and then only actually write to 1kB of it, then you will have only used one page of memory (typically 4kB). This is completely independent of swap space and does not actually consume 1GB of memory.

      btw, the whole thing about Solaris and tmpfs being mounted in RAM is IMHO not a good thing to do. What you should instead rely on is the O/S's ability to do proper file caching. If you create a tempory file, it doesn't need to be flushed to disk right away. If you then delete it, it'll never need to be written to disk.

      Also, creating a 1GB swap space is not a good thing to do if you're a developer. e.g., if the gcc people didn't have tons of swap space then they would have instantly noticed the problem where compiling certain things consumes massive quantities of ram.(or they would have at least been notified very quickly)

      "Hey guys, I just added this cool new feature!"
      g++ *.cpp
      panic: out of memory.

      t.

  • With swap at least if you run out of RAM things get slower first.

    I figure it's better to go slower and slower till you can afford to get more RAM, than to one moment things seem to be fine then the next WHAM, BAM, out of RAM! At 266MHz too :).

    OK so it's not that gradual a degradation, but hey things continue working while you go around killing those netscapes...

  • Believe it or not, I've run my Win98 machine without a swap file and it does just fine. I turn it off every now and then to defragment the swap file, and I'll run with it that way afterward (as opposed to rebooting again). I have 128MB of RAM, and I've opened up Word 97, multiple IE 5.5 windows, and the connection software for my Psion before the machine begins to complain. I usually leave the swap turned on, though, as I believe Windows caches closed programs in memory for faster opening, and I kind of like being able to take advantage of that feature.
  • It's good to have anyway so your OS can swap out stuff that isn't used at all but is loaded anyway -- and make more room for stuff that is used. i.e., swap out that screen saver code for more room for a GIMP cache or what have you.

And it should be the law: If you use the word `paradigm' without knowing what the dictionary says it means, you go to jail. No exceptions. -- David Jones

Working...