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?
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.
I'd say keep a swap space just incase you run out of memory. Linux dosen't handle running out of memory gracefully.
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.
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?)
One future, two choices. Oppose them or let them destroy us.
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.
t.
RAM disk for your swap file. teehee
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
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.)
/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).
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
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.
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.
Sometimes I wish I was a plumber, then I'd know how to deal with other people's shit.
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?
If tits were wings it'd be flying around.
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.
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.
Daniel