How Big Should My Swap Partition Be? 900
For the last 10 years, I have been asking people more knowledgeable than I, "How big should my swap be?" and the answer has always been "Just set it to twice your RAM and forget about it." In the old days, it wasn't much to think about — 128 megs of RAM means 256 megs of swap. Now that I have 4 gigs of RAM in my laptop, I find myself wondering, "Is 8 gigs of swap really necessary?" How much swap does the average desktop user really need? Does the whole "twice your RAM" rule still apply? If so, for how much longer will it likely apply? Or will it always apply? Or have I been consistently misinformed over the last 10 years?
What Has Changed? (Score:5, Informative)
'Is 8 gigs of swap really necessary?'
With a 750GB [newegg.com] hard drive selling under $100, what has changed?
... and 8GB of space is still trivial with a 750GB hard drive.
Yeah, your 256MB of space was trivial when you had a 30GB hard drive
That said, I'll forward you some common information on paging [wikipedia.org].
Linux and other Unix-like operating systems use the term "swap" to describe both the act of moving memory pages between RAM and disk, and the region of a disk the pages are stored on. It is common to use a whole partition of a hard disk for swapping. However, with the 2.6 Linux kernel, swap files are just as fast as swap partitions, although Red Hat recommends using a swap partition. The administrative flexibility of swap files outweighs that of partitions; since modern high capacity hard drives can remap physical sectors, no partition is guaranteed to be contiguous.
I'm no expert but the short answer to this is to look at your swap partition as your extended virtual memory. By saying that your swap partition should be 2x your main memory is like saying that you will never use 3x of what your main memory is (in this case 12GB). While that rule of thumb is a good one, there may in fact be applications today in the graphics and processing world that require insane amounts of memory. While Firefox is probably never going to reach that critical mass (nor will most average programs) it's probable that a few years from now it will be common place. I know it's insane to think of but 'ought to be enough for anybody' is not the phrase you want to throw around in the digital information world.
It's those days when I'm playing Warcraft through wine, listening to streaming radio through Amarok, have 20 windows open behind it, idling a LAMP server for my development projects, running a vent client, some form of news aggregater, pidgin & an e-mail client hooked up to several POP3/IMAP accounts that I am happy I erred on the side of a whole ton of swap space.
Definitely not twice... (Score:5, Informative)
The origin of the 'twice real RAM' came in the early days of windows, in which windows could not use any swap unless you had at least as much as real RAM. That's been gone for ages now - and you should actively avoid too much swap.
If you allocate, say, 8G of swap for 4G of RAM, most of the time almost all of it will go unused. If it actually /is/ used, your machine has probably spent the past hour or so frantically swapping to try to accomidate this 12G request; ie, your system is completely unresponsive due to every program being mostly swapped out. The additional swap merely delays the out of memory event, and in the meantime you can't control the machine.
Swap is still useful for holding data that's not part of the working set, in order to free memory for cache; but this shouldn't be very much RAM (256-512mb should be enough). It's also useful for software suspend on linux - if you have a laptop, make it a little bit larger than physical RAM. And always have /some/ - linux's memory manager doesn't like having none.
What Oracle Wants (Score:5, Informative)
If you were running Oracle - here is what they recommend:
RAM -> Swap Space
1 GB - 2 GB -> 1.5 times the size of RAM
2 GB - 8 GB -> Equal to the size of RAM
more than 8GB -> 0.75 times the size of RAM
I don't know if this would carry across to general computing - it seems to me if it's enough for an Oracle RDBMS server, it ought to do it for most things.
More sensible suggestion... (Score:5, Informative)
Reading through OpenBSD's FAQ:
"The 'b' partition of your root drive automatically becomes your system swap partition. Many people follow an old rule of thumb that your swap partition should be twice the size of your main system RAM. This rule is nonsense. On a modern system, that's a LOT of swap, most people prefer that their systems never swap. You don't want your system to ever run out of RAM+swap, but you usually would rather have enough RAM in the system so it doesn't need to swap. If you are using a flash device for disk, you probably want no swap partition at all. Use what is appropriate for your needs. If you guess wrong, you can add another swap partition in /etc/fstab or swap to a file later."
HTH.
Just test? (Score:5, Informative)
I imagine different people will need different amounts of swap space, so use a size that's right for you.
If you need crashdumps, same rule applies (Score:5, Informative)
If you're debugging your kernel or are helping people to debug your kernel, and are generating crashdumps either manually or as a result of kernel panic, you need your swap to be twice as big as the memory so it all fits comfortably (You can probably get away with X times bigger, where 1X2, but 2 is a safe number).
To my understanding that's always been the reason for the rule of thumb about doubling the memory. If you can afford the disk, go for it, because you never know when you might hit a panic and need crashdumps. If you are in a live environment and are sure you will never, ever need or even want crash dumps, and the disk space is at a premium, you can size it based on need.
Another thing to keep in mind is that as you have more ram, you have more pages, and the whole point of swap is to get pages to disk as well in case you need to free up physical ram quickly.
256M (Score:2, Informative)
If you need more than like 512M of swap, you need more physical RAM.
Seriously though, maybe like 10% of your physical RAM; but if you reach a point where you need to access a lot of swap in a short time (say a graphics intensive program, or a Web browser that has 2 gigs relevant data in swap), your machine will slow to a crawl.
This is why I use like 128M swap and swapd on Ubuntu.
It Depends, but at least as much as RAM (Score:5, Informative)
Oh, nonsense (Score:4, Informative)
2X RAM was the standard rule of thumb at Sun, for SunOS long before Windows was around.
If anything, Microsoft ripped it off from Sun.
Re:What Has Changed? (Score:3, Informative)
Now, if you suppose that someone has 4 GB RAM and a 750 GB drive, they'd be using 8 GB for swap space, which represents about
HOWEVER, if you look at smaller drive sizes, which are still common in the modern day -- I know plenty of people who just use 120 GB or 200 GB drives; not everyone likes all their eggs in one basket.
8 GB swap on a 120 GB drive represents about
Just some thoughts.
As much as you think you'll need (Score:3, Informative)
How big should my swap be?
It really depends on what you're planning on doing with the machine:
It really depends on what you're doing. A simple firewalling machine will never need to swap. Low trafic websites and mailservers will probably hardly ever need it.
Also, you can always add swap later if you resize another partition. It really isn't that much of an issue, so pick a value and adjust according to your needs.
Re:None (Score:5, Informative)
Well, I do occasionally need more than 2GB of RAM, without there being a memory leak. I've been running GIS programs, an IDE, a couple of RDBMSs, and then I fire up the old compression program...
Which brings me to my point. The question "how much swap do I need" is probably meaningless, even for a given amount of memory. There are people who find 2GB with no swap fine, and others, like me, who probably could get by with 2GB of RAM and maybe 512MB of swap, and others who might need more.
I think the 2x RAM rule of thumb has one virtue: excepting certain exotic kinds of systems, it's fairly safe that anybody who finds themselves needing more than that is probably feeling a world of pain that can only be fixed by getting more RAM. On the other hand, in most cases 2x RAM amounts to a trivial amount of disk. Probably most people could get by with 25% of RAM, but the value of thinking about whether that is true for you is very likely less than the cost of the disk space.
Common sense applies. If you have some kind of scientific computing device with a gazillion bytes of RAM, your swap requirements might not be related to your maximum RAM requirements at all. If you're running some kind of operating system that launches a bunch of rarely used garbage, you probably ought to think about your swap. I had awful problems with Vista until I figured out the page file Windows created had something like eight thousand fragments. I was actually better off getting rid of the page file
Re:It Depends, but at least as much as RAM (Score:4, Informative)
Yeah, hibernate actually DOES mean "use no electricity". Perhaps you mean "suspend"?
Re:What Has Changed? (Score:4, Informative)
i assume you dont hibernate, thats the only reason i have 1x my ram in swap. Although using something like "hibernate" instead of ubuntu's tool will happily compress it so i could really get away with about 60-70%
Re:For Suspend to Disk more than actual RAM (Score:3, Informative)
For built-in suspend this is true. TuxOnIce [tuxonice.org] offers, among other things, suspend-to-file support which eliminates the need to keep gobs of swap around if you don't want to.
Been There Done That... (Score:3, Informative)
I have made hundreds of swap partitions for OS X, AU/X, Windows, Schmindows, and just about every flavor of Unix I came across.
I would advise...
For Windows, load Process Explorer, and look at the Commit Change Peak RAM. Nice...
Now load a browser, a word processor, and Acrobat. OR Load the game you want to play.
Make the partition the size of that peak RAM+10%.
Make the swap size, the larger of the system cache or the minimum peak commit change. ( There is a brilliant trick here, but Id have to kill you...)
System 1:
1024MB ram.
Peak is 70%.
Swap partition is : 1916Mb, 64K Clusters.
Swap file size is : 512~1668Mb
Swap file size on OS Partition is 2Mb.
( Someone warned me about this, and I actually listened. Sure has helped when imaging drives )
More Later...( It gets trickier for smaller ram values...) I am working on a 512MB system, a 384MB system, and a 256MB system.
Re:What Oracle Wants (Score:3, Informative)
for a server thats probably about right, on a desktop where stability is not quite as important id go with about half that
That's not the point of swap space. (Score:3, Informative)
The point of swap space isn't to kick in when you run out of physical memory. The point of swap space is to allow the kernel to make use the most efficient use of your RAM, by swapping out the contents of infrequently accessed memory pages, and putting that memory to better use, like caching frequently accessed disk blocks.
If you have no swap space at all, any memory pages that your processes are hardly using have to stick around in memory forever, even if you'd get better performance by swapping the contents out and using it for caching disk blocks. So seriously, you should add some swap space, at least as much as your RAM.
Errr... check your math. (Score:5, Informative)
8GB swap on a 120GB drive is 7%, not .07%. On a 200GB drive, it's 4%, not .04%, etc.
SirWired
Re:It Depends, but at least as much as RAM (Score:3, Informative)
"Hibernate" does not mean "use no electricity."
Actually, "hibernate" is no different than "off" from an electricity use perspective. When you hibernate with Linux (or even Windows), the contents of memory are stored to disk and the machine is powered off just as if you had performed a normal shutdown procedure.
At this point, a hibernating system is using exactly as much power as a system that is off. For an ATX system this is not zero since the power supply has to provide some power for the on/off button to function as well as to power the USB ports.
Suspending your system, on the other hand, does use more power since the RAM must be continually refreshed, though most of the other components are off.
Re:What Has Changed? (Score:5, Informative)
There are better reasons than boldness for not using swap on an Eee. They use solid-state drives (except some 1000-series models and the 904), which are faster than mechanical devices but can be rewritten fewer times. To make sure your drives last longer, do the following [ubuntu.com]:
Sure, without swap and with tmpfs you will have less memory available, but I have an Eee 900A and I bought it as a presentation machine, possibly for some occasional work while travelling, not as a workhorse.
Re:Personal research? (Score:2, Informative)
Re:Forget the RAMx2 rule (Score:4, Informative)
Lower the amount of RAM Linux uses by changing vfs_cache_pressure to > 100. This will make the kernel dedicate less RAM for caching dirents (directory entries) for quicker lookups. For instance, to cut the amount of directory caching in half, double the pressure by doing:
'echo 200 >
HTH
Re:What Has Changed? (Score:3, Informative)
I'm not 100% sure, but I think firefox grays out when trying to crunch big script(s) - it might be pegging the processor, but I don't know for sure. I've been meaning to track down the issue, but have been too lazy to so far. If anyone knows the cause/fix, I'd love to hear it.
Re:What Has Changed? (Score:5, Informative)
Just killing processes more or less at random when the system runs low on memory is not a good idea. (I know it is not completely random, but there surely ain't any guarantee that it will make sane decisions). What you really want is for programs to get an out of memory error when trying to allocate memory, and then they can shut down as gracefully as possible. (Would be neat if the choice of who get the first ENOMEM was chosen by the heuristics that would otherwise kill the process, but I guess that has not been implemented). Guaranteeing that you will never need to kill a process because you are out of memory means the kernel will have to not commit to more than can be backed by memory and swap. However since actual usage tends to be somewhat lower than what is actually committed to, that would be a bit wasteful. This is the main reason why it makes sense to have a large swap partition that is mostly unused. Just so you have backing for the amount you need to commit to in order to optimally use the physically available memory.
You typically wouldn't want to make use of most of that swap. So once any significant amount start getting used, you'd want to start giving ENOMEM errors. And that should help ensuring that the swap will only be used for a short time. There are a few pieces of data in virtual memory that are only used under very rare circumstances, and those it is nice to have on swap so they don't take up precious memory. So the aim is not to have zero swap in use, just some low number of pages that are really not needed in memory.
Is there any kernel out there that gets all of this right? I don't know. But at least those I know about can be tweaked to do pretty well.
Re:What Has Changed? (Score:5, Informative)
For best performance, don't reduce your swap below the amount of RAM you have, unless you want to get rid of it entirely. The reason is that Linux 2.2.x and later will, when your disks are idle, preemptively copy your physical memory to swap - that way if you do run out of RAM, all Linux has to do is reuse that RAM for other things - your application's virtual memory has already been written out to disk. This can't work as well if the swap space isn't there for it.
With 2.0.x and earlier, I would have recommended you pick the amount of virtual memory you think you need, subtract the amount of physical memory you have, and set up that much swap. With 2.2.x and later, I recommend you pick the amount of virtual memory you think you need, and set up that much swap.
For what it's worth, Windows NT derivatives do the same thing.
Re:Definitely not twice... (Score:3, Informative)
Re:separate partitions for / and /home (Score:4, Informative)
Guess how many times I've thanked 8 lb 6 oz baby Jesus that I had the foresight to separate the two?
My guess: At LEAST three. :-)
I have three partitions on my system:
Home stores all my stuff, /usr/local stores all the stuff I download and build from source, and / is the stuff the distribution I use (currently Slackware 12.1) gets to muck with.
When I want a new distro, I can nuke and pave / with impunity, and depending on the age of things in /usr/local, they may need to be recompiled, and that's about all I need. Every now and then, /home and /usr/local get moved to a new, bigger drive, which is a lengthy, but fairly painless process. I don't clean out; I can't justify spending hours figuring out what I can purge and what I can't when storage is so cheap. I just buy a bigger drive, and the old smaller one becomes the new /. If the old system drive fails, it's no biggie. The new one gets its critical files backed up. If I lose it, there will be some pain, but I keep the "If I lose these files, I'd rather just die" stuff burned to disk, copied to my virtual server 1000 miles away, and on my USB keychain drive.
Multiple partitions FTW.
RedHat EL 5 documentation says.... (Score:3, Informative)
Arguably RH is the authority on the subject... See their documentation here [redhat.com].
-m
Re:RAM-based hard drive (Score:1, Informative)
They have this technology already
http://www.tomshardware.com/reviews/gigabyte,1111.html
Can't find the other product that actually fits in 5.25 inch drive bay, but it was 10x's the cost a few years ago.
I picked up 4 of these cards for $60 on ebay 3 years ago, and then sold on ebay for twice that each.
However these cards have battery backup, but this could be removed. =]
Re:What Has Changed? (Score:4, Informative)
How much Swap per RAM? (Score:3, Informative)
Oracle has very specific requirements/recommendations:
Our organization just bought 4 database servers with 32 Gb of RAM each. I personally setup and installed the servers. I told the DBA:
The DBA agreed with this, and we went with 8 Gb of swap. Haven't had any problems with the server or DB applications for more than 6 months. It is the most heavily utilized server in the entire organization.
For a laptop, I would set the swap to equal or more of the RAM, only if you want to suspend to swap. Depending on the applications, I would say at least half the amount of RAM to double the amount of RAM, within reason. If you have 8 Gb of RAM on a workstation, you probably do not need 16 Gb of swap for everyday use.
Re:What Has Changed? (Score:3, Informative)
Why would I want that? If Windows crashes, I want it to restart and quickly, not waste my time dumping memory.
Agree, but having a pagefile the size of RAM in Windows is not for crashes as the parent suggests.
Having a pagefile the size of RAM in Vista for example, lets the OS do writethrough to the pagefile, so when you hibernate, it is faster, as it is a snapshot that doesn't have to be written to the HD.
I only recommend this for laptop users that want that extra second or two of speed when sending the computer to hibernate though.
If you have 4GB of RAM, a swap file is not needed 99% of the time for most users with today's applications. The only exceptions is gamers running multiple instances of large games, or using applications that are dealing with multiple GB of data, then you should have a 1.5 to 2x RAM pagefile or more according to the amount of data you are processing.
Re:What Has Changed? (Score:5, Informative)
Base 2. Storage numbers using base 10 are for disk manufacturers that are filthy liars.
Re:What Has Changed? (Score:5, Informative)
Try it out, it's amazingly useful for debugging BSODs.
Re:What if we just got rid of paging? (Score:3, Informative)
Either your professor is an idiot, or you had no understanding what (s)he was talking about. /some/ swap is helpful because often you have data in RAM that you are not actually using, but is not file backed, so you can swap it out to disk and use that memory for something useful, like disk cache for your active set.
Swap is not the reason for paging. Memory fragmentation between programs is the reason for paging. Saying a program can't allocate memory because it has bumped into the next one, when there is a large amount on the other side is insanity. This is exactly like saying you can't write to a file because there is another file right after it on the hard drive. Paging has the nice side benefit of efficient swap (swapping out pages instead of entire processes).
Having
Also, all of those addressing steps are only needed on a full cache/page miss. If this is happening often, your system is thrashing. Think spending 10,000 times the time waiting for page loads than doing address look-ups, or more.
In any case, suspend to disk requires at least as much swap as you have RAM to store your suspend image.
Re:What if we just got rid of paging? (Score:3, Informative)
Swapping requires virtual memory. The converse is false.
All this scary PDE, PTE and other TLB stuff is what happens when a virtual address is converted to a physical address. That has nothing to do with swapping or paging.
Now, you cannot seriously consider abandoning virtual memory and all that comes with it (inter-process protection, kernel protection from user-space errors amongst others), can you?
My OS X installation... (Score:3, Informative)
has a dynamically grown swap file currently at 64 MB.
I have 8 GB of RAM and never page out even when I run dozens of memory hungry apps (photoshop, nikon capture etc).
The general rule is if you are swapping pages out when running typical apps you use daily, get more RAM.
Re:RAM-based hard drive (Score:2, Informative)
Re:What Has Changed? (Score:2, Informative)
If you find your apps leaking to the extent that they swap a lot, simply consider alternative applications, or at least reload them more frequently.
Re:What Has Changed? (Score:4, Informative)
Re:What Has Changed? (Score:5, Informative)
Pop quiz:
Throughput: How many bits per second peak can a 14.4kbps modem move? 1.544Mbps T1 line? 10Mbit Ethernet?
Disks: How many bytes are on a 1.44MB floppy? A 2.88MB floppy? A 650MB CD-ROM?
Answers:
Throughput: 14,400. 1,544,000. 10,000,000. Hmmm... so much for base-2 throughput numbers. And yet, when you see the "kB/sec" rate in your browser download dialog, that is most likely in a 1024 byte/sec quantities.
Disks: 1,473,560 (1440 * 1024, a mixture of base-10 and base-2), 2,949,120 (2880 * 1024, again a mixture), and 681,984,000 (purely base-2, derived from 333,000 sectors * 2048 bytes/sector / 1,048,576). And yet when you look at disk capacities from most computer software, it's reported as purely base-2 sizes.
So, what's consistent about this again? RAM seems to be the only thing that gets it right most of the time, though I do remember seeing plenty of adverts for Commodore 64s that listed them with 65K of memory back in the day.
And for the real brain bender: If we agree that bits should always use power-of-2 meanings and everything else should use power-of-10, what do we do when the two collide, such as when talking about areal density? (That's bits per square meter.)
That said, whoever came up with the names gibibytes, mebibytes and kibibytes must have wanted us all to sound like we have a speech impediment or something, as the pronunciation for these sounds worse than baby talk. I'll stick to saying gigabytes, megabytes and kilobytes and their understood power-of-2 meanings where it makes sense, knowing full well that it has deep flaws. It's just an unfortunate circumstance, but most of the time it thankfully doesn't matter.
--Joe
Re:What Has Changed? (Score:2, Informative)
The kernel could be made more efficient, and *many* drivers made simpler, if the whole concept of "page fault" ceased to exist.
Page Faults [wikipedia.org] are not about swap, they're about Virtual Memory - which a different (though related) thing. You should read up some more.
Re:Just test? (Score:3, Informative)
Remember to set permissions on swapfiles, letting any user read them is not a good idea as they may end up containing sensitive information (e.g. passwords).
Re:separate partitions for / and /home (Score:1, Informative)
Separate /var too. If the system goes down, active partitions are at the highest risk of corruption. /home /var and /tmp are the only things that are active. /etc only changes when you reconfigure. Anything else should only change during software a upgrade. /tmp a tmpfs didn't you?
You did make
Re:What Has Changed? (Score:3, Informative)
They use solid-state drives (except some 1000-series models and the 904), which are faster than mechanical devices but can be rewritten fewer times.
Actually, on my Eee PC 901 they're not even faster than normal drives. The stock Eee PC comes with one boot drive that seems to run at more-or-less "normal" speed, and one larger "data drive" that seems ... slow. The slowness is especially noticeable during writes. For example, when I stored my Firefox profile on the data drive, I could expect a 1-4 second pause every time I loaded up a Web page, during which the program would be unresponsive. Presumably this happened when Firefox was writing to its cache, history, etc. Moving the profile to the boot drive cut that time in half. Also, when downloading to the data drive over a 6Mbps cable line, I can't saturate the line. The drive is the bottleneck. Some people have suggested that Asus's drivers for the controller may be flawed. All I can say is, don't believe [all of] the hype about SSDs.
Re:What Has Changed? (Score:5, Informative)
Linux will use swap sometimes even if you don't fill up your RAM. It can swap out idle programs and use the recovered RAM for file caching which gives a performance boost to the file system.
Conversely, if you have enough ram for file caching and running applications, then you will get a performance boost from disabling swap (because applications would be faster if they weren't ever swapped out).
Re:What Has Changed? (Score:2, Informative)
It's probably trying to make room for open office's code.
Because you don't have a swap partition configured, the system can't swap out your data so it's trying to find memory the only place it can - it's discarding the code segments for firefox.
But of course when open office wants to run it needs to swap in the code for the open office which means it needs to find some memory to throw away. And that means it throws away the memory for firefox.
And when firefox wants to run it needs to find a place to put the memory for the firefox code. Because it can't page out your data, it finds the memory in the only place it can: it throws out the memory used by openoffice and uses it for firefox.
wash, rinse, repeat.
There's a reason that most modern OS's have swap partitions (or paging files).
Re:What Has Changed? (Score:3, Informative)
Because if you've already successfully chewed through 8GB of RAM, having an extra 256MB of swap available just in case isn't likely to be a very meaningful stop-gap.
The other advantage of swap, which I've not seen anyone discuss here yet, is that unused programs and data will be flushed out of RAM to make room for more buffers and cache.
Might not seem like a big deal, either, but: Suppose you've got OpenOffice and Firefox open, but you haven't used them for awhile. They're each using a few hundred megs of RAM. You then decide to, say, start editing a DVD (or some other disk-intensive thing). With enough RAM and enough swap, the unused programs will be swapped to disk, and the RAM freed by doing sowill be used to cache as much of the DVD as possible. This makes the editing process quicker, and less CPU intensive.
In other words, swapless systems (or those with limited swap) are cache-starved.
Re:Oh, nonsense (Score:5, Informative)
Yes, I believe it was the BSD memory manager (possibly earlier, V7 maybe) that had the 2xRAM rule. Less and you could have issues - more was wasted disk space.
BSD was the foundation for SunOS (pre-Solaris 2.X), Ultrix, etc. so they all inherited this requirement - and from there the "requirement" became gospel on other systems.
I've actually never heard the 2xRAM in relation to Windows, but it certainly predates it. I was setting up systems with 2xRAM when Windows was a DOS app... :)
Re:What Has Changed? (Score:4, Informative)
Re:What if we just got rid of paging? (Score:2, Informative)
Re:RAM-based hard drive (Score:3, Informative)
Yeah that would be a great [gigabyte.com.tw] idea.
And yes, those bad boys do raid together and they max out SATA transfer rates.
Re:separate partitions for / and /home (Score:1, Informative)
From the boot CD:
`mv /mnt/hd /mnt/hd/old'
Install, then mv your home directory back. Now you don't need the foresight from college days to realize you'll need 25 GiB for MP3s! Plus now if you have the disk space, you can keep the whole old FS and bring over conf files and binaries as you discover you need them, and even `chroot' into it if you like.
Re:What Has Changed? (Score:3, Informative)
Perhaps for a very specific definition of "swap", you might be correct, but swap has a more general meaning. Your definition seems to be full process swapping (where swap = suspend process, send all code and data to disk). That certainly is pretty rare, and is generally a last resort. Since it is so rare, the verbs "page" and "swap" generally get conflated and discussed together. On most systems (pretty much all systems with virtual memory support), swapping/paging definitely happens way before memory fills completely, as you could see using any system monitor like top (Unix) or TaskMan (Windows).
Re:What Has Changed? (Score:3, Informative)
ROMs, EPROMS, EEPROMs, and other static or non-volatile memory devices tend to be advertised as having some 2^N number of bits in them. Even if they most commonly are organized and used as words of 8 bits.
This tends to be reflected in the part numbers, which frequently have a strong relationship to the number of bits of storage in the device. EPROMs in the 27xx series and EEPROMs in the 24xx and 28xx series are the most likely. For example, the 2764, 27C64, 2864, 24C64, etc., all have 64K (65536) bits of storage, although available and used as 8192 by 8, and the 24256 and 27256 have 256K (262144) bits in them, organized and used as 32768 by 8. There are several other sizes of these memories with corresponding part numbers.
Re:Here's how big (Score:5, Informative)
So I'm a FreeBSD guy rather than linux, but I'm going to assume that Linux also supports 'limits' that define the maximum a program can utilize before its denied access to more resources. You won't get a normal app on my FreeBSD boxes to use more than 256M of ram, they aren't allowed. There are 2 exceptions, the PostgreSQL server on one of the machines, and the bot that connects to that database. They both deal with large datasets on regular basis so they are allowed to use more ram. Now mind you, these machines are used for my personal development projects and they aren't really 'servers' in the sense that they see real load. My instances of apache don't NEED a lot of ram, some do.
My point is that there are other protections in place that prevent an app from 'running away' and taking a properly configured machine down.
Second, swap can be VERY useful even if you NEVER run out of ram. The OS can swap apps that have used memory but aren't actually doing anything with it out, and leave that memory available for file/disk caching, which can make performance FAR better than if you kept the idling apps in memory and had less available disk cache. Some apps avoid buffering things in memory because its both easier and most times more efficient to use the disk and let the OS manange the buffering. I've seen NT based OSes aggressively swap out things that aren't in use just so there is more memory available for disk cache, and it makes sense cause there is a lot of crap the kernel and other apps load up that is very RARELY needed, if ever.
So while you can ( and did ) point out the potential pitfalls of using swap, your examples don't apply to any modern OS. I'm excluding Windows from that statement cause lets face it, its not exactly modern at the core. Modern kernels are FAR better at deciding what to swap than you are in almost every case, just like compilers can do a far better job of optimizing applications that most developers can. Yes some can do better, but its not likely you are, and certainly not the guy asking this question.
In short, if you're going to try to get technical with why you wouldn't want to use swap, at least use examples problems that weren't solved years ago.
And for reference, you configure your swap poorly if you do what you say.
Re:32 bit (Score:3, Informative)
Yes.
Just because an app can only use '32bit' addressing, doesn't mean the OS does. For instance my '32 bit' processor has '36 bits' of address space. So I have the capability in the processor to address 16 full 32 bit address spaces, even though the OS doesn't let any one app have more than 32bits worth of address space.
Unfortunately, I run XP which won't let me get even to 32bits for all apps combined, but thats another story.
Second, when you take 'virtual memory' into account, you can have a 'virtually' unlimited amount of applications that all think they have access to 32bits worth of address space. For instance say I have 3 apps that have memory leaks in them. These 3 apps for whatever reason must run for long periods of time without restarting. They really only use a gig each of active memory, but because they leak all the time, they consume a lot of wasted memory. This wasted memory will never be used again, so the OS can swap it out as needed and continue to let the buggy apps run until they can be patched, hopefully they will complete their long run cycle before exhausting swap as well.
A better question is, do you really want to deal with those situations? Most of us have no need to. I don't, I know that. And for many people, if they actively need to use 2gb of swap, your dealing with some process that is going to be so painfully slow that you'll probably be willing to plunk down the money for more ram than deal with waitting on the disk light to turn off sometime next May. My swap is set to 8gigs on my XP machine, not because I want/need the swap space, but because I use it as a buffer for free space. When I get low, I turn off swap and reboot and have an extra 8 gigs of space for porn until I can drive my lazy ass to the store to get more tissues and a bigger drive. Not the ideal solution, but it makes me cleanup old crap when I get low on space most of the time and provides an alternative that is just inconvient enough that I don't use it 99.999% of the time.
Re:What Has Changed? (Score:3, Informative)
Your DSL could be 6144kbps but since ATM cells are 48 byte payload with 5 byte header, your theoretical max TCP/IP speeds would be significantly less than 6144kbps. PPPoE also has some overheads but it does allow for larger packets.
How long will it take to read/write that? (Score:1, Informative)
8 gigs on a HDD will take 100-800 seconds to read off.
If you need that much, buy another 8 gigs of memory.
THAT'S why you don't double memory as swap.
1/2 to 1 Gig is plenty. If you start using a lot of it, get more memory.
Re:What Has Changed? (Score:3, Informative)
the Solaris 10 System Administrator Collection (Score:2, Informative)
says:
"The most important factors in determining swap space size are the requirements of the system's software applications. [...] If you are unable to determine swap space requirements from your application vendors, use the following general guidelines based on your system type to allocate swap space."
Workstation with about 4 Gbytes of physical memory: 1 Gbyte Swap
Mid-range server with about 8 Gbytes of physical memory: 2 Gbyte Swap
High-end server with about 16 to 128 Gbytes of physical memory: 4 Gbyte Swap
http://docs.sun.com/app/docs/doc/817-5093/fsswap-31050?l=en&a=view
Re:Loopback Swap. (Score:3, Informative)
afaict there is no need to bother with a loopback device on modern linux you can just mkswap and swapon the file directly.
Re:Will 32-bit OS ever map 4GB? (Score:3, Informative)
Each userspace process has its memory divided in to pages. These are typically 4KB. Each process has its own set of page tables, which map each of these pages to a real page in RAM. These entries are 32 bits, with 20 being used to indicate the address of the physical page. The remaining 12 are flags. One of these is the 'present' flag. If this is not set, then the operating system will receive an interrupt and have to set up the mapping correctly before it can proceed.
If you have a 32-bit OS with two processes, each using 2.5GB of their 4GB address space, then some of this will have to spill over to swap space. Each process will have (for example) 0.5GB of its RAM swapped out to disk. When it attempts to access this, it will be paused while the OS writes some pages that haven't been used recently out to disk and then loads the requested page back in.
A 32-bit OS just means that each process can only have 4GB of address space and that you can only have 4GB of total RAM. There are some slight fudges to get around this too - on anything more recent than a Pentium Pro, you have Page Address Extensions, which gives you 36 bits of physical address space, so you can address 64GB of RAM, but pointers are still 32 bits, so you still only get 4GB of virtual address space per process.
Re:What Has Changed? (Score:3, Informative)
Those "1.44MB" disks actually had a 2MB capacity, and the actual usable capacity depended on how they were formatted... Some places sold them as 2MB disks, some didn't...
Re:What Has Changed? (Score:1, Informative)
In windows it's a good idea to set a fixed size for the swap as it avoids fragmenting the swap file, which I can assure you it does, at least in XP.
Re:What Has Changed? (Score:3, Informative)
on top of fragmentation - if you set it to "let windows manage" instead of setting a fixed pagefile size windows has a very very bad habit of only allocating what it needs at the current moment with no flex space..
Meaning..
evry time it swaps something to disk it has to look up and allocate more space (this causes the fragmentation and takes time)
every time ti swaps something from disk to memory it frees up the space for the File system (takes even more time and opens others things to fragment by releaseing things if 4kb peices)
in the even that it is a true swaping of pages.. it will allocate space on disk then write from memory to disk the current page then read from disk the page it wants then it frees the space on disk.. so not jsut swaping memory but eating disk time to do it.
having windows manage pagefile is just asking for slower preformace if windows ever decieds to swap.. which it does alot even if you arn't running alot of programs that eat memory as windows likes to do system and program cacheing - so you run somethign and quit.. windows will leave it in memory so it doesn't have to read it back next time.. only issue is it doesn't treat this special compared to other things and will page this cache just like anything else..
if you set a fixed size.. then all of the allocating and freeing of disk space goes away.. which makes swaping alot faster in windows.. not to mention that it helps prevent fragmentation of the swap space.. which just compounds the speed issues
Re:What Has Changed? (Score:2, Informative)
No swap partition, which would predictably have many more writes than the rest of the disk;
The firmware of the SSD will do the job to avoid wearing a particular cells of the flash memory, no matter of the partitioning. The partitioning of the SSD is purely logical.
Re:What Has Changed? (Score:2, Informative)
Re:What Has Changed? (Score:3, Informative)
The OS doesn't just randomly "throw away" memory. There is no mechanism for doing so, asking programs to relinquish RAM they previously allocated. What the OS IS doing is dropping file caches from memory, stuff Firefox has read for rendering pages, and leaving them just on the disk. But that's not Firefox's memory... that's the operating system's memory. It can't throw out OpenOffice memory at all. The ONLY thing an OS can do is say "no, you can't have more memory" when a program wants more, or kill the program entirely. It can't find "safe" places to reclaim RAM.
Go take an OS design course, or at least read up on it. There is nothing in your post based in fact.
posix_fadvise and posix_madvise (Score:2, Informative)