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.
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.
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.
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.
Three Step Plan:
1. Take over the world.
2. Get a lot of cookies.
3. Eat the cookies.
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.