Slashdot Mirror


Do Modern PCs Need Swap Space?

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?

17 of 37 comments (clear)

  1. No by Anonymous Coward · · Score: 2, Informative

    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.

  2. Just in Case by Bryan+Andersen · · Score: 3, Interesting

    I'd say keep a swap space just incase you run out of memory. Linux dosen't handle running out of memory gracefully.

    1. Re:Just in Case by larien · · Score: 2
      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?
    2. Re:Just in Case by J'raxis · · Score: 3, Funny

      % kill -9 $RANDOM

      Thatll fix your problem, eventually.

    3. Re:Just in Case by larien · · Score: 2

      Especially if $RANDOM==1, although I don't know if that qualifies as 'fixing' the problem!

    4. Re:Just in Case by Mignon · · Score: 2

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

    5. Re:Just in Case by J'raxis · · Score: 2

      Heh, out of control Netscapes. Most of the workstations at my universitys 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.

  3. You've got to be kidding me by clark625 · · Score: 2

    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"?

    --
    Long, cute, or funny Sigs are just another form of over compensation, used by geeks, nerdz, etc.
  4. Yes, keep swap space by Controlio · · Score: 3, Informative

    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.

  5. Use a ram drive to find out. by stienman · · Score: 2

    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

  6. Just as a comparison, corporate UNIX servers... by AtariDatacenter · · Score: 3, Informative

    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.

  7. Re:Depends on your geek aptitude by chill · · Score: 2

    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.

    --
    Learning HOW to think is more important than learning WHAT to think.
  8. What's the difference? by PD · · Score: 3, Interesting

    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?

    1. Re:What's the difference? by PD · · Score: 2

      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.

  9. Allocated vs. Reserved Memory Space... by trims · · Score: 3, Informative

    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

    --
    There are always four sides to every story: your side, their side, the truth, and what really happened.
  10. Re:Here's an idea: by spudnic · · Score: 2

    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?

    --
    load "linux",8,1
  11. Yes by danpbrowning · · Score: 2

    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.

    --
    Daniel