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?
No (Score:2, Informative)
Just in Case (Score:3, Interesting)
Re:Just in Case (Score:2)
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:
Re:Just in Case (Score:3, Funny)
Thatll fix your problem, eventually.
Re:Just in Case (Score:2)
Re:Just in Case (Score:2)
Re:Just in Case (Score:2)
Re:Just in Case (Score:1)
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 got to be kidding me (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"?
Might as well use swap (Score:1)
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?)
Yes, do it. (Score:1)
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.
Re:Yes, do it. (Score:1)
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.
Re:Yes, do it. (Score:1)
The poster didn't say Linux, just a PC. What if he wants to use FreeBSD or Solaris?
Having swap can be worse then no swap. (Score:1)
t.
Re:Having swap can be worse then no swap. (Score:1)
"Well then don't do that."
A big fuck you to the anomoyous dipshits like you. There are some of us who have actually have been around long enough to know the reasons that virtual memory came into existence in the first place. But for the mentally challenged such as yourself, I will explain it to you using small words so that you may follow along.
A long time ago there was not enough memory on computers. So they decided to save portions of memory to disk and "swap" between them. So now lets jump way into the future when computer systems with terabytes of RAM are common, will you still need swap to run your simple email program? Probably not. So that means at some point in time swap space became unnecessary. For me that has happened already. So why would I continue to use a temporary workaround that has implementation problems?
btw, swap space isn't the answer to the "I want to run programs that use a lot of memory" question since swap space is usually allocated before hand and is static in size. So there will always be programs that are too big for your system.
t.
Here's an idea: (Score:1)
Re:Here's an idea: (Score:1)
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).
Re:Here's an idea: (Score:2)
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)
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.
Use a ram drive to find out. (Score:2)
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 as a comparison, corporate UNIX servers... (Score:3, Informative)
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.
Depends on your geek aptitude (Score:1)
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.
Re:Depends on your geek aptitude (Score:2)
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.
I can't come up with a good subject (Score:1)
Also if you use Photoshop.. (Score:1)
Re:Also if you use Photoshop.. (Score:1, Informative)
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.
What's the difference? (Score:3, Interesting)
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?
Re:What's the difference? (Score:1)
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.
Re:What's the difference? (Score:2)
Allocated vs. Reserved Memory Space... (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
Re:Allocated vs. Reserved Memory Space... (Score:1)
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.
Swap= gradual degradation (Score:1)
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...
No Swap -- Runs Fine (Score:1)
Yes (Score:2)