How Much Virtual Memory is Enough?
whitroth asks: "Ten years ago, Received Wisdom said that virtual memory should be, on the average, two to two-and-a-half times real memory. In these days, where 2G RAM is not unusual, and many times is not that uncommon, is this unreasonable? What's the sense of the community as to what is a reasonable size for swap these days?"
lots
Under Windows it seems it'll swap out whether the free RAM is needed or not, no matter what (there's a registry setting to change this though). Under Linux, you won't swap much anyway unless you need it.
I run a Core Duo laptop with 1GB of RAM and have never swapped out in Linux, no matter what I was doing.
"You can either have software quality or you can have pointer arithmetic, but you cannot have both at the same time."
My rule of thumb these days is 1.5x RAM, unless you're at 2GB, in which case I go with 2GB swap as well. This is for *gasp* Windows, though.
Back when I had 512MB of memory, I had a 512MB swap partition, but I noticed that I never came close to using all of it.
When I got my new machine with 1G, I never bothered to make one at all, and I've never had a problem with it. If I do ever find myself in a situation where I need some swap space, I could always just create a swap file. It's a lot more convinient because it wouldn't have to be a fixed size, doesn't take up space when I don't need it, and I have one less partition
Especially if you have 2G or more, I don't see a real reason to use swap
640k should be enough for anybody.
I just make mine equal to my ram these days.
slashdot: where everyone yells sarcastic metaphors to themselves to understand the issue
2X physical memory for under 2G RAM
2G swap for up to 8G RAM
+1G swap for every 4G RAM beyond that
I disable virtual memory on computers with more than 1GB of ram unless the user is going to be manipulating large images. Never had a problem yet.
It depends on what you want to use. If you don't care about Hibernate mode, then you probably wouldn't need any swap (or much). However, if you want to use that mode, you need to have at least the same amount of swap space as memory. I've tried it with less, and it wouldn't even attempt to go to sleep (for obvious reasons - swap is used to store what's currently in RAM when going into hibernate mode).
If you use LVM (which you should, it's great!), you can expand and contract your swap partition as needed.
If you really want to know, I use 1-2 GB swap with 1GB ram and the same for 512MB ram.
However, you might just do what I do and try out different values to figure out what works. If you're talking about a linux system a real-time memory/swap usage graph can be added to most window managers so that you can see what's happening. You could also try to estimate usages based on what the machine is expected to do.
-Tim Louden
On the other hand, on my laptop with 256MB, I have (iirc) 1GB swap, and on my laptop with but 96MB ram, I have (again, iirc) 25% of my disk in swap. (But then, the disk is only 2GB anyway...)
So do as much as you can spare. Sure, you may never use it, but hd space is cheap these days.
After some poking around in the system, we found that we were in the topsy-turvy situation of having the OS running in RAM and all the applications running in the swap file on the HD!
As soon as he got rid of the silly voices and other frippery (cool, though!), it went back to behaving in a more sensible manner.
I think RAM prices have fallen faster than HD speeds have risen, so it has more impact than it used to to have applications requiring swap file space.
I use 4x750 GB hard drives (RAID), purely for virtual memory. It increases the speed on the RAM preprocessing directive, but demodulates the core processing utility monitor. I find it to be a good setup, especially for running Naibed Linux.
Stupidity is like nuclear power, it can be used for good or evil. And you don't want to get any on you.
According to MS, it's 1.5 times the total RAM. I assume you're asking because you're trying to avoid a fragmented page file. While the benefits of an unfragmented page file are dubious at best (since it will be randomly accessing different parts of the page file), it's better to err on the side of caution: If you have 2GB of memory, you likely have an equally compensating-for-something hard drive, so you probably won't miss 3GB of space, or even 4. It's better to waste a little space than have Windows run out of Virtual Memory. Otherwise, just let it do its dynamic page file adjustment thing.
If you're asking about creating a swap partition for Linux then 1.5X is also recommended. Just be generous, unless -- for some reason -- you've got 2GB of RAM and a 50 meg hard drive. Too much is always better than not enough.
https://www.eff.org/https-everywhere
One of the real advantages of using swap isn't to avoid memory exhaustion at all; by moving infrequently accessed pages from memory you make more room for the disk cache, thereby possibly improving overall system performance by reducing hard drive reads.
I still use a small multiplier, typically 2-3x physical RAM, for swap partition sizes on Solaris, Linux, xBSD, etc.
Systems typically are paging less now that we have multiple gigs of RAM per server, but if something goes wrong, the disk is so cheap that having the overhead installed and ready to use is fine. Having a live, active safety margin is just good sytem planner sense.
If you skimp on OS hard disks so much that 2-3x physical RAM is an excessive chunk out of the hard disks, then you're doing something wrong.
I'm not sure about any nongaming applications, but some games require that you have a swap file regardless if you need it or not. This will usually be indicated by an error message stating this fact or some other oddball message. Of course this is an easy fix, just start using a swap file again
Videogames made me kill people...I also eat mushrooms to grow bigger.
just let windows set it for you.
The conventional wisdom was (1) for Windows and (2) when memory was a lot more expensive. In general, you never want to use virtual memory. You absolutely never want to need it. This has been true since the days that swapping was done to fixed head drums. You do not want to rely upon it while you are doing anything important. Get enough real memory, and set the virtual memory to whatever makes sense for your usage pattern.
Here is my rule and is founded on years of managing Unix/Linux systems professionally.
Never, ever use less than 1x physical RAM. Some operating systems use swap space on disk to through core dumps on a crash (Digital Unix... err Tru64 is one). Without a single swap space big enough to hold a physical RAM dump you might be SOL when it comes time for the vendor to diagnose. (In the case of Tru64 you're already SOL because they can't diagnose anything.)
2x physical, which is what I was always told as the recommended amount, is just ludicrous. It was then and it is even more so now.
So my rule is, first, know how much memory your machine uses under heavy load but not when the system is ailing because of an app leaking memory or some other out-of-the-norm issue. Now add that, plus a reasonable margin of error (I like 50%), to your physical and you have a good number. Remember what I said above about always having at least physical? It's very likely (though I've never run into this issue) that a system that wants to dump core to swap space may very well want to dump what's in active swap along with it. As far as the OS is concerned this memory space can be important (though, in the case of a system panic it seems impossible that the offending code would be sitting in swap space).
It should go without saying but the amount of paging space actually used should always be kept to a negligant amount. If this gets out-of-hand you need to add more RAM.
Finally, it's better to err on the side of too much than too little.
Mod me up, Baby! You know that's at least as funny as the parent post!!
Let's create a ramdisk!
I typically will use no less that 2g for swaps, however, as the more memory is added to the system, the less swap I use.
It is never less than 1 - 1.5x the ram size. You NEED to have enough space to dump the entire contents of memory out in the event of a panic (for tracing) and then anything else that is still resident in swap at the time. Start with 2GB and add 1GB per 512MB of memory. You should be sitting safe in most situations.
I let the operating system increase and decrease as it sees fit. It has a better picture of the situation than I do. I use Windows XP, though. Is this possible in Linux? I find it strange that someone hasn't mentioned this already. Usually the latest beta of Firefox, Minefield, triggers the OS to grab more.
Linux has futzed with this a lot (and lets the user tweak VM behavior a lot, but /proc/sys/vm/swappiness goes a long way...), both linux and Windows will swap well ahead of not having free memory (for good reason). Just wanted to go into detail because I keep seeing people complain that they see swap used in linux or windows when they still have free memory, not realizing this isn't a bad thing generally.
There are generally two strategies:
-The common-sense one where you swap when you run out of memory. This makes a lot of practical sense on systems with limited write cycles (flash based swap, though you really never ever should do that anyway), and systems that want to spin down drives to conserve power for battery conservation. Performance wise (this may surprise people who haven't spent time thinking about it), this can often be bad. Avoiding swapping is generally only good on systems where resource utilization is carefully managed and you know it won't swap ever (the IO operations of unneeded can interfere with the productive activity of a constantly busy system). This is actually a vast minority of systems in the world (no matter how l33t one may think themselves, they most certainly don't have a usage pattern that would be impacted by the extraneous IO operations of occasional write to swap.
-Pre-emptive swapping. When the IO subsystem is idle and the system can afford to copy memory to swap area, it does so (depending on criteria). Generally speaking it will select memory not accessed much and write it to disk, but leave the memory copy in place if the physical memory is not immediately needed. A fair amount of swap used in an apparently underutilized system is duplicated in physical memory and swap space. The benefit here is that if the process reads back that memory, it doesn't incur any penalty in reading it back despite it being also in swap (the system may make certain decisions on what is the best swap candidate and write to disk different data). The benefit of writing this stuff to swap even when not needed is clear when an application comes along that allocs more memory than the system has free in physical space. In the first strategy, this means the malloc blocks while data is written to disk, and the new application starting or needing a lot of data is severely impacted. In the pre-emptive swap case, system notices the condition, knows what memory it has a backup in swap of that hasn't been used lately, and can free that memory and satisfy the malloc pretty much instantly.
To those who have 1GB of RAM or so it becomes less likely that the system will have to flush memory from physical RAM, but there is a balance to be struck between memory used directly invoked by applications, what the application memory access pattern is, and what ram you can use to buffer filesystem access. If your total application memory allocation is 75%, it still may make sense performance wise to only keep 50% of your physical memory dedicated to the applications, (the other bit relegated to swap), and 50% of the memory to buffer disk I/O.
XML is like violence. If it doesn't solve the problem, use more.
What is this "enough memory" of which you speak?
Oh, wait, virtual memory. I thought you were talking about real memory.
Never mind.
-- Alastair
I think it was one of the Live Journal guys at OScon that said, "If your server starts to swap, you've lost the battle".
With all of our 64bit 4GB of ram minimum hosts floating around, there is no longer a point to having swap -- if you server really is swapping, it's under a huge load and the io is making the problem worse. Let the OS kill a few processes to get it back under control
-- DrZaius - Minister of Sciences and Protector of the Faith
It really does depend.
It depends on what you're doing with the computer, and what hardware resources are available. Out of memory is bad. Very bad. On systems which have oodles of RAM, I tend to give low or no swap; on systems tight on RAM I may give 10x or more the amount of RAM.
Here, "oodles of RAM" and "tight on RAM" are very dependant on what the system's being used for. For a home NAT gateway 64MB may be oodles; for an image processing station, 1GB may be tight (especially when dealing with medium or large format photographs).
My desktop currently has 1GB RAM and 8GB swap, since I work with 100MPixel 16 bit images when I'm not working on hundreds of 14MPixel 16 bit images at the same time.
For me, my systems are highly dependent on what I do with them. Currently my swap space/file is at 0.75GB on a system with 1GB RAM. The only times that I would have encountered problems running out of memory is when dealing with Adobe's memory hogging programs. Since I'm not that big on graphics and video manipulations using those programs, I rarely run out of memory anyway.
However, on my removable hard disks where I do general testing, I set my swap size to none. 1GB physical RAM is more than adequate for my needs.
OP poses wrong question. Virtual Memory is built into the OS and cannot be turned off. What OP means is Paging or Swap File (i.e. simulating memory using HD space). The rest of this reply will ignore this difference.
Very simply, if you use windows and use it heavily (run some intensive tasks or need performance), turning off the page file will give you a nice performance boost.. or rather will not take away from performance.
I have 1GiB of physical memory on my laptop, and reaching the limit in Windows when my paging file was off, posed a challenge (in other words, it worked perfectly well without it)
This is because Windows attempts to use the paging file whenever it can (proactive), unlike Linux, which uses it only when there's no other way (reactive). Depending on the applications you're running, one of the approaches will be better than the other, though from what I've seen, I don't like what Windows does...
Caveat Lector: this might be because I wasn't seeing the slowdowns which might've been caused by reactive approach. I've still yet to formulate an opinion on it - but so far it looks very reasonable.
If using Linux, keep the swap partition and forget about it.
In Windows, the best way to figure out if you need your page file is to load up as many apps as you normally load, maybe a few more - and check the memory usage (don't trust "VM usage" in windows task manager, it doesn't show you what you think it shows you!). If the usage is lower than your physical ram by a [few] hundred MiBs, turn off the page file and don't look back. If it's closer, set the page file to a small size, usually no more than 512MiB. If you set the file, make its size static, so that Windows doesn't try to adjust it all the time (it's too stupid to understand that you want to keep it as small as possible)
Interesting to note that the paging file is not used for hibernation, even though you'd think it were almost tailor-made for that purpose. I've heard that early betas of Windows 2000 woke up from hibernation in a few seconds - I bet they were using the paging file for hibernation then... but I digress
HTH
Did you know that "FTW" ("for the win") is a direct translation of "Sieg Heil"?
I gotta agree with what many have already said... monitor your usage for a while, and then adjust accordingly. I haven't had a swap file in over a year in any of my desktops/workstations (1-2GB of RAM) and with prices of RAM nowadays I don't forsee myself ever needing another swap file again. ... and killing that swap file is sooooo liberating :-)
My strategy generally is to use a file for swap rather than a partition, even in linux. I figure that if memory has to be swapped in from disk, it's already crappy going to disk so the extra overhead doesn't matter much, and I have freedom to adjust it up or down depending on my needs. (This is a desktop/laptop circumnstance). I generally start at 512MB or so, increasing maybe if IO is faster on the drive. I view swap like a rumble strip on a road before a stop sign. With no swap, you don't realize a process leaked memory until it's too late, with swap, while it eats through your swap the performance will degrade and you'll see the end coming ahead of time, and may be able to head it off with a kill. It may be well an good your 4GB of ram is technically capable of handling the same load your 1GB RAM+1GB swap handled in the past, but having some noticable impact when things start going wroing is nice. I realize theoretically there are better approaches, but nothing gets in your face like poor performance and tons of disk accesses.
On a production server or a problematic system where I want support and the OS likes to dump a core to swap, I'll ensure a generous swap partition is available (generally observed active swapx1.5+physical memory size). In this case a file-backed swap may depend on layers of the kernel that are in an invalid state, and a swap partition is more likely to be reliably writable. The only system I would even theoretically hibernate on is my laptop, and I only ever suspend to ram or shutdown completely, so I don't consider my laptop as needing a swap partition of any significant size.
XML is like violence. If it doesn't solve the problem, use more.
"Memory is like an orgasm. It's a lot better if you don't have to fake it." -- Seymour Cray, on virtual memory.
This is even more true today, with memory speeds growing faster than disk speeds. Don't use virtual memory for anything that is actually used more than once. I was recently asked to bump the swap on a 128G machine to 1X; imagine how long it would take to access all that memory only once, let alone multiple passes. That machine has a 1-2G swap. Any process that actively used more than 128G wouldn't finish in the lifetime of the project anyway.
It may make sense to enable a lot of swap if you're running Linux and turn off memory overcommit. This is "unused" memory that's required because many programs only run efficiently with overcommit turned on, and you don't lose performance because the memory is never addressed anyway.
Swap in any case should be based on memory size alone only for special purposes like suspend; otherwise, use the largest image you expect minus physical RAM.
Swap devices are intended to hold long-inactive pages, like those of a stopped process. They are NOT "virtual memory."
Memory usage depends on what YOU are using your computer for and the platform. I have an Apple PowerMac G5 with dual 2.7 GHz PowerPC G5 processors and 2.5 GB of RAM and IT ISN'T ENOUGH! Mac OS X pages out to virtual memory almost every day, because I'm constantly using Mozilla Firefox, Apple's Mail program, Micrsoft Office, OpenOffice (under X11), iTunes, MacTheRipper, HandBrake, Google Earth, VueScan, Preview, Adobe Reader, iCal, AddressBook, iWeb, QuickTime, AOL Instant Messenger, Skype, VLC, DVD2OneX2, Toast 6 Titanium, RBrowser, iPhoto, iMovie, iDVD, and iChat. If you have a Macintosh running under a recent Mac OS X, you'll want as much RAM as possible to avoid paging-out to virtual memory - makes your Mac faster overall.
If the computer has a lot of memory (1GB+) I usually set the swap partition to the same size as the memory. Works great for me.
A machine with 9ms seek times and 4G of swap in use is probably going to be unusable. Everyone seems to over-engineer swap space a little too much, 2x the amount of memory you have isn't a bad rule unless you have a very unusual situation.
There's an old discussion amongst various kernel developers about this issue which, even though it's a couple of years old, is almost certainly going to be more insightful than anything you'll read on slashdot. You'll note that there doesn't seem to be a ready consensus even amongst the folks who know this stuff best, so if you see anyone posting the "correct" answer, call bullshit.
My advice is that you should just do the same thing as some random poster on slashdot who says "these days I set up my swap like blah blah blah" without any explanation or justification.
windows 2000, xp, and server 2003, do not use the swap file for hibernation, they use a file called "hiberfil.sys" in the root of the system volume. it is equal in size to the memory in the computer.
On Larger systems, where the system and applications can be tuned to operate within a performance envelope, I think swap should be eliminated. It's a legacy concept, and will drag down any system if it has to operate in swap actively.
If the system is small and resources are scarce, then swap is needed, but I would still think the best solution would be to get a new system or expand resources to accomodate. Just piling on swap to handle an application that is overrunning RAM is like trying to put out a fire by throwing logs on it.
Personal Note: The fact that large database vendors can recommend 1x to 2x swap to RAM on large systems that have upwards of 256G of RAM is ludicrous.
Me - Professional Computer Geek
Specifically, you could set your swap file to a FIXED SIZE to keep Windows from resizing the swap file, thus theoretically upping performance due to less disk activity.
Today in XP, I set a decent minimum size (1.5GB, to complement my 1.5GB memory... I had 0.5GB at one point and I haven't changed my virtual memory size since then, no real need to.) and then set the maximum as high as it can go, for emergencies (memory leak from hell). 32bit Windows XP allows 3gb maximum size (so it tells me), so that's what I have it set at.
Another old trick that works as well today is, if you have multiple hard drives, move your paging file to the non-Windows drive. So I have my C: drive set to no paging, and D: set to 1536-3072 (Windows recommends 2302 for it, fyi).
Unfortunately I have no clue if it actually produces measurable benefits, and I have no motivation to do benchmarking to see. For most people it's probably just best to leave it be at "System managed size" unless you know what you're doing.
I have 4GB of physical ram (ddr2-6400) and 4gb of swap. There are actually a few reasons for this, YMMV (obviously I think the answer to this question depends on what you do).
I have a lot of things running which, usually, are doing nothing. For instance, apache2, mysql, postfix, and courier-imapd-ssl are always running, but they're rarely actually *doing* anything. (If I get a hit or an email, it's relatively rare as I hardly have very little hosted off of my home box - nevertheless, I do want these running). So I'm happy to let these get swapped out. When I start up matlab, and start dealing with huge datasets, I know it's going to swap most of these out. That's good. It will also swap out some of my matlab data that's loaded but not currently being used (and yes, it's quite possible to have >4gb in your workspace). For me, I have the swap because I need it. Figure out what you need, and you will have the answer to your question.
This depends - see other comments for most situations. However if you have a large Sun, HP, Fujitsu, IBM, etc. with 16+ CPUs and say 2 to 8 Gb per CPU (not uncommon in the big systems), then at minimum you need 3 times the --per CPU-- memory, becuse if one of the CPU's goes bad, the hot swap mechanism is going to use the swap space to keep the processes (at least on some of these systems) for moving them to the other CPU's as it marks the one as bad. You certainly don't need 2 times the total memory, or several hundred Gig. This is assuming the kind of NUMA architechure that I think all of these systems still have.
Generally we just used to use, say, 36 Gig local drives as (mirrored) swap for simplicity. In this environment you are probably on a SAN and people will say to move everything there, and that might be more true now than a year or two ago.
You need to add physical memory until your performance is adequate.
You need to add swap until you have enough. You have enough if you don't run out of (virtual) memory while doing whatever you need to do with the system.
On my main (fast) system, I have a lot of physical memory. I have about 1.5X that much swap set up, because occasionally I load a lot of programs at once.
On a test (slow) system, I have very little physical memory. I have about 10X that much swap set up, because I still need to run programs that allocate a lot of memory, but their working set tends to stay small, so they run ok even when 90% is in swap.
Time flies like an arrow. Fruit flies like a banana.
The size of swap should be large enough to hold the contents of kernel memory when a panic+core dump occurs. Anything larger than that depends on workload.
Many people think that you should save the fastest part of the HD to allocate as swap. But after thinking about it no matter where your swap is on a hard disk it's going to be noticeable when the system pages. what is not noticeable is the perceived difference in human terms of the VM at the outer most of the platter or the innermost. And if your allocating a gig of VM or more you're wasting space for system files or applications files where things like time to boot and application launch speed can be faster. (Along with prefetch data) In Linux you can use riser for your system root to further optimize this since most system application files are small in size. (Along with a small block allocation size.) Also, if you're using a secure VM file you may notice a difference if you move the paging file to a secondary drive with the file allocated at the outermost section. No matter what the system I make a page file. If it needs to be secure you should lock the applications pages to ram memory. I any event when using a disk you're going to notice paging and at that point you'll be waiting anyway... I doubt you'll care or notice at that point the page finsihed 2ms faster or not.
||| I still can't believe Parkay's not butter.
The main purpose of swap memory in a modern computer is to create an alternative to crashing when physical memory is exhausted. Swapping pages out, in the absense of a low memory condition, will probably not yield a significant improvement, and will definitely cause a significant performance penalty when those pages need to be swapped back in. The only time you want to pre-emptively swap is when you are certain a page will never be needed to be retreived quickly, which is a fairly difficult thing to determine. A secondary purpose for swap is for software suspend or hibernate. Sizing your swap to the minimum required for suspend is important, if you want to use this feature. The best arrangement is where the operating system can manage the swap size on its own. However, it really hardly matters, as you should never have more active pages than the amount of physical memory on the system. If this happens to you, the solution is to get more RAM, not more swap.
On Linux servers I typically don't give more than 2 gigs, no matter what the memory. I even have a 56 gig box with only a 2 gig swap. The rationale is that swap is slow. If I get to the point that I need to swap 2 gigs on a regular basis, it means I need more memory. If you are maxing out your swap under Linux, don't increase your swap, get more memory! A server that is swapping consistently is thrashing...give the lil' fella a break...
Free the Swappie!
(on the flip side, a really old box can benifit from a larger swap since it may not have the memory on hand to load a modern Linux desktop and such completely in memory...but as above, more real memory would be better if its an option)
512 MB ought to be enough for anybody... oh wait
64 megabytes. Oh, and according to top, I have 0 pageouts.
Mac OS X 10.4 w/ 1GB RAM if any were wondering...
Sure when you had 128MB of ram, and you had a 256MB swap.
But dude, my next box will have two GIGABYTES of RAM!
Every one of your usage options assumes you'll run out of physical ram. Maybe if the OS is wasting it on pointless disk caching, but don't you think the programs in memory should have priority over blind disk caching?
Lest a foolish reader believe your two options (swap immediately, or swap as lazily/late as you can) are the only two possibilities, how about swapping when, say, only 20% of physical RAM is left? That way my Firefox and Eclipse don't swap to disk and take twenty seconds to swap in when I have 500MB of GODDAMN FREE RAM!
Hey, I'm just your average shit and piss factory.
On Mac OS X, swap is stored (by default) in files in the /var/vm directory on the boot hard drive, instead of on a separate partition. So there's no limit to how much is used, nor a predefined minimum amount of space used, the swap space expanding and contracting as needed. That seems reasonable.
Signature.
With modern systems easily capable of alot more than pitiful 2GB (which is the minimum for anything respectable) if you need swap (or Virtual Memory) then you need more RAM. Simple, RAM fast, HD slow, swapping in and out of HD nasty retarded slow. Swap is a bunch of sissy pansy bullshit. Be a man, load up with RAM....more power.....
http://www.linuxnews.pl/_news/2002/09/03/_long/144 5.html describes a way to use gpu memory as swap on linux.
Disk is always far cheaper and more plentiful than memory. If you have four gigs of memory, what's wrong with carving eight gigs of swap out of your terrabyte RAID? If you have that much memory in the first place, then you're probably running large apps. Do you and them a favor and give them a little breathing room.
Dewey, what part of this looks like authorities should be involved?
I have a Corsair XMS 2GB kit in my AMD64... The motherboard can hold 4GB. I have 4GB Swap. Set swap to whatever the maximum capacity of your computer is, and you'll be fine. I use swap all the time, even with 2GB, Ubuntu dual head + wine + windows games + firefox 40 tabs + thunderbird + amsn + xosview + gimp, eat up a lot of RAM. So yeah, 2GB isn't enough. Someone send me 4!
If your system informs you that you ran out of memory, then you apparently didn't have enough for what you were doing. If you have never received such an error, then I'd say you have plenty...
or you could ask... How much hard disk space do you use for your swap partition today?
ajf
You have a GUI to run: 600 MB for firefox, 1800 MB for OpenOffice.org, 100 MB for X, 100 MB for desktop odds and ends, 300 MB for Evolution or Thunderbird, and 10 MB for old-style stuff running in the background.
Total: 2910 MB
Yep, you need a gigabyte of swap. OpenOffice.org was made 64-bit clean for a reason. If you plan ahead, not wanting to reallocate disk space in the next few years, you'll allow for this:
2 GB for firefox, 5 GB for OpenOffice.org, 1/2 GB for X, 1/2 GB for desktop odds and ends, 1 GB for Evolution or Thunderbird, and 10 MB for old-style stuff running in the background
That's 9.01 GB. You're exactly 7.01 GB short, so you'll be needing that swap space before you know it.
While you can turn it off for large memory systems as some suggest, that's a bad idea. I'm sure you never think you'll eat up 2GB of RAM but it can be done. I'm known to run my system out of RAM from time to time on accident.
So, here's how I'd break it down:
--If you have less than 512MB RAM, get more RAM dammit.
--If you have 1GB of RAM go for a 1-1.5GB swap. That's enough you shouldn't run out but not too much.
--If you have more than 1.5GB and are on a 32-bit platform, then set the swap to make up the difference to 4GB. That's all your system can address anyhow. Yes I know there's stuff like Intel's PAE and such but really, on a 32-bit system 4GB is all you ever really have and all you should ever count on.
--If you have a 64-bit system with 2GB or more RAM, I'd probably go for them RAM amount over again. So 3GB of RAM, go 3GB of swap. That basically lets the OS swap out your entire memory, should it need to. Overkill really, but disk space is cheap.
All in all in high memory (2+GB) situations it's non-critical.
In the case of Windows 32-bit, much past 2GB isn't likely to see a lot of use. Windows divides it's virtual memory model as 2GB user, 2GB kernel. Well if you actually HAVE 4GB of RAM, you'll find that a single program just can't access more than 2GB of it, the address psace presented to it won't allow that. So really unless you are running multiple massive memory apps, you aren't going to accomplish anything. In 64-bit, of course, it'll support what you give it.
I doubt that you'll ever break the 1 gig mark, with 2 gigs of ram, it's pretty safe to turn the virtual memory and swapping on windows off through the control panel.
I've had my swap turned off ever since I got my first gig of ram.
If you are doing something so memory intensive that you might need to swap, good software all has it's own swap built in, e.g. photoshop will swap itself when necessary.
To know for sure if you need to use swap or not, hit ctrl-alt-del, and look at the commit charge in the task manager, if you've ran your computer for a while and the peak is the amount of ram you have, it should be safe to turn the swap off. My computers peak is at 700megs, and I run 2 virtual machines, photoshop, eclipse, and stream video all at the same time. So it's probably pretty safe.
How much WHAT ?!?!?!?
/etc/fstab ...
(I use a Mac you insensitive clod!!)
Ohhhhh,
-- "It's not stalking if you're married!" My Wife.
Hell, I still use swapfiles, too bad most distros dont offer it as an option anymore.
...memory swaps YOU!
But... but... the rule of thumb says to have twice as much swap as RAM!
It's a pet peeve of mine that so many system administrators appeal to "rules of thumb" about decisions such as this, instead of actually thinking it through. Sys admins pass around these nuggets of wisdom with unquestioning reverence, like they were handed down from some bearded UNIX guru sitting on a mountaintop. These rules either 1) happen to reflect reality, 2) do not reflect reality, or 3) reflected reality 20 years ago but nobody got around to issuing some sort of "revocation rule of thumb". :)
My experience is that very little swap is needed these days, and the rule of thumb falls into category #3. Long gone are the days that the OS demanded swap space for all process memory.
If I have a machine with 1GB of RAM, I'll usually give it 512MB of swap or so. As discussed elsewhere in this thread, a little bit of swap is good for pre-emptive swapping and for emergencies (to avoid the dreaded Linux "oom killer".) Also, if you're going to use hibernate, you'll want at least as much swap as real memory.
In Windows and Mac OS X, let the system decide. Windows likes to swap things out to keep physical memory free, so having some swap will in fact make the system less crash prone (since you won't suddenly run out of memory.) Just let the OS decide, it will enlarge and shrink as it sees fit, and you don't have to worry about it.
In OS X, you can't really control it anyway (unless you dig into the BSD roots.) So leave it alone.
In Linux, I generally recommend swap area equal to the time-tested 2.5x system memory. Unless you KNOW beyond a shadow of a doubt that it will be a 'light use' system, then go with swap equal to main system memory.)
The only time I ever set swap to zero is on a hard-drive-space-lacking notebook computer that has plenty of memory. (A rare occurrence.) Although I do have a testbed machine running now with 4 GB of main RAM and an ancient 4.3 GB hard drive, so it's running with no swap. (Awaiting a new hard drive at the moment to turn it into a production machine, so it's just stress testing itself with the old hard drive.)
Another non-functioning site was "uncertainty.microsoft.com."
The purpose of that site was not known.
The question should be: How much swap space is enough?
/tmp in "memory" - so that takes up swapspace as well.
And the answer depends on a lot of things. This includes the usual questions of what programs and how many concurrently.
And of course some Unix variants have
For Desktops:
--------------
2x physical ram, capped at 512MB
reason: Most everything the user wants to do involves "twitch" access. By wich I mean this: If it ain't fast, it's crap. Paging to disk.... is flat out SLOW. For Servers:
------------------
2x physical ram, up to (HD usable space / 10);
reason: Servers have variable load requirements. You never know from one day to the next what your load will be.(sure you can estimate, but that goes beyond general fromulas) By having massive amounts of pageable to disk memory(in an envrionment where response time is not a big as uptime) you have the advantage of absorbing that excess work.
Cliff Claven
K.E.G. Party Chairman
Founding Leader of: Koncerned for Egalitarin Governance
Virtual memory is not the same thing as swap, you imbecile.
Malike Bamiyi wanted my assistance.
(i.e. simulating memory using HD space)
Simulating high speed solid state random access memory using hard disk memory.
Hard disks are memory too. Last time I put data on a hard disk it seemed to remember what I put there.
I drink to make other people interesting!
Plenty of good comments here already. As has been pointed out, you may get performance benefits by swapping out less-used apps and using that RAM for disk buffering instead.
... so the kernel dumps everything out to the swap partition. That's fine: the kernel's just panicked, so the contents of swap are moot anyway; you know you're not overwriting anything important that way (unless you're holding serious data in /tmp, in which case you have bigger problems than wondering how large swap should be.) Ok, maybe the disk driver has caused the panic, but that's relatively unlikely; you shouldn't have swap (or root) on fancy-schmancy disks anyway.
...
But in my opinion, for a server at least, you should have at least as much swap as physical RAM, possibly more. Why? Well, if (for example) Solaris has a kernel panic, it can be configured to dump the contents of RAM out to disk. Which disk, and where on that disk, is safe? You can't rely upon the filesystem driver being safe to use; it might be that that's what caused the panic
On the next boot, it reads the data in from the swap partition, and writes it to a nice, permanent file somewhere on the filesystem. That dump file can then be sent off to Sun for analysis (or whomever else might be interested). Effective, and above all else, safe.
Once you have that swap space in place, you can start asking questions about whether you should allocate more. The answer to those questions depends on the applications you're running, and no one answer will be right
These days it's just better to upgrade your RAM rather than going much beyond 1.5-2GB swap. Why? Well, the problem I'm seeing with enterprise and high-use database applications is that too much swap becomes extremely counter-productive for large processes or large numbers of processes. "Too much" is often unfortunately defined post-event as "the amount of swap that it takes for the OS to bring your system to its knees long enough to annoy someone important."
In reality, it is better for these high-use users to limit swap enough that an out-of-control process or process group is halted before the system begins swapping so much as to become unusable.
Ah, but sudog, you might be thinking: your users should just be using resource limits per-application!
This is irrelevant, I say: if anything else ever, as a (perversely) cooperating set of processes start being pushed out to swap then we have the same problem and we're screwed again. The real solution is to limit swap, not try to juggle individual processes like a herd of cats.
Hard drives just aren't fast enough to support a large volume of swap; think about it. The HD speeds become a significant bottleneck when swap is busy, and since swap usually takes precedence over normal drive use, your responsiveness in the machine drops to unusable levels. Normal users especially *really* don't have the drive speeds to accommodate a large swap, and it's been my experience with mid-range servers running applications heavily used by hundreds or thousands of concurrent users that even on the big servers, if you set swap too high you get exactly the same problem.
So therefore, let me offer you my answer: calculate the speed of your drives in a MB/sec ratio. Multiply that by about 30-50 (depending on your own tolerances) and set that to be your swap.
One thing to consider is whether or not you're using tmpfs for /tmp. For performance, I recommend using tmpfs for /tmp, and basically treat the swap partition as your /tmp partition. It may seem counterintuitive, "why would it be faster than a filesystem when it's backed to disk anyway, and my filesystems caches just file if need be?" The answer is that tmpfs never needs to worry about consistency. On the kernel.org machines, we have seen /tmp-intensive tasks run 10-100 times faster with tmpfs than with a plain filesystem. The downside, of course, is that on a reboot, tmpfs is gone.
Honestly, all of these answers and not a single person has asked this question yet? /. may have hit a new low tonight.
The proper answer is, 'it depends.' This is one of the things it depends on.
"People who do stupid things with hazardous materials often die." -- Jim Davidson on alt.folklore.urban
Turning off the page file in windows can be regarded as a hint that you wont need it. If you leave it turned on, windows will assume it might be needed and use it proactively to make the best use of it when it is absolutely needed.
However, this is probably not a good hint to make. However great you think it is not to use the pagefile, youd probably rather some of that memory get used for disk io buffers than hold super ancient stale pages that nobody is accessing.
I think the best way to look at this is the same way as the superfetchwhatever flash drive feature of vista.. obviously adding 1G of dram is better than adding 1G of flash memory, but even if you think its pointless, a lot of very intelligent people are finding ways to make the OS take advantage of whatever resources you can scrape up for it and there is plenty of room for improvement and innovation in this respect.
Similarly, if you are choosing between 2G of page file and 2G of dram--choose the dram! But if you can't fit any more dram in, you'll wish you gave windows the extra resources it can use to tune your performance.
whereas linux can swap however you wish, swap partitions are only frequently used because they are the best performance wise, no overhead dealing with the filesystem. Linux can and will use basicly any type of storage you can imagine to swap on though.
:)
If I ever encounter a linux box without swap, a quick dd creating an empty file and then using swapon on the file fixes all, you can also use multiple swap files/partitions if necessary. same deal.
only main annoyance with mac os vm is that it swaps out way before necessary, not as bad as windows but still it does some strange things which my mac tech friends cannot fathom why it does that way. Also it (appears) to not be changable behaviour. Correct me if wrong on that since said friends are quite annoyed with it
these days, when you hit swap your system is misconfigured.
One of the systems I support is a Sun v1280 with 96Gb RAM (three system boards maxed out). The system primarily is a db server running Oracle 10i. I set swap at 12Gb (per Sun's recommendation). However, this box has been up for over a year and actively utilized with swap usage unchanged at just over 200Kb. Still, swap is an OS requirement (at least for Solaris 8), even if it's set to just a meg.
150 comments as I write this and I haven't seen anybody say this yet.
Processors have gotten faster, memory has gotten somewhat faster, hard drives have gotten monstrously larger, but hard drives have only gotten marginally faster since ten years ago.
Instead of measuring swap in terms of absolute size, measure it in terms of time-to-fill, if you were writing flat-out, which you never are with swap.
Let's say you have 1GB of memory and you use your rule-of-thumb for 2.5GB of swap. Using an average hard drive transfer of 50GB/sec (and I think that's actually read, not write, but as you'll see it doesn't really matter), if you're going to use that swap, it would take you nearly a minute to use that space, writing flat out. Writing's often slower so multiply by an appropriate amount.
Odds are you're not actually going to use it that way, so whatever is using that swap is probably going to take a lot longer, orders of magnitude more.
Do you really need a minute's worth of swap? Is there anything that is so critical that you can't afford to run out of memory, but you're willing to wait hours upon hours while the swap is fully utilized?
Swap has two purposes: To swap out uncommonly-used pages so you can load more of the current working set, and to extend the memory space available to programs. 10 years ago, when we had mere seconds of swap, this made more sense. You could load windows, and swap half of it out, and boy did you ever need that RAM. If you were going to load a Word document that didn't quite fit, swap could save your bum, and if it got too loaded, it'd still run out of memory. You could afford to wait because you only had a few seconds of swap, and short of a really pathological swapping pattern you could expect your operation to terminate in a couple of minutes.
The second use in modern times is basically pointless; just let the program fail. You almost certainly do not want to let the program spend the next hour swapping. The first use might still be valid, but you might as well only use a couple of seconds of swap; call it 100MB. Beyond that, nothing is really useful. And in Windows, excessive swapping also tends to basically lock up the machine which is something to be avoided.
Huge swap partitions, unless you have another use for them (some implementations of Linux suspend are the only ones I know) are basically a holdover from the past, religiously clung to by people who have been 'doing it this way' for over a decade. Skip the swap unless you know why you shouldn't.
Man, it's utterly depressing to see the same useless "rules-of-thumb" still in effect when the original question is asking if the rule-of-thumb is a good idea.
1) Page space is not swap space. There's a small distinction that's generally lost (and generally ignored). Page space is used to move memory pages to and from disk. Swap space is technically to move entire processes out to disk. The difference is mainly based on when your OS was created (i.e., technological underpinnings) and no need to get into it now... but the difference is meaningful.
2) Page space is not *free*. There's a misconception that if you have 500G of disk space then "how does it hurt" to put 8G of swap on 4G RAM. Depending on your OS, the size of the page table can grow remarkably depending on how much memory (RAM + VM) is allocated. This means that adding 2G of page space may not cost anything, but adding 2.5G may suddenly take up another chunk of real, non-pageable memory because the page table cannot itself be paged. This means that if your app is thrashing, then adding page space may make it worse.
3) Even with lots of RAM, it's still often a good idea (depending on your usage) to have some page space. Modern OSes will still page out unused pages to use RAM for better stuff. I.e., if you have a huge file open in a graphics application, but are not actively using that application for a length of time (an hour, say) then the OS will page it to disk. This makes better use of your physical RAM. On some OSes the OS will use page space even if free RAM is available. It can then toggle a page out by flipping a bit in the page table and not have to do an expensive write.
4) In some systems you can overcommit memory. Applications tend to request a lot more memory from the OS than they'll actually use. This is useful in many instances but it again depends on your usage. If you're running a single application that doesn't dynamically allocate memory then you can run pageless. If a new app requests memory that's not available then it will get a failure on malloc request. This can be desirable in some circumstances.
5) There are benefits to running page space on a separate disk, but for the vast majority of home users, the difference is negligible. This applies to Windows and Linux. Once you start stressing the VM subsystem then a separate disk is highly desirable.
6) You can create page files on Unix/Linux. It's not desirable generally because of the extra filesystem overhead and possibility of fragmentation. But hey, in a pinch it works.
7) Why this 2x RAM rule? A lot of it comes from old VM subsystems that needed a "picture" of the entire memory space. This made the page-out algorithms easier to code. Newer algorithms don't require the 2X RAM.
KL
what if you have a cheap mega commodity drive and the old school small 15k 8M cache u160 scsi diak laying around *cough*
Remember to fix your pagefile / swapfile size, i.e. set the minimum pagefile size = maximum pagefile size.
Yes, having a pagefile that resizes automatically is more space-efficient, but this will slow down your system whenever you need more memory. I get really irritated when my pagefile increases in size by hundreds of megabytes whenever I load memory intensive games and when my pagefile shrinks back to normal when the games quit.
w00t
The 2.5x case comes from two simple rules of thumb. Firstly, you need enough to be able to hold the whole of what is in RAM now, plus everything you want to swap in, plus enough to minimise fragmentation and cover overheads. Secondly, the more swap space you have, the more metadata you need to manage it AND the greater the latency to perform any kind of swap AND the more swapping you need to do to run all active processes. Too much virtual memory is a Bad Thing. Having 2.5 x RAM was considered a good compromise and it is one I use to this day.
Today, both rules of thumb still hold. The largest single object you can have is one that fills ALL of RAM after the kernel, and you absolutely must have sufficient swap space to be able to dump that object to disk. If you don't, then the kernel will either panic, kill the process or cause any other activity to behave unpredictably. It won't have the resources to behave correctly. Any number of these objects could, in theory, be swapped out - but remember that they don't run when on disk, only when in memory, so the more you have, the smaller the timeslice each will get - and the sum of those timeslices will go down, as you need to allow time for the swap to take place.
However, today isn't quite the same as yesterday. The difference in performance between hard drives and RAM has changed. There is better caching on the drive. The swap algorithms are smarter and there is more understanding of what metadata is useful and what really has no value. Process handling is also smarter, so processes aren't necessarily run in order - round-robin scheduling is used for some time-critical stuff on Linux, but most applications use a more relaxed system.
Also, programming has changed. There is greater re-use of tools and libraries - well, sometimes - and this means that the largest object you really have to handle at a time is much smaller than the size of RAM. A certain fraction of what's left will be used by shared libraries and shared resources.
Lastly, because hard drives are reasonably cheap and most PCs can handle several at the same time, you are far far better off getting a drive and dedicating it to swap. This is good for many reasons, not least because the drive won't have to move the read heads from data space to swap space and back. You eliminate a vast chunk of seek time, reduce the stress on the drive AND can experiment with different swap sizes without risking losing data.
I would therefore STRONGLY advise using the classic 2.5x and a different hard drive, but if you can't do this for some reason and want an updated formula, here is what I would suggest:
The meaningful RAM will be equal to the total RAM minus the space used by the kernel and vital, non-swappable resources/daemons. Multiply this by three for 7200RPM hard drives or by five for 15000RPM hard drives. Multiply by one and a quarter for basic swap schemes, or by one and an eighth for profiling/intelligent swap schemes. Add the size of the hard disk cache, if the cache uses a high water mark to control operations. Subtract the size of the hard drive cache (unless this takes the size below zero) if the behavior is controlled by a low water mark only. Add one megabyte per simultaneous user. Add one megabyte for each large -or- long-running application likely to be running simultaneously. Subtract the total size of all the shared libraries likely to be loaded in the case just considered.
This is a LOT more complex than 2.5x, so much so that I generally wouldn't bother using it except
It's a small world and it smells funny; I'd buy another if it wasn't for the money; Take back what I paid (SoM)
Can't you linucks people get on the same page about this?
You're 10 years on now, for God's sake; get it done.
I'm still on AmigaOS.
touche :)
;)
however, may I remind you that
clarity ~= conciseness/(precision)^2
I would've used "simulating RAM using HD space" if I had hit the Preview button first
Did you know that "FTW" ("for the win") is a direct translation of "Sieg Heil"?
The answer, as others point out, is "it depends". Several applications are likely to want to create in-memory data structures of size proportional to their input. Inputs can be huge these days. So you feed an application a large input, it will need Gigabytes of memory.
But here is the meta-question: is it better for applications to use in-memory data structures or should they do their own RAM management and write stuff to disk? I claim that apps *should* create in-memory structures as much as possible. Virtual memory was a huge advance in programmability. It relieved programmers from managing RAM explicitly. Compare an old-style app (e.g., tex, or an old compiler with lots of stages and intermediate files) to pretty much anything modern. TeX will write lots of intermediate files. This is completely unnecessary and a bad programming style. So, my advice is to give your system plenty of swap. It frees programmers from having to worry about RAM/disk constraints.
Note that I'm not claiming that all applications should delegate all their RAM management to the OS. There will always be sophisticated apps that will need to manage RAM explicitly. But a well-designed app should only need to do this when the OS's replacement or prefetching policy is not ideal for its usage patterns, *not* just because there is not enough space in the swap file. The latter is a pretty weak reason for doing explicit RAM management.
(It's for a data mining project. No, I haven't filled all the swap yet, but I'm still coding...)
Your god may be dead, but mine aren't!
It's hard to know what exactly what people are doing with their linux laptops, but since you can choose to suspend to a swap partition from the kernel config, I'd guess that's a fairly popular option. On old thinkpads, I remember having to creat a hibernation file on a dos partition under dos and I'd suspend to that. That's just my experience with my machines ( = apples and thinkpads) & my favourite distros (slackware/slackintosh), but I'd still hesitate to say that the typical linux laptop user suspends to a file in /tmp. What does Ubuntu do?
Yes, it depends.
With Linux, at least, it's completely up to you and what you'll be doing.
I know of people happily using a 256MB swap space with 1GB or 2GB RAM.
On a basic system used for firewalling, I have no swap at all.
At work, we try to have 8GB, even on 1GB systems, because we do occasionally have batch jobs consume tons of memory, or giant databases loading into CAD apps, where drastic slowdownns are still better than lockups or crashes. But a screwup in making install disks resulted in a bunch of desktops with 1GB swap and 1GB or 2GB RAM, and only a couple of them have problems. Our proxy server and mail gateway have a small swap space as an emergency precaution since we never, ever want them to die. Slow is better than dead, and the monitoring software will catch the slowdown.
My file server at home has a swap the size of RAM, just to be safe. The "workstations" have swap spaces at least 2X RAM, just to be safe. Once in a while, doing something hairy in GIMP on a large image, this has saved one of our fannies.
I'm just a lowly A+ in training, but it seems to me that anything more than 1.5x your physical RAM is counterproductive as it means a lot more read/write cycles over the course of any given period. 1.5x is what everyone i know uses and i've never known any more to impact performance in a beneficial way.
"No, no, no, don't tug on that! You never know what it might be attached to."
There's no real hard and fast rule anymore. And setting it against a static value (like physical memory) is incredibly wasteful.
It's a much better idea to set it interactively. Use the system without adjusting the Virtual Memory for a while. Then take a look at your usage and set your virtual memory against that usage.
For instance.
If you're in a Windows machine, let it run normally for a few days.
Run everything the way you normally use it.
Multiple apps, multiple instances, games out the ass, everything.
Then open up the Task Manager and look at the Performance tab.
Take a look at the Peak value under "Commit Charge".
Set your virtual memory, min and max, at about 10% above that value to leave yourself a little headroom.
Normally this will be enough to deal with your maximum swap requests.
If, somehow, you begin bumping against virtual memory limits again AFTER that, bump it another 10%.
If you still have problems, keep bumping it in 10% increments, and start looking for apps that are memory leaking.
Chas - The one, the only.
THANK GOD!!!
Who cares with the current prices. Just take the old standard. Twice as much as your 'nirmal' memory. So what if that means you take up 4 GB of your 2GB machine and you never use 3.5GB.
Your freaking HD is probably 200GB
Use your old 8GB HD if you like, it doesn't do anything else.
On Linux it is like this; if you need your swap a lot, add memory. If you use your swap a lot, it might be more importand WHERE you place your swap. Devide it over different HDs. Put it on an HD that you seldom use. That kind of stuff.
Don't fight for your country, if your country does not fight for you.
Don't you hate meta-sigs?
I've needed > 2 Gig on a Windows system before. And this is with 2 Gig of RAM. Yes, that's right, I've needed this. Granted, I was running multiple instances of a memory intensive application (finance), which is not what a "normal" user would see... But, you can't just say "Oh, no one needs a pagefile" without some pretty hefty fine print. Anyway, after Windows made a total mess of instantaneous resizing, I changed all the machines to use 2 Gig pagefiles.
:-) (thanks ppl!)
Linux? Dunno, I'm gonna go for the 1.5x RAM
--LWM
My strategy generally is to use a file for swap rather than a partition, even in linux.
What I find curious is that you have a strategy. On what relevant experience do you base this strategy? 1 GB of disk space costs less than $0.50. Set up 3 GB of VM if it makes you feel good. The latte you drink while you set it up costs more than the extra disk space!
So go for it!!! Who cares what you do? Heck, give yourself 10x the RAM and see if it actually makes any difference!!! (it won't)
This is sort of like asking: "Which goes faster: the yellow Pacer or the red Pacer?"!
I have no problem with your religion until you decide it's reason to deprive others of the truth.
I was setting up SLS on a 4meg 486SX with coprocessor emulation and dreading the fact that I had to give up 8meg of disk space for swap. 2 gig swap... bah...
Zoid.com
It all depends on the system's role. Common desktop, lotsa RAM? No swap. Medium RAM, common desktop? No RAM. Anything with more stringent requirements or less RAM, add swap accordingly...
But then again, when a 250G disk is like $80, what's another 3 or 4G of used space?
~/ssh slashdot.org ssh: connect to host slashdot.org port 22: too many beers
Swap space in my experience depends on management and the application. I had a manager previously that came from a mainframe background and had a specific amount he wanted (2.5x RAM). I showed him documentation time after time showing swap space under utilized, but any time there was an issue, he brought up the swap space. Also, SAP will complain if there is not a very specific amount of swap space.
Before talking about swapping, pagging, and virtual memory please learn and understand this equation: Virtual Memory = Physical Memory + Swap(or Page) file. I let the OS (windows) manage my page file. The current generation of windows OS's (2k, xp, & 03) mange the swap file much more efficently than windows 9x did. All this mumbo-jumbo about tweaking the swapfile came about because these old versions of windows needed to be tweaked, they had memory problems and tweaking the swapfile would improve performance and stability. But the current generation of windows has no need for tweaking the swapfile, save for some special server situations. Its a waste of time to personally manage the swapfile for a desktop/development computer.
I never user more than 512Mb of swap. If you have a runaway process, you can let it live but you avoid a lot of trashing. If more than one process start consuming RAM like crazy you, actually want them to die from an out-of-mem error otherwise your whole system will grind to a halt while it spends most of its time unswaping one and the other. At 512Mb you can do a little excess of memory usage but won't go beyond what you can unswap in a time quantum (mostly).
Smarter per-process ressource quotas would probably be better and it would be nice to have a trashiness function according to the disk speed but so far 512Mb sounds like the limit between using the resset button or just taking a coffee break when you see the HD led blinking like a strobe.
It is just easier to try the approach where you consume a lot of RAM first and to re-code if it doesn't work. I work in bioinformatics and we often have huge datasets, I alway try to load the whole thing and to make the computation in RAM. Only when I get and out-of-mem error do I segment the dataset and try a smarter approach. That might explain my choice for 512Mb and the right threshold for other people might be bigger or lower but I'm pretty sure that its bellow 8Gb.
i'd really like to not have to swap at all.
...
it would be neat if the OS just said, sorry boss
no memory left close something else first.
on XP it seems impossible to disabel the pagefile/swap
and even if disabling tons of services etc. running
notepad it will still swap.
anyway, since we can't get around it, live with it
the samrt way. if you install XP or linux or
remeber to make the very first partition your swap. the
idea is that the first partition is nearer to the center
of a platter, e.g. the seek and write times will be faster
then at the edge of a hdd platter.
my first partition C: is called PAGEFILE and is 3GB big and
i have 764 MB ram. the only thing on it is the pagefile for
XP.
same for linux first partition is swap.
last thought swap is not "BAD", but the way a OS decides to use
it can be bad.
Swap is useless unless you use firefox. The concept of swap is a big BS. If you dont have enough ram , it's better the program will be closed than wait till it hits the swap and dies anyway.
The need to close the program will remind you that your resources are indeed limited and will not permit alot of vendors to bundle crap with new pc since it will eat all the ram away.
I dont really see any benefit of swap. Why not make programs just resume upon reopening. Why not spen some time writing quality software. The absence of swap will make gnome/kde guys consider how to program efficently, it will make people think if the schould use maybe utorrent instead of azureus with the effect of being able to edit something in photoshop. And as a result the people developting Azureus/firefox will actually fix their bugs or noone will use their software.
That raises the question: is swapping obsolete? Or to put it more explicitly, has the speed difference between modern CPUs and hard drives become so large, and RAM so cheap, that it's better to consider running out of RAM to be indicative of a software failure? That way you end up with a system where one or more processes may fail (or be terminated) but at least the machine remains usable and doesn't swap itself into non-responsiveness.
In my experience, the answer is yes: with 2GB of RAM in my machine, I never need to swap, and in the few instances where swapping did occur, it was because of buggy software (memory leaks) and manually terminating the offending processes is what I needed to do resolve the memory shortage. So why not just have the OS do that automatically?
Or to put it a third way, is there any situation where swapping is helpful, anymore?
I don't care if it's 90,000 hectares. That lake was not my doing.
No page file at all! http://www.kevincornwell.com/forums/index.php?show topic=9&pid=9&st=0&#entry9/
Change the line in CONFIG.SYS: SWAPPATH=:\ is how much free space is left before the OS alerts you to running out of swap space. is the initial swapsize Example: SWAPPATH=C:\OS2\SWAPPER.DAT 4096 12880 4MB minfree, 12MB initial swapsize. You can even swap to a RAM disk, see this page To turn off swapping, in CONFIG.SYS, use the line MEMMAN=NOSWAP,PROTECT
Comment removed based on user account deletion
For Windows, omit the word "either" and replace "or" with "and".
It's a small world and it smells funny; I'd buy another if it wasn't for the money; Take back what I paid (SoM)
...I see your swap is as big as mine...
Comment removed based on user account deletion
Thrashing is even worse when the system doesn't allocate enough ahead of time. One of my Java programs (unintentionally) brought down a production AS/400 in the middle of the work day. A third party utility for running batch applications allocated the Java program to a 1 MB (max), single threaded pool. This was a program that used three threads of its own (plus however many the JDBC process spawned, which was probably at least two). So somewhere between swapping all of those thread contexts into a single threaded workspace and managing at least 64MB (and probably closer to 128MB) in a 1MB window, you might say that it converted OS/400 to DOS. The amazing thing is that it had run successfully several times prior (we were trying to figure out why it was running so many orders of magnitude slower when running in batch vs interactive).
Programmers in mirror are brighter than they appear
"Memory is like an orgasm. It's a lot better if you don't have to fake it."
-- Seymour Cray, on virtual memory.
You are not entitled to your opinion. You are entitled to your informed opinion. -- Harlan Ellison
Windows just wouldn't stop swapping out shit that I had been using two minutes ago - so I gave it bugger all to run with. I figure 3.8GB of address space is enogh for now. Screw giving it more. I would turn it off, but PS bitches about lack of a swap file.
~/words_by_grainfed.txt
Yes, swap is useful in any situation when you don't know if you'll have enough RAM to run everything.
And RAM can be so "cheap" as you say, but disk is still far cheaper.
With swap, you also have some way to find out that you're running out of memory. You can monitor it, and you can also sometimes see a performance decrease (if it's a desktop), though you'll probably not notice it with SCSI disks. But you still have the monitor, right ?
Use of terminology has varied between system architectures and over time, but on the big systems I grew up on, paging referred to the process of writing out 4K chunks (pages) on a LRU basis. Swapping was the process of writing out an entire application or address space. The purpose of paging was to share memory resources, wheras swapping was mostly intended to reduce the number of applications actively competing for CPU resources.
Or to put it a third way, is there any situation where swapping is helpful, anymore?
More filesystem cache is almost always useful, and swapping out unused pages will allow you to have a larger filesystem cache.
Or to put it a third way, is there any situation where swapping is helpful, anymore?
:)
Sure. Consider Andrew Morton's logic:
http://kerneltrap.org/node/3000
In your average program, most code never gets executed, and most data is never used. For a long-lived process, swapping out the unnecessary bits frees the memory for disk cache.
While you may improve overall performance, by minimizing the average completion time for operations, the downside is responsiveness. As a user, I don't care if Firefox reads cached images a few milliseconds faster (by reading from cache instead of disk) if I have to wait 3 seconds for Thunderbird to respond to my clicks (because it has to swap in) after I've been browsing for a while. Average speed be damned!
Having said that, I just set my swappiness to 100.
There's a single issue I take up with the above post. Just loading a bunch of applications won't give a good indication of memory usage. Load of some work with them, projects or code. Open a few web pages, etc... Those apps will start to grab more memory leading to a more accurate indication of memory use. Devstudio, for example, just shot up from 60MB to 260MB just opening a project. Never mind actually trying to build something :)
It's always 2^virtual memory address bits of the processor.
Sometimes the amount of virtual memory available to programs is smaller due the operating systems reserving some part ( like upper half ) of the virtual for itself, so on most operating systems on the most common settings on the most common hardware there is always 2 gibibytes of virtual memory for every process.
Swap file and virtual memory are differnt things. If you are talking about swap file, use the term swap file.
The equation stays about the same though the scale of memory sizes involved increases. If one ran a set number of processes that all fit within core (RAM) memory and did not increase in size over time, one wouldn't need virtual memory at all. When using a properly sized computer of a given generation, the typical set of processes being run fits in or almost fits in core memory, so a virtual memory size equal to the core size provides ample protection against memory exhaustion (both core and virtual memories full). Exactly how much memory this is increases as the sizes of those typical processes increase. These days 2gb of core is usually large enough to avoid the need to use virtual memory, but it can be consumed pretty quickly by either large numbers of typical processes or a few memory intensive ones. Memory exhaustion is a very unpleasant situation and leads to data loss and service outages. The computer does not react well to having literally no room to think. So given this, and that virtual memory (disk space) gets cheaper at (somewhat) the same pace as core (RAM), it is much safer and cost effective to err on the side of caution and make the virtual memory bigger than necessary for day to day operation. Regardless of the scale of the current generation memory sizes, a virtual memory space equal to one or so times the core space of a properly equiped machine is the right size. For small core machines, the larger the core memory deficit, the more times larger the virtual memory space must be to avoid running out of total memory. A machine running the latest Windows environment in 512mb of core would need a virtual memory much larger than one or two times that size to be safe. Said machine would still perform very poorly due to the cost of continually accessing the virtual memory, but it would avoid crashing due to memory shortage. Systems with much more than average core memory may be able to do safely with less or even no virtual space, but it is arguably a foolish place to conserve since disk space is cheap and maintaining at least a one times core sized virtual memory space is insurance against the pain of memory exhaustion.
Or distilled: less RAM than average needs more than two times that for virtual, average RAM needs one to two times that, and lots more RAM than average can probably get away with less than one times or even none but probably should use one times anyway.
Again note that average refers to the RAM size of a current generation machine configured to run the typical number of typical current programs with reasonable performance.
I take care of few machines (for my surroundings), all under Linux, and with the current state of the art of the kernel my rule of thumb is that: swap = 2*RAM if swap > 1Gb swap = RAM I always put at least as much RAM as swap in order to allow for suspend to disk.
When using tmpfs create a huge swap. For normal use you won't need it, but when you decide to compile some packages it will use it all. Around 5GB swap + 2 GB RAM is enough (for me).
Note that this is a fail-safe measure. It will work with 2 GB RAM + 1 GB swap, but sometimes it breaks... And you don't want to get a disk full error after a few hours compiling something. Another option is to de-activate tmpfs before compiling huge things (but I never remember to do that).
But always remember, virtual memory is only there to buy you time, so you can keep running until you can increase main storage.
And, of course, if at all possible, use several smaller swap partitions on SEPARATE disks to get better performance.
What the original article didn't mention, and none of the replies seemed to go into, is the fact that with current CPUs, effectively all RAM is 'virtual':
Only on-chip memory, i.e. cache, is "real" these days, and all accesses to DRAM will be handled in paging units of 64/128 bytes or so. If this sounds familiar, it should! CPUs with 1 to 4 MB of real memory and lots of virtual memory is what the mainframes and minicomputers had about 20-30 years ago.
What this means is that now, just like then, all performance-critical code needs to be written to keep the working set within the amount of "real" memory you have available. When you passed this limit, you needed to make sure that you handled paging in suitably large blocks, to overcome the initial seek time overhead.
Today this corresponds to the difference between random access to DRAM and burst-mode (block transfer) which can be nearly an order of magnitude faster.
In the old days, when you passed the limits of your drum/disk swap device, you had to go to tape, which was a purely sequential device. Today, when you pass the limits of DRAM, you have to go to disk, which also needs to be treated as a bulk transfer/sequential device.
I.e. all the programming algorithms that was developed to handle resource limitations on old mainframes should now be ressurected!
"those who forget their history, are condemned to repeat it"
Terje
"almost all programming can be viewed as an exercise in caching"
I have 2GB of ram now, and I don't use a swapfile on windows. I even play wow with this setup, and blizzard games are notorious for eating up every available resource (diablo2 even created it's own pagefile when it felt like it) swapfiles are the devil. they are a remnant of times when ram was expensive. they are a solution to a problem we don't really have anymore.
Move sig!
Hard disks are too slow to provide useful virtual memory of anything close to / above 2Gb. If your machine is swapping over 2Gb to disk, performance is likely to be poor during swapping, as whatever process is trying to allocate memory that is not available will block waiting for I/O while other proceses allocations are swapped out, and whatever is applications pages are swapped out will also block when it tries to access the swapped data again. There is absoletely no point in allocating much more than 2Gb, particularly with the low cost of physical memory. Hard disks are simply not fast enough. Again, it really depends what you are going to do with your computer, but if you have a typical 2-4Gb of RAM in a decent desktop computer, most machines running a few applications are not going to have a problem anyway. With 4Gb+, I'd say you can get away without a swap at all, but it's always nice to have some fallback if you are running some kind of huge job.
Dunno about Windows, but in Linux if you want a really fast swap space you make a virtual disk in memory and set it up as your swap space.
For a while, I thought he was just having a play on words, but after a while I realised it was actually a very important observation about performance in computing systems, and if you make the mistake of thinking virtual memory was in any way as good as real memory, you were headed for tears. In these days of cheap RAM, if you need 4GB, install 4GB, and be done with this foolishness of thinking hard disk is just as good.
Of course, in reality it's always good to have a few unused holes on your belt, and VM is a useful thing. Just don't think it's in any way as good as real. For best performance, the optimum ratio is 1:1. That's the message.
Which is why I set ulimit caps on my server, so that no process can use more than eg 256MB of real memory and 64MB virtual (a soft limit, so it can be raised if necessary). Then I get all the speed benefits of swap space, a short time of degraded performance if the process starts leaking, then it dies of memory loss; all the other processes carry on as normal, since there's plenty of ram free, just no single process can use it all.
I mod down anyone who says "I will be modded down for this", regardless of the rest of their comment
Unless I'm reading the activity monitor wrong, I have 4 gigs of physical RAM, and 14 gigs of virtual RAM at the moment. This is a dual 2ghz G5, running 10.4.7.
I currently have Photoshop, Firefox, Azureus, Skype, Adium, Entourage, Mail, and Safari running.
The thing is, I am constantly running out of memory, or rather, constantly getting down to 40megs free. Trying to do anything in Photoshop at that time is incredibly slow, which is crazy because PS has it's own swap files/scratch discs...
Currently you have say 512mb of process memory, and 512mb of in-memory cached files (the kernel keeps commonly accessed files in ram to speed reads); with swap, you could move 256mb of idle processes to swap (you won't notice the processes slowing down, since the're idle anyway), and have 768mb free for caching files.
The only time people notice swap slowing things down is when they don't have enough ram to keep active processes in main memory, and the couple of seconds lag when eg you've had firefox minimised for a day (so the OS thinks the process is idle, and swapped it out), and it takes a while for the hundreds of megs of process to get back to main ram.
I mod down anyone who says "I will be modded down for this", regardless of the rest of their comment
In my opinion the rule of thumb still applies. No matter what you are going to do with your system, it never hurts to have (more than) enough swap space. Like several people mentioned earlier: the more free RAM you have, the more RAM is available to the OS for the disk and buffer caches.
There is, however, a potentially severe case if you have two processes accessing the same resource simultanously. Every good informatician and computer programmer knows that such a case is the ultimate no-no in software engineering. Unfortunately, there are scenarios thinkable, in which it will happen nonetheless.
Back when I was still working on my Bachelor's degree I and a couple of friends of mine tried to simulate this theoretical possibility and see what happens. We had two processes, called 'ss1' and 'ss2', accessing the same resource at the same time:
ss1 would create a file sized X and go into an endless loop writing random bytes at random positions in the file. ss2 would open that file and mmap() it. That way it would be in the buffer cache as long as data was written to it (and since data was written to it by the other process, that was actually the case). The result of the mmap() was a character array and ss2 would write random bytes to that character array at random positions.
We tested this on the following OSes: Linux 2.0, Linux 2.2, Solaris x86 (can't remember which version), FreeBSD 3.3, Irix 4.0.5, 5.3 and 6.2 and Windows NT 4.0 Workstation. We ran the application with administrative or superuser privileges.
As long as the size (X) did not approach half the physical amount of RAM present in the machine, there were no problems whatsoever. However, as soon as X passed that threshold, bad things started to happen. The only exception was Windows NT, which simply aborted the process with a page fault and an out-of-memory error.
All the aforementioned machines that were running Linux or a variant of UNIX, suffered the same problem: a non-responsive system. The processes could only be terminated by doing a hardware reset of the machine. A kill -9 of the two processes did not work, because they were in a non-interruptable sleep. And the reason they were was that the OS was trying to fullfill the resource demands of the processes by swapping out other stuff, including, as we theorized, other parts of the file that were not "hot" at that time.
This piece of intentionally bad-written software and intentionally bad system operatorship of course proved that, while it was highly unlikely to happen, it could happen and would have dire consequences for the system.
Ordinarily, one should never run programs as a privileged user unless one absolutely has to and the two competing processes would have been terminated by the OS had they not run as root on the Linux and UNIX machines. But regardless of whether the OS in question uses the optimistic or pessimistic approach when allocating resources for a new process, the net result of having such a (in our case intentionally) badly written piece of software is the same: the system becomes non-responsive.
In this case, it does not matter much how much swap space you have, the only difference is that if you have only a little amount of swap space the "dreaded" OOM killer starts to kill of processes at a very early hour instead of when it is already too late (and virtually incapable of functioning properly and actually do its job).
Personally, I would still recommend using at least the same amount of swap space as you have physical RAM, and preferably at twice the amount. Bad things happen all the time, and it is better to be prepared for it. Therefore, the rule of thumb still applies.
And on the Eighth Day, Man created God.
I have 2gb (maybe 2.5gb, I don't remember) in my Windows machine, and I just disabled the swap file. The only times I ever have issues is when I'm working a memory leak, and I'd have issues with that no matter how much swap space I used. RAM is cheap enough to make this a non-issue. Besides, it makes Eclipse feel really snappy not to keep having its plugins swapped out from under it.
You're special forces then? That's great! I just love your olympics!
In my experience, the answer is yes: with 2GB of RAM in my machine, I never need to swap, and in the few instances where swapping did occur, it was because of buggy software (memory leaks) and manually terminating the offending processes is what I needed to do resolve the memory shortage. So why not just have the OS do that automatically?
.995GB and rising
As long as it's killing the offending process, not the proverbial drop that made it flow over. Example:
Normal apps: 1GB
Leaky app:
= Free space: 5MB
Now a normal app decides to ask for 10MB space. Which process is killed?
What I would prefer is that the OS kept system cache limited and swapping disabled until it reached a threshold value, say 90% RAM... pass 1.8GB, then you can go into panic mode, warn the user, start preemptively swapping out dead pages so we don't crash hard. But until then, don't swap. When you swap you warn, or if you know some processes are leaky, set them to "auto-killable". But I don't want the OS just kill any process that happens to make the last request.
Live today, because you never know what tomorrow brings
My windows XP pro box started with 512MB, which wasn't nearly enough. So, I went to 1GB, and things got better, but the hard disk still thrashed from time to time. So, I went to 2GB and the system finally seemed like it was starting up faster and running more freely.
:)
I'm actually very glad I went to 2GB, because X-plane takes 900MB of RAM if you let it
If RAM is so cheap, why not buy twice the amount you need, set up a virtual drive and use this as a swap partition. Not really sure whether linux allows it, but it would combine the advantages of both worlds, right?
And it shouldn't be a data safety issue, as swap isn't considered written to the hard drive, right?
Any objections?
"People who are willing to sacrifice essential freedoms for security deserve neither freedom nor security."
B F
My windows box has 2G RAM and turning of the swap file works very well. Windows swaps to disk weather or not it neads to, unless you turn swapping of completely (System Properties -> Advanced -> Performance Settings -> Advanced -> Virtual memory Change -> (o) No paging file -> Set).
The computer is a lot more responsive without virtual memory, and I get no thrashing, ever!
Using this sort of setup I recomend MemInfo from http://www.carthagosoft.net/ to be able to monitor memory usage (hitting the 2G max can be painfull).
Sindri Traustason.
After the demand for virtual memory in Minix drove Linus to create Linux, now people don't want to use it.
Disk is so cheap and plentiful I now configure w/ swap ~8x DRAM so I can suspend large jobs and still start new jobs instead of having to kill the process. I also install max DRAM to minimize swapping and paging. But I'm a scientist working w/ large datasets and don't do Windows or web stuff, so your milage may vary.
old, bearded, Unix guy
The system *always* user virtual memory, and any tricks you try to play keep the system from using VM probably just hurt you. It has been a while since I've done any low level VMM work, but a good sized swap area allows more options on the choice of RAM to swap algoritms. Typically speaking, the system wants, AT LEAST, 1:1 RAM for swap, and more is better. Besides I hear a lot of people talking about applictions "swapping out." Applications do not "swap out" that is an old Mac-ism. In fact, virtual memory is seldom, if ever, keyed by application. On most systems VM is done on 4K page boundaries irrespective of applications, and on i386 systems, on the 32 bit linear memory space below the applications virtual machines. On Pentium II and higher, it can even be done on 4M page boundaries (but I'm not aware if either Linux, Mac, or Windows uses this feature.) Also, virtual memory is VERY fast when compared to application file access. If you have an 8m pix digital camera, your jpegs may be 3 or 4 meg, but the "in memory" version of that picture is 24 to 32 meg. Strategies to chunk up images because there isn't enough memory to load them is almost always slower than virtual memory. In short, these days, a few gigs of disk space is a $1.00, use it, your system *will* be faster.
I use linux, and I have a Machine with 512 MB RAM (please don't ask me two put another 512 stick in, because I really don't need it) I have always found when deciding what amount of space to allocate to the swap, that twice the amount of RAM, works perfectly. However physically you may be able to have as much swap as you want you've got to ask yourself, what's the point!
"I could be bought, but Linux couldn't be." - Linus Torvalds
Not quite answering your question but I read a great tip somewhere on the interweb once: as most PCs now have so much RAM you can get a big speed improvement by mapping your swap file into some spare RAM space.
If I had 2GB of RAM or more, I'd set up a 512MB RAMdisk and use 256MB of it for swap (Everything's in RAM =D). The chances of a system using 2GB of RAM or more are very, very small. As it stands, with my paltry 512MB of RAM, I never swap out unless I'm doing something with soundfonts, or I'm playing a newer game, and then I never breach 1GB unless something's very wrong.
Screw the rules, I have green hair!
"In these days, where 250G of hard disk space is not unusual, and many times is not that uncommon, does anybody care how big the swap file/partition is?"
I've got 512MB of RAM, and Linux rarely resorts to swap. But I have a 120GB hard drive that's nowhere close to full, so there's a 1GB swap partition. Why not?
Penny - plain text accounting
The amount of swap space you need does not depend on the amount of real memory. It depends on what programs you want to run. You need enough virtual memory for all those programs. Then you want as much RAM as you can afford so that programs don't need to be paged out. More precisely, you want as much RAM as the working set of the programs - that is, the memory that is actively used.
Particularly absurd are claims that you need *at least* N times as much swap as RAM. If you size your total VM according to the programs you run, then you want RAM to be as big a proportion of that as possible. It would make more sense to demand at least 1/N as much RAM as swap!
(A minor point: in most current operating systems, swap is effectively in addition to RAM, so that RAM+swap must be as big as the programs you run, but in some older ones the RAM needs to be backed by swap, so that swap by itself must be that big.)
Personally, I have one gig of memory, and I barely ever go over 512 MB usage. A more "above-average" user might get up to 700, but generally speaking, the chance that people today will get to using 2GB of memory is unlikely. Thus, it may sometimes affect a computer's preformance positively to disable swap, since some programs will swap even if you're not close to 50% RAM usage (For example, I am currently using 310MB of RAM and 123MB of swap), which slows things down since it takes time to load swapped stuff into memory.
My new blog
if you use linux, you wont need vmem at all. if you use windows, i doubt you'd need to manipulate around that, or the system will complain and adjust the vmem itself, so i guess its better to leave these 6GB of vmem.
apart from above, i am not sure if "having lots of ram" is a good idea with windows:
1) it will not make use of it anyways (while still ripping every last breath of your hard drive as it used to do)
2) manipulating the registry and forcing the executables to land in ram first will eventually utilize every last bit of your (even graphics) ram and force you to reboot.
i believe gates' followers would still do as good as they do now with these classic 640k, heh
1 gig of PC3200 DDR RAM and a 1 gig swap partition is pleny for my purposes...
Politics is Treachery, Religion is Brainwashing
or just none at all
Kaetemi
How do power considerations affect the size of your paging file? When using a laptop, for example, you'd typically want your energy consumption to be as low as possible: are you therefore better off turning your paging file off and forcing the OS to use your RAM, or letting it swap out?
Antiquis temporibus, nati tibi similes in rupibus ventosissimis exponebantur ad necem.
My desktop at work has 256MB RAM and I typically have 200-400MB of a 512MB swap partition used during the day. (Thanks gkrellm!) The computer is an old GX200 series dell workstation with one ECC RAMBUS RIMM installed. Due to the price of RAMBUS memory and the age of my workstation, swap space is all I'm gonna get from my bosses until I get a new workstation. This just feels like the perfect argument for swap space.
The whole discussion is moot when you use Fedora Core 5 because you need a swap partition equal to the size of your memory so you can use the suspend/resume to harddisk functionality. If that were not the case, I'd say to hell with swap. Don't need no slow disk bringing down my laptop to a crawl. I'd much more prefer the app that's causing the trashing to shoot itself into oblivion.
Oh, please. How do you quantify "more responsive?"
Sorry to say this, but the witch-doctory of computer maintenance is not engineering, it isn't science, it isn't even common sense
If you get "thrashing" in your system it is because you don't have enough RAM for the applications you are using. At this stage, the application has one of two options, use user space files to reduce the "in RAM" data size or quit with an out of memory error. Most all applications, in this scenario, perform better when the OS provides virtual memory. (Obviously not all because the default swap algorithm can be a worst case, but I digress.)
The Macintosh's early virtual memory (pre-OS/X) and old OS/2 1.x virtual memory systems really created a lot of lore about the woes of virtual memory. The reality is that the modern VMMs as implemented in the Pentiums and later are very good, and the OS support for them are excellent, and a system is almost always better off with VM than without.
In an honest discussion it is hard to speak with absolutes, so no one can say any one way is any better than any other way 100% of the time, unless it is an obvious choice like drink poison or drink pure distilled sterilized and safe water in moderate amounts when you are thursty and have balanced electrolytes.
That being said, unless you have a specific and quantifiable case where virtual memory hurts performance dramatically, use virtual memory, you will be better off.
1. "As much swap as you're ever likely to use in your environment." Which involves watching your swap usage over time and optimising it accordingly.
2. "1GB of swap per CPU". This was told to me by a Solaris admin, and I'm still not sure what he meant by it. Solaris is particularly good at handling swap dynamically, however.
Personally, I always assign double the RAM on the machine and have yet to run into problems. On my 2Gb VMWare box I hit about a 2Gb charge when all 4 virtual machines are hammering away nicely, with little or no slowdown (some more physical RAM wouldn't hurt a bit though, I expect). The extra 4Gb is there if something really silly happens.
The point is, the machine has 300Gb of drive space... if I wanted more swap I could easily add it. Drive space is cheap, why risk losing a production machine to something daft like a runaway process?
> Or to put it a third way, is there any situation where swapping is helpful, anymore?
Sure. As a programmer of IC CAD software I have some experience here. Our tools use large datasets: allocating 8GB is common. However, the tool uses only smaller amounts of data at a time: for example, there are four functions each using only one 2GB data structure. When they are all called sequentially, you need only slightly more than 2GB of ram. Swapping now only causes a small hickup when switching from one datastructure to another, but has hardly any other penalty. But it allows now much simpler software design, just let the OS handle the complicated stuff instead of saving the data yourself to tempfiles. And you save lots of money by needing less ram.
networked swap drives, what will they think of next!
A guilty conscience means at least you've got one.
Winblows machines:
Home desktop, internet machine - 1 to 1.5 times ram
Medium duty workstation - 2 to 2.5 times ram
Heavy duty workstation (CAD, M$ Developers, or my case just a RAM pig) 4 times RAM
Server(s)
I like to set them up with 2 swaps
first = 2 times RAM per processor on primary partition / primary drive (BSOD dumpable)
second = 4 times RAM per processor on primary partition / secondary drive
Linux Machines
2.5 times RAM for workstations
4 times RAM for servers
-- I am the NRA, enough said...
... here's what I'm currently experimenting with:
(coming from a 256M system, and moving to a new build with 2G, win2k pro & Ubuntu 6.06 on the machine currently)
For Ubuntu (Linux kernel v. 2.6.16) I went with a 2G swap partition, or a 1:1 DRAM/VM ratio.
For win2k SP4 + all post SP4 updates: I'm currently just letting windows manage the VM space. On the old 256M machine, I went with a fixed 3x DRAM VM pagefile.
Caveats: I've only recently moved to this system, and have NOT stressed them to any real degree with fully memory intensive operations. The most stressful application that has been to date on the new build has been Oblivion under win2k. The max pagefile use in those conditions have been c. 385M of pagefile use, however judging from performance that space was not being actively utilized(i.e. didn't notice alot of extraneous swapping going on judging by disk activity and pagefile usage growth(none).)
Under linux, I can't really thinik of anything that I utilize it for that would require vast amounts of memory ATM, although I may examine building of new linux kernels and gcc from source. I expect that gcc build would be the most demanding, but suspect that, that may not even stress a system w/2G. I have no large databases or a way to generate enough use artificially or otherwise(or time or interest ATM really) see what would happen, but I strongly suspect that a swapfile around the size of physical memory may be enough, especially on systems with even more memory as undoubtedly the idea in those situations was to minimize swap space use to avoid thrashing, or even more low level swapping activity...
Back in the day VM was great as disk space was much cheaper than physical RAM, and large VM swapfiles/partitions allowed us to run applications that may not have been able to run before. Most of these same apps now run on machines with MUCH large physical RAM installations, while using not very much more physical memory than before meaning that they can run directly from RAM which is significantly faster than swapping under VM. It would seem the best strategy is to allocate some(I like the 1:1 ratio) as applications will still allocate large amounts of space most of which will be allocated from the VM pool(reducing physical RAM size) while still avoiding swapping. In more limited(#/size of apps) systems you could probably even turn off VM, although I really don't think that it would gain you much, and each running app would have a MUCH larger physical RAM footprint as all of it's requested memory would have to be from the physical RAM pool...
i.e. babbling aside, you'll need to do some experimentation likely with a worst load case scenario and see what sort of configuration works best for you AND how much disk space that you can AFFORD to allocate to swapfile usage. Another potential idea would be to look at limited embedded systems which just don't have large amounts of storage OR physical RAM and see what happens with those, as most embedded systems with linux that I have seen usually don't even have a 1:1 ratio of RAM & VM, usually it's a very small VM space with RAM that is several times that amount, of course this gets a little fuzzy as most embedded systems don't have anything other than some sort of RAM(flash, static, etc.).
http://www.newegg.com/Product/Product.asp?Item=N82 E16815168001
And you're set. I don't think you can get over 2GB on this model though.
I assert ownership of all trademarks and copyrights on this page.
And is 1000 times faster ?
So, to answer the original question :
Optimal amount of Swap ? 0 !
Even my old PIII 1Ghz takes 2 gigs of ram. Newest system we have at the office takes 64 Gigs.
=> right now I consider the Linux systems @ work as having a problem if they use swap...
Adding just a wee bit of RAM to your system and seeing swap disappear means your perfomance just exploded on this particular task...
Best Regards,
D.
It takes 40+ muscles to frown, but only four to extend your arm and bitchslap the motherfucker
http://tinyurl.com/eqncw It's an old setting, not for XP for starters, and it's not very useful on the OS it's intended to be used with.
I am, and always will be, an idiot. Karma: Coma (mostly effected by
The alternative is to use your harddrive light as the monitor. But who ever sits there watching their hard drive light?
It's a simple matter of complex programming.
Depends on what the systems runs and how long between application restart. I've seen crappy inhouse apps that initially only use 500m or so but if they run long enough they will use all available swap (4-16gb) due to memory leaks. A restart of the app fixes the issue but if it isn't caught you get a hung server (generally at 3am in the middle of REM).
Generally app servers need swap>=phys memory whilst db servers are around 25% of physical memory as we have oracle/sybase servers with 96gb of ram. When we had *nix workstations they were generally 4 times physical memory but this was 128mb days.
So I would say depends on what you're running and how long you want to run between restarts.
what is a reasonable size for swap these days?
Reasonable limits aren't.
Demand always outstrips expectation, be it phone exchanges or IP addresses. What may seem like a reasonable limit at one time can prove to be too constraining in the future. That which is reasonably large at present will prove to be unreasonably small in future. So make it unreasonably large at present and you just may find it reasonably large in future.
Though a system that can expand without limit upon demand is ideal.
Oh, say does that Star-Spangled Banner entwine / The myrtle of Venus with Bacchus's vine?
What's with the standard help questions here today? C'mon guys- this is basics of system tuning.
It all depends on your purpose of course. The amount of memory, what is running, etc.
Windows requires virtual memory and still advises 2-2.5x sized RAM. Right now my 1GB of RAM windows machine has 200MB of physical memory free and 800MB of page in use while doing next to nothing. It depends on the number of programs you have in use, memory requirements of the programs and so on. If you are doing video editing with minimal RAM or using advanced photoshop plugins, up those figures. If you are running notepad exclusively, reduce them.
Linux runs fine with zero, but the question becomes would you rather your system start killing processes or swap things out to disk if it does get a burst of memory requirements. But there's more- it will slow to a crawl if you get that spurt and start using swap.
The formulas don't always work. A database server should ahve more memory and less swap. A workstation vice-versa. What happens if you increase memory on a database server to 16GB- should you make your Swap 40GB? Hell no- by the time you use any of that your system is fried to a halt anyway. On windows it has to be at least 16GB, but that's about all I'd do. On linux, a few GB to give it some room.
Look at your own systems' needs and make a judgement. There is no right answer.
-M
Absolutely. We have a server that processes images uploaded by our customers. It has 4GB of RAM, which is plenty for 99.9% of the workload. Every now and then, though, someone will send a really huge image our way. In those cases, we'd much rather throw some swap at the problem - even if it temporarily degrades performance a bit - than tell that customer that we can't process their work.
Swap isn't for normal circumstances. It's for the unusual situations that you can't really plan for in advance, and is the differences between doing a job more slowly than usual and not being able to do it at all.
Dewey, what part of this looks like authorities should be involved?
Before I started this I didn't care about the answer, but now I realize that this question is as important as "Ultimate Answer to Life, the Universe, and Everything" and as I read I have realized that we humans are not powerful enough to answer this question. We should build a super computer with more VM and VA and more processors, yes, then we can ask it the question.
Just kidding all, but it was good reading
I'm SURE they meant the address space - they not only pointed out the kernel option possibilities, they also explicitly said a "32bit" machine. A 32 bit address space is exactly 4Gi addresses...
If you need it, being able to use more than 4GB of RAM is the single biggest reason to get a 64bit machine - and shipping from Apple with 8GB stock for only like $10k was one of the great things about the original G5 towers, years ago. (Obviously this was loads cheaper if you bought third party RAM - the vast majority of that price was Apple's RAM markup. But, that was still cheap for a machine actually shipping with that much)
Looking for freelance Actionscript (Flash/Flex) or ColdFusion work and/or freelance developers. Email me, put Slashdot
Lol
"it has built-in performance monitoring for you! When the system crashes or starts throwing weird errors or denies you running new programs, etc... then it is telling you "time for more RAM"."
True, that is why I still give 1 gig Swap partition to the systems, so I have some time for the replacement ram to get in.
but my memory monitoring system is quite simple : if swap used > 0, mail the admin.
"But who ever sits there watching their hard drive light?"
Be carefull...This is slashdot after all ! 8)
It takes 40+ muscles to frown, but only four to extend your arm and bitchslap the motherfucker
My own perspective is from UNIX servers. As I keep telling people any use of swap/paging spaces is bad for performance so the ideal solution is to add RAM. That's not always practicable, so the real answer to how much swap space to allocate is "enough".
I still get software suppliers, (mostly SAP AG) moaning that we've got to allocate 3.5xRAM, which is arrant nonsense. It might have been necessary years back when 2GB was a lot of memory. Now I've got servers with 10s of GBs and I really don't want to waste 100s of GBs of disk on swap space which simply isn't going to be used. Sure: disk is cheap but it all adds up. One of the larger servers I support has 128GB of RAM and 32GB of paging space, (only 1% is actually used at the moment). A few servers like that and you're saving TBs of disk space.
Of course, if you're going to keep your swap space to a minimum you need to have good monitoring in place so that you can extend it before it becomes a problem if something unexpected happens, and it's sensible to be a bit generous about it. We do occasionally have problems when processes suddenly start writing vast amounts of data to memory but I doubt that having loads more swap space would help in those cases, as there are usually bugs in the code. Fortunately root can usually still get in, (if you're patient), identify the offending processes and kill them.
It also helps to have an OS that makes effective use of memory. What I know best is AIX and a few years back, (quite a lot of years in IT terms!) the memory allocation processes were changed so that even if you requested an enormous amount of memory it wasn't really allocated until you actually started to use it, (i.e. put some data in there). That made a considerable difference. I would expect any modern and efficient OS to do something similar.
Paging can be dreadful for performance as you get a multiple hit: the process that needs swapped-out pages runs slow as it waits for data to be paged in; your system as a whole also runs slowly as CPU cycles are taken up servicing the paging requests; your I/O subsystem suffers as it spends time reading and writing to/from paging spaces rather than actually doing useful I/O. It's one of the first things I always target when I'm investigating performance problems on a server, just as it was a couple of decades ago when I was doing the same things with MVS.
I'm the guy in charge of this sort of decision on a network of about 1,200 computers and our policy this year is to set _ALL_ Windows boxes to a fixed 512MB pagefile. If someone is actually USING that much swap, I _WANT_ them to crash and have to call me so I can order them more RAM. So far the only time this has happened was in the computer lab that has Maya.
If you're actually swapping out more than 256MB in this day and age, if you actually are executing from swap... It's time to buy more RAM.
"Sometimes, I think Trent just needs a cup of hot chocolate and a blankie." -Tori Amos on Nine Inch Nails
For Windows XP the geniuses at Microsoft removed this ability and the whole system runs much worse because of it.
Every time you do something which reads big files from disk on XP all your apps get paged out to disk. I don't know in which fantasy world this is supposed to be an "improvement", but it's one of my favourite reasons to hate XP.
No sig today...
We've found that 512 Megs of swap is more than enough for our 2 and 4 Gig machines. Why even have swap? Here is an example:
1) On a system with zero swap, when apache gets slammed (say you get to the top of digg or slashdot), apache starts consuming lots of memory to handle new inbound requests. When it runs out, the machine grinds to a halt because it can't allocate more and requires a power cycle. (Setting a low max children really only helps if you are happy denying traffic to the people who are trying to see your site...it's best to plan for capacity and put quite a few servers load balanced).
2) On a system with any appreciable swap (IMHO, more than 128 Megs, up to 512 Megs), if you're monitoring the system (watch -n 1 df -h, for example) and all of a sudden it starts using swap, the machine is on the edge of dying. This gives you an early warning that maximum machine performance/throughput is occurring. You can restart apache or shut it down or similar, you can do something to temporarily lower or remove load from that machine. This doesn't give you *much* time, but it gives you some.
In our real world experience, at digg and slashdot loads you have about 10-15 seconds to stop apache once it starts swapping. After that, the performance degrades so bad that the machine becomes catatonic, the same as #1, requiring a power reset (obviously because virtual memory on HD is magnitudes slower than RAM, as numerous others have suggested). The key here is that you must realize that some swap is good for allowing unused programs to be swapped out, such as login terminals that just sit there. It's great for detecting problems, but if your heavy app is the one utilizing swap, your machine is about to crash anyway.
I think most people who think that swap should be in terms of multiples of physical RAM are missing the point.
How much swap you have should be related to the longest you are willing to wait for stuff to be swapped in and out.
Adjust your swap so that your computer is as slow as you can tolerate when it runs out of memory.
For example: if you have a typical ATA drive, random read transfers would be about 10-15MB/sec. So if you ever need to swap in 400MB of stuff, you'd have to wait about 30-40 seconds before all of it is read in.
What complicates things is there are some applications/programs that allocate memory that they will practically never use, so you'd may want to add swap for that.
So the swap amount would be something like: total swap = "permanently swapped out unused stuff" + (seconds willing to wait * random read speed).
Of course virtual mem doesn't really behave exactly like that - when you are low on RAM the computer will be continously reading the program it needs in, while writing the stuff it thinks it is less important out, but basically you're kind of reliving the old days of "drum/disk memory" - where you running stuff from drum or disk. And that's really slow.
The problem with running out of memory is that under some conditions some operating systems (e.g. Linux) can mess up and kill the wrong process to free memory. I think this has improved somewhat - but Linux used to be pretty stupid and kill pretty important stuff...
This is mainly because of the default overcommitting of memory. With overcommit, the O/S can say "fine" even if there really isn't enough memory, but when it turns out you really do need it all, the O/S goes around looking for stuff to kill...
If you turn off overcommit things can become safer, but you'll need enough memory to hold all allocated memory even if unused.
...of any good tutorials and such on how to properly resize a swap partition in Linux? I am running a Mandrake 10.1 box right now, and while I have no real problems with it, I am pretty sure when I set it up I made the swap undersized, and I would like to increase it (I have 512MB, and I think my swap is either that size or maybe even smaller - I have yet to notice an issue, though). Whether using a GUI tool under X or using the CLI is fine with me, just as long as I understand the process and don't muck up my system...
Reason is the Path to God - Anon
Ok, I was the one asking this, so I see that I should have clarified:
first, I was talking about a Real o/s (*nix), not WinDoze.
Second, the thing that I was worried about is thrashing. As someone mentioned in their post concerning the difference between page space and swap space, page tables, that address the swap space, grow as well, and the lookups, no matter how efficient, start bogging down and adding overhead to the swap. For such reasons, too much page space can be as bad as too little.
So, with that, I'd like to single out
Junta (36770)
Anonymous Coward (I use this)
edward.virtually
and especially
Anonymous Coward (Read (Please!))
for their thoughtful and useful discussions.
mark
SysInternals.com has a free utility that defrags windows page files and registry hives, called PageDefrag.
SAP http://www.sap.com/ suggests (really, requires) 3x memory + 512MB for swap.
Every time I fire up my development system with 2GB RAM, I see it swap. The program is a monster and requires much memory.
Best bet is to consider the application you're planning to run. For example, if you're a video editor, you may frequently deal with files in the gigabyte size range. You may wish to use the 2.5x RAM in that instance. A business desktop user wouldn't necessarily need that much swap.
Personally, I have 1GB in my laptop and I use 2x RAM for my swap. Yes, I've made it swap before....I was really trying.
"Lame" - Galaxar
I recently attended IBM's "Performance Tuning with AIX" course. It could basically be summed up as "Don't Use Paging Space. Ever." Then it went into lots of detail about AIX memory management techniques and the VM subsystems, with a brief foray into network performance.
It is a very sickening feeling to go and power-cycle a production system which is completely halted due to running out of memory. Almost as bad is a system which is hitting the swap and responding like molasses.
Look at the work you need your server to do, then put the RAM in it you need to get the job done. I've not worked with Linux in a full-on production environment, but I will go look into its systems for dealing with OOM errors. I'm sure it will be interesting.
-- Flaw
In laptops! There's actually some work being done to use flash as a hard drive cache. If it works, keeping system memory small and using more flash (with paging) could potentialy increase battery life.
Also, remember that 2GB of RAM in a laptop can be very, very, very costly.
No, I will not work for your startup
I never thought anyone could make Windows 3.x memory management look good (even by comparison), but you just did...
Sorry for the ugly formatting, but you get the idea. Only 256M RAM and the same size swap and I'm not touching swap. I have OOo-calc running, and fairly large compile going, and a few other minor things and that's my stats.
I'm not a prophet or a stone-age man,
I'm just a mortal with potential of a super man.
Which process is killed?
...
With the Linux OOM killer, the answer is "depends" - on how much accumulated CPU time each process has, how long it's been running for, who owns it, who its chlidren/parents/siblings are (and what they've been doing), the phase of the moon,
These days, with a current Linux kernel, the only reason for swap is to page out data pages (executable pages will be just dropped and paged-in again from the original binary on disc) in order to leave more room for disc cache.
Finally, disc is cheap these days, and re-partitioning can be a pain if one adds more memory later, so these days, I usually just make swap twice the maximum amount of RAM the system can accept.
Fedora Core 6 test 2 packages it as 64-bit.
About the only 32-bit thing left, besides libraries, is grub.
The first question is a Windows question. I read a long time ago (in PC World, I think) that the min/max pagefile/vm should be set to the same amount because Windows constantly resizes a swapfile that has a variable size and takes a lot of proc/hd/mem juice while doing so. Is this still true?
The second question is for Windows and Linux. Does having a too-big swap file allocated cut down on performance or is the only downside the excess hd space it uses?
Read my blog: HansMast.com
Yes ram is incredibly cheap, and any amount of serious swapping is to be avoided. On the other hand, once in a while you do something stupid like having VI load a 2GB log file into RAM, or whip firefox into an 800mb frenzy and then load that 16kx32k image into GIMP, or do that database query that uses *way* more ram than you'd expected.
In general, I'd rather have my system slow to a crawl than blow up in my face when something like that happens. At least, then, I've got the choice of what I want to kill/stop, rather than having random (critical) processes die on me and have no choice other than a post mortem.
If you're that worried about your system slowing to a crawl when you start eating into swap space, then put instrumentation onto the system that alerts you when swap gets over 100MB. At least that way, you keep uptime and some hope of a controled recovery. With the price of hard disk storage being what it is today, it's not having a few spare gigabytes of backup VM resources that seems like a bad idea.
Sometimes boldness is in fashion. Sometimes only the brave will be bold.
1) none. Except in unusual circumstances, there is little reason to actually use your swap and you take a huge performance hit for using it.
2) Lots. You may never *need* your swap but at around 20c/GB, it is pretty cheap insurance.
I seem to recall that some older Unices and/or apps required that you had some swap even if they never used it---probably no longer the case. Plenty of swap can also keep a leaky app running much longer than it would otherwise at very little performance cost.
bottom line: in a regular desktop system or fileserver, I would go 2GB. In a laptop or minimal system, I would allocate enough to bring my total RAM to 1-2GB depending. Then there's the special cases...
The correct amount of virtual memory is: whatever you need.
Seriously, you ought to have enough RAM that you don't need to swap, saving that, enough to minimize it. So, use more swap that you think you will need at maximum demand. That's it.
Just enough time to fix things if a process decides to eat the computer without warning.
Some OS's coredump to swap, so having swap >= ram is essential if you want to analyze the coredump. Depending on the OS you may need some other partition to be capable of holding the dump as well (e.g. wherever /var/crash lives on Solaris).
But yeah, depending on swap for running processes isn't generally very good.
neat!
*takes a picture*
Did you know that "FTW" ("for the win") is a direct translation of "Sieg Heil"?
I do tech support for schools and RAM in the PC's has increased exponentially with
every rollout. We now have software which won't run because it's checking the virtual
memory size, not using enough bits, and thinking there can't be anything larger than
512mb. Every PC that has to run certain software has to be configured to have a swap of 512mb
or we get an error saying 'I need more than 3Mb of RAM' or 'I need more than 6Mb of RAM'.
This is Macromedia Director Player stuff, obviously not future proofed.
In short - If you've got more than 1Gb of RAM and you're not swapping, you don't need a swap file.
It's up to the OS though, isn't it. It should be more intuitive and realise this itself.
How about dynamic swap files that guage the amount of RAM. amount of free HDD space, and do
their own thing dependant on if they actually need to swap out.
I can see the gotcha - need to swap and no HDD space. Happens already, go with the already coded
stuff, or swap more frequently with less HDD space and warn the user HDD space is low (or get more RAM).
You should have enough real memory in your computer to cover the working set of your programs. round up.
Then, as a safety margin add swap. More swap = larger safety margin. 2-3 times memory is still sensible. However, as VMs are more flexible today. both 0 and 10x are possible and sensible choices for certain scopes.
The swap should cover for some memory leaks, cover for extraordenary situations, and buy you some reaction time.
Swap will buy you some speed with some server applications. Swap will always buy you safety and uptime.
If you can, disable overcommit and add more swap for increased safety.
Some swap space _use_ is OK. (and normal for a system with a long uptime.)
However, if your computer are activly writing/reading to your swap space (more than 1% of I/O capacity) thats a sign you already are late in ordering more memory.
I do - any time I'm running Mozilla with a lot of tabs open and it decides to go into annoying-swapping-mode (on WinXP and predecessors) for no obviously good reason, so I've got to wait for Mozilla to swap itself in or out before I can see the web page or other application I want. It doesn't help that I mainly use it on a laptop, where the drive is slow and the RAM is a fairly large 384MB, but it also happens on my home desktop, where the drives are faster and there's 640GB of RAM, which ought to be enough for anybody.
Bill Stewart
New Fast-Compression-only CPR http://preview.tinyurl.com/dy575ks
So, when building a machine, I typically include a single swap partition equal to the amount of RAM plus 96MB or so. Disk is cheap, and the ability to diagnose panics can be extremely valuable.
Note: This has worked well for FreeBSD 4.x, 5.x, and 6.x.
...For Chuck Norris
The Kruger Dunning explains most post on
Look, disk space is nearly free, and disk drives are Big Enough these days that you can waste however much space you need on swap. For a production environment, you don't want to waste time swapping unless something really requires it, in which case you should make sure to have all your application needs. (In an interactive server, you can play around and add swap files if you find you really need them.) So build yourself a swap partition that's at least 2x RAM, or if you're running a database or similar application that gives you some guidance about wanting more, give it more. If you think you might want 8GB, build an 8GB partition; even if you build a 16GB partition on your 160GB disk drive, it's only 10%. If you find you've got a really strange usage pattern that wants less, you'll have room to shrink it.
16GB of disk drive costs $16, or maybe $32 on some blazingly fast Ultra-SCSI 15krpm drive. As they used to say on Usenet, your posting costs the net hundreds or thousands of dollars; you've probably spent more than $32 of salary in reading the responses and thinking about them, and you'd certainly waste far more than that by making a small partition and having to resize it to larger, whereas making it too big and then shrinking it or turning it off entirely is much less trouble.
The real question is whether you need to put your swap on a separate spindle, or on something fast like Flash. (Yes, I know that flash has limits on how many times you can write to it, but those limits are a lot higher these days than a couple of years ago, and if $100 for a 4GB flash stick lasts you a year, you've probably saved a chunk of money compared to buying a faster CPU or more RAM or more electricity for the rotating disk drives or for the opportunity costs of making users wait. It's especially useful for reducing power-up time, though of course you're not going to have typical servers go into laptop-hibernation mode.)
Bill Stewart
New Fast-Compression-only CPR http://preview.tinyurl.com/dy575ks
But it's nice not to have to swap at all, if you've got enough RAM, and there are applications and OS's that do a lousy job of managing virtual memory; sometimes you're better off with none (e.g. if the thing's going to memory-leak anyway, then it'll use up all your virtual memory just as easily as all your RAM, so you'd be better off letting the thing choke and die early.) I get really annoyed when I'm running Firefox on Windows with lots of tabs open - if I need to do something else, and then come back to Firefox, it acts like it's decided to swap the whole thing out and needs to swap it all in again before it'll show me any pages, which is just Dog City.
On laptops, you may need enough swap for hibernation to be able to store anything, unlike desktops where there's usually no need to be that aggressive about energy-saving, so maybe you want to have, say, 1.1 - 1.5x as much swap as RAM so that it'll be there if you need to hibernate but won't waste too much time swapping otherwise.
Bill Stewart
New Fast-Compression-only CPR http://preview.tinyurl.com/dy575ks
Thank you, thank you for not saying 'this begs the question'.
That is all.
Graham "Teach" Mitchell, computer science teacher, Leander HS
I'm sure you know you can assign priority to swap. When you use the same priority on swap, it behave like RAID0 (but size of partitions can be different). So piles of old disks can beat one modern disk, because total sequential rate is sum of partial sequential rate.
I hate rebooting a server to fix a problem, on principle. Usually, if we've got a memory overflow I can still get in as root but it can take a very long time, (10 minutes+ just to get past the login prompt). AIX won't often crash through lack of memory. However, as a pragmatic choice sometimes it's quicker just to knock the server on the head and reboot than to spend ages trying to log in and kill the offending processes. Better for the customer to have the application up and running than to fix it "properly", even if you have to spend a little time on database recovery afterwards.
Terje,
do I recall this quote accurately? It sure has meaning today!
Zero. ZERO.
Zero swap. Buy enough ram, deactivate swap, watch your computer run as fast as it should.
Making laws based on opinions that stem up from false informations leads to witch hunts.
but it also happens on my home desktop, where the drives are faster and there's 640GB of RAM, which ought to be enough for anybody.
:-)
Whoa, you have 640 GB of RAM! I am jealous!
Hey, there is only one Return and it's not of the King, it's of the Jedi.
Er, yeah, so it was 640MB. Either way, it ought to be enough for anybody....
Bill Stewart
New Fast-Compression-only CPR http://preview.tinyurl.com/dy575ks
Regarding:
_______________
-->My strategy generally is to use a file for swap rather than a partition, even in linux.
What I find curious is that you have a strategy. On what relevant experience do you base this strategy? 1 GB of disk space costs less than $0.50. Set up 3 GB of VM if it makes you feel good. The latte you drink while you set it up costs more than the extra disk space!
So go for it!!! Who cares what you do? Heck, give yourself 10x the RAM and see if it actually makes any difference!!! (it won't)
_______________
I have a strategy and I care. I have some 50+ rather individual servers to maintain including constant builds, upgrades, etc., etc. so even a small amount of additional administration overhead is significant (not the disk space which I agree isn't significant).
I prefer to use swap files rather than partitions on my Unix servers (Linux and FreeBSD almost entirely). For me the main difference is that I can have an initialization script (e.g. cfengine driven) set up and even "re-up" swap files automatically vs. setting up a swap partition at build time. My "kickstart" mechanisms aren't as carefree in terms of setting up and managing swap partitions. Since I can't recall the last time anything actually swapped on any of my servers (years ago and just before a crash anyway), I don't think swap makes much difference, so I optimize for the time I have to put into getting it into place - by dealing with it in an automated initialization script and keeping it out of the issues related to partitioning the disks.
Oh heck no! Load balanced servers SUCK like Scooty Puff JR. My hosting provider has never been the same. It was much better and faster when they just let servers crash. As now the folks hogging up all the bandwith screw us all like in a pyrmid scam. They not only over load their rack server but them all. load balancing is a suckers pyrmid scam for bandwith hogs.
I never use swap (for about six years) and had a 256MB ram machine with win98.
Thing is i run into out of memory errors,when running alot of stuff,though rarely(windows takes 35MB by itself here).Now with 512MB i could run practically anything.
My advice:Turn off swap,buy more ram.
You are right about Linux systems and Swap, but I still allocate at least 20G of swap to my AMD/Intel systems.
Think of it as your window of time to find and kill that runaway process.
and
Hey...the DB guys just added in annother environment without letting anyone know.
_Using_ no swap is the ideal for performance,
but
_Having_ swap is nice if you like to sleep.
That plus, if the users never suffer, they take you for granted.
F X=0:1:9999 F D=2:1 Q:((X>2)&(X#D=0)!((D>X/2)&(X'=1))) I D>(X/2) W:$X>75 ! W X,?$X+5-$l(X) Q
I suggest using between $10 and $15 worth of disk and then never worrying again about it.
((lambda (x) (x x)) (lambda (x) (x x))) http://www.endpointcomputing.com a scientific approach to custom computing.