How Big Should My Swap Partition Be?
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?
'Is 8 gigs of swap really necessary?'
With a 750GB 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.
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.
My work here is dung.
For what its worth, I've noticed a lot of databases (Oracle especially) insists on insane levels of swap space on the swap partition.
So, yeah. I'd go with = your ram, and if you experience problems, run gparted and grow the partition a bit. But, I can't imagine any real problems from a 4gig partition.
-Red
Guns don't kill people, "with glowing hearts" kills people.
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.
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.
It's hard to believe that's how Micronians are made. Why don't we see it right now by having you both kiss one another?
I'm not an expert, but I'd say that depends on what you are doing. At some point your applications won't be able to allocate new memory. So if you do hidef video editing, extra swap *could* be useful.
I have 1GB of RAM and no swap partition, and I don't remember ever having trouble with firefox-surfing, watching video or gaming. That said I don't use KDE or Gnome but a minimalist window manager.
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 make a note of your virtual memory use every hour or so (or just whenever you remember) for a few days/weeks. Then just give yourself maybe 2-3 times the peak usage.
I imagine different people will need different amounts of swap space, so use a size that's right for you.
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.
-bugg
I normally make the swap file the same size as the memory. If you're using more than twice your physical memory, you need to upgrade.
When I used FAT32 I made sure the swap file was at the beginning of the hard drive, but my NTFS defragger doesn't let me fine tune file placement like that.
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.
Support my political activism on Patreon.
Talking about my Linux setup. I originally had 2GB RAM but had a swap of 1GB, upgrading the RAM I kept the swap of 1GB. The amount of times the system has ever used the swap space can be counted on one hand. The once it did, was when a process went out of control and ate all the system ram, then all the swap space, before crashing the OS.
I would have a swap of 512MB and not bother with any more.
Take Nobody's Word For It.
42 Petabytes for Vista, the next version, who knows.
The page file system needs to be able to juggle the
fake RAM sizes effectively, So petabytes seems to fit the bill.
Whatever you do, you need to remember to setup you swap partition to as large or bigger than your ram in order to be able to use the "suspend to disk" function in Linux. On older laptops suspend is sometimes handled by the bios. Then you need a special partition. But nowdays Linux just suspends to your swap. And if your memory was full ...
One other thing to consider when setting swap is the amount of memory you will need to address at once. Linux can't map more than physical and swap combined so if you are going to be mmaping 80GB files you'll need at least 80GB between swap and physical memory.
Search your logs like the web: splunk!
Sometimes I generate really big files, by stitching photographs into large panoramas that are 30,000 x 10,000 pixels. That can use all of my 4GiB of ram, causing everything else to be put into the swap file for a while. (I have 4 GiB of swap on each of my 2 * RAID 1 arrays, for a total of 8 GiB of swap. That is a bit of overkill.)
Other than that, if I actually use more than 4GiB of ram at once, performance is going to take such a massive hit that it might be better to let the "Out of Memory" errors appear.
If I have nothing to hide, don't search me
Forget the RAM X 2 rule. Capacity of drives are way up, base RAM load is way up. Drive transfer speed isn't up very much. Doesn't really matter how much ram you have, long before you get a Gig of swap utilized the system is going to be trashing to the point of being unusable under any but lab conditions.
Running with no swap can cause some problems, because it does help if the system can push out blocks of memory that aren't backed by a file and also haven't been used for awhile. Still on an all flash system with an adequate amount of RAM running without swap is probably the right move. On a machine with a spinning disc give it a 1GB swap and forget it.
The exception being in cases where the a system is doing suspend to disc into the swap. I don't have any Linux machines that will do suspend to disc so don't ask me about any details.
Democrat delenda est
In the end, it depends. If you are running several memory intensive applications you're going to want more swap space. At the very least, you should have as much as your RAM because when you hibernate it takes all the pages in your RAM and puts it into the swap space before powering off your computer. I wrote about this a while ago: http://www.bytetrap.com/blog/2008/06/02/swap-space-linux/
Reasonable limits aren't.
Insufficient swap space is one cause of enduring Green Screen of Death on early TiVo expansions (Series 1). There it wasn't the size of the memory (fixed) that was the issue; it was the size of the video storage and how much space you would need to do the equivalent of fsck on it.
So make it something unreasonably huge. Got an old spare 40 GB drive lying around? Make it all swap and use it 'til it dies. If your environment has as an upper limit something smaller, use that instead. Disks are cheap.
Oh, say does that Star-Spangled Banner entwine / The myrtle of Venus with Bacchus's vine?
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.
Is that transactional servers that swap are useless.
There, ive said it (more than once and ive heard it from the mouths of real unix gawds): swap is not usable in a heavy production environment webserver, mailserver, printserver or whatever thingie that does syncronous jobs (need to provide an answer in seconds or minutes after a request comes).
OLAP Database servers are also in this category: if youre swaping, it aint workin.
There are only a few applications that actually benefit from swapping (large datawarehouses come to mind), but they almost do the part of their job that consumes more memory in an asyncronous way.
Bottom line: set your swap to whichever reasonable figure you can calculate from a realistic-as-possible memory usage scenario for the particular application you are using.
NO SIG
runs without swap, at least the version of Xandros that comes pre-installed (SSD's do not seem to be the best medium to hold swap partitios).
On regular desktops that do not need to hibernate I usually have between 512Mb - 1Gb. On laptops it is useful to have 1.1X size of RAM to be able to hold the system state there.
metageek
Delaying is largely the point as I see it. If you're out of ram and it's eating into the swap, things are going to slow to a crawl and you'll know something is wrong, so you can look for, find, and kill whatever is running amok before it consumes all and triggers a panic/BSOD/etc.
upon the advice of my lawyer, i have no sig at this time
I personally prefer to put /tmp on tmpfs, and combine with a large swap partition (much larger than 2x RAM). tmpfs is a lot faster than a regular filesystem *even if it has to hit disk*, simply because it doesn't have to care about consistency. If the machine goes down, the data disappears.
On some new servers. 50+ GB of RAM and 1GB of swap. I guess that is what happens when you trust HP to install the OS.
Kilroy was here.
On a system with adequate RAM, the primary effect of swap is to make the system bog down before it crashes when a runaway process tries to allocate a huge amount of memory.
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.
I'm running 8 GB of RAM and haven't used a swap file in a year in Linux. I keep it around in Windows because Windows likes to have it, but even then, it's only 2 GB.
Colin Dean Go a year without DRM
I'd say I'd stay on the safe side and follow this rule - my laptop has 1.2G of ram and even at the times when I have lots of applications open under KDE3.5: 5 firefox windows with 15-20 tabs each, evolution, amarok, a couple of krusader instances, 3 consoles with 5 tabs each, eclipse and apache2 running in the background, I've never seen swap usage go over 100Mbytes, so I can say, that for normal work I don't need more than 256 Megs of swap, however, hibernation to disk dumps memory into swap space, so I need at least 1x for Ram for that. So I guess the new rule of thumb is: Swap space = 1x Ram + (Swap at peak memory usage) Of course I use LVM for virtualizing partitions, so resizing a partition is not nearly as painful as it used to be. Also I suggest reading man pages for swapon, swapoff and mkswap; You'd be amazed the flexibility of linux when managing swap partition/files.
Anyway. Ime, I have often used same as ram, but twice, i.e. on 2 different drives. and used the priority option to run them at the same level.
Also, the problem with swap, is that if it does get used alot, then the whole system slows right down. If you have a lot of swap, and a lot in use, your system will be slowed down, but for much much longer.
Why don't you conduct some personal tests. Consider creating a script that encompass your typical applications and file sizes that reflect you day-to-day work. Now run the script with ... say 1 gig, 2 gig, 4 gig and 8 gig swap files.
or /flamebait=on just use a system utility like Activity Monitor on the Mac to compare the number of page ins and page outs.
I have 4 gigs of ram on an intel iMac, and my swap file weighs in at just under 6 megabytes. This is a production machine that uses CS3, and it's been up and running for 5 days, 21 minutes right now. I'm not working with a lot of large files, but I've been working on a 160 mb (lzw compressed) PSD today while everything else is open.
YMMV
With large ram sizes fairly cheap these days, you don't need much swap. On fairly fast systems, I usually set only a half gig swap partition. This keeps the system from wasting time swapping when it doesn't need to. It also will deal with most normal use requirements for swap. Also, as previously mentioned, as of kernel 2.6 in linux, swap files are basically just as fast as swap partitions, so if the need for more swap arises, you can just handle it that way.
I have a laptop with 4gb ram, and a 1gb swap file just in case. While compiling linux in a vmware hosted linux and using the 'real' os (also linux) for amarok/firefox/gaim/terminals/thunderbird/open-office/etc. I was using 1GB ram. I don't think it's hit swap ever.
... make sure you have a swap partition, so if you ever need to do a memory dump, it can do it right to the partition. Logic follows that you would need to have the swap partition at least as big as your memory. Also look ahead to any potential memory additions. I do my swap partitions 100 MB larger than my physical RAM max size just to be safe.
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
Post may contain irony: discontinue use if experiencing mood swings, nausea or elevated blood pressure.
Look, I have a 2G ram Linux desktop system. I now used a flash ram disk with zero swap on it. On my server, I have 3G ram, and 4G CD flash HDD for / and 1 TB for other storage, (which sleeps most of the time). On the laptop, it is 1G and has 2G swap. I can tell you that this it depends on apps being used. If I start running google earth for any length of time, then I will add swap on desktop. At this time, it handles KDE, KDETV, and vi for development, make, g++ nicely. With swap turned off and using CF, the system is slightly faster AND 10 degrees cooler (and a lot quieter). SO, are you running MASSIVE APPS, or is it a standard laptop. If so, turn off the swap.
I prefer the "u" in honour as it seems to be missing these days.
How many Windows users do you know with a swap partition?
If your DB server is swapping, either you've misconfigured things, or some process has run away with your memory.
Keep your swap file small so that the OOM killer kicks in sooner rather than later.
Minimum of 5 TB for a Windows Vista Swap file..
I run a laptop with 4GB real memory and a desktop with 8GB - both are running XP64 and have 64GB SSDs (though the desktop is 3x32GB RAID0). I have no swap under either and they are both stellar performers. I never use all my real memory - so why would I need swap?
On my old desktop the drive ran continuously even when RAM was not completely utilized. The drive was a Raptor so I really noticed it and it annoyed me. It's one of the reasons that I went solid state (besides having an insane urge to blow money) but the constant swapping is gone as well.
Right now I am running my normal system and 2 1GB VMs and I still have 4.8G available.
Seems good to me...
-Dave
Maybe we should be asking "should we even bother with swap files?". I took a class on that where we calculated the steps it takes to get the final memory address in a paged memory system. It was something like 36 steps per address! We had PDEs, PTEs, convert this, change that. I didn't grok all the steps, but I do know there were a lot of them. I know 36 steps per little itty bitty piece of memory is a lot, even if you are a very fast CPU, when you have to do this hundreds of millions of times.
Back in the day, it made sense to convince your programs you had an extra 100 megs of RAM, because a lot of programs needed that and didn't have it in memory. Today, memory is more abundant than things we would really need it for at the non-industrial level. I don't personally have any non-industrial applications that will fill up 4 gigs of RAM. Even Vista + WoW won't take up all that.
So, and my professor suggested this, maybe the ideal swap size is ZERO. What if your operating system just operated under the concept of "If you can't fit it in 4 gigs, tough. Just wait until memory is free. I'm not even going to bother to split memory into pages because I'm always going to use RAM, not a hard drive page. Case closed." We could save so much overhead and complexity if we just admit that we never need to pretend hard drive is RAM. With 4 gigs or more of RAM, why even have a glacial slow hard drive in the mix?
So I figure 4GB of total virtual memory is enough for anyone. Um, I mean, enough for me.
As copyright owner of this comment, I authorize everyone to defeat any technological measure which limits access to it.
I'd actually like to set up more swap, for the times I need more RAM than I've got (only 1GB on my work LT, oy). Nevertheless, I generally do not use any swap space for two reasons: 1) windows at least seems to poorly manage memory, even when I am not using anything close to my physical RAM, it insists on swapping, slowing things down unnecessarily; and 2) I usually need the HDD space...why is it that windows and other OSes cannot dynamically allocate/deallocate swap space as needed?
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.
At least I have a firewall/fileserver 1GB memory but without swap. It gets uptimes > 1 year. I have not observed any problems so far.
Most ACs are not even worth the keystrokes to insult them. Be generically insulted by this and ignored otherwise.
You probably need less than your RAM size. On my laptop with 1 GB of RAM it's 512 MB:
astro@myrtle:~] ll -h /var/vm/
total 3145728
-rw------T 1 root wheel 1.0G 6 Feb 2008 sleepimage
-rw------T 1 root wheel 64M 1 Oct 13:21 swapfile0
-rw------T 1 root wheel 64M 1 Oct 14:32 swapfile1
-rw------T 1 root wheel 128M 1 Oct 14:35 swapfile2
-rw------T 1 root wheel 256M 1 Oct 14:35 swapfile3
ENDUT! HOCH HECH!
Is there any point to separate partitions for / and /home? I mean, if you were running different file systems on each of them I could see the point.
How we know is more important than what we know.
This is sensible. The sum of swap and real memory should exceed the largest amount of virtual memory you ever expect to need. On Linux it is desireable (but not necessary) to always have a little swap.
Warning: this article may contain humor, sarcasm, parody, and perhaps even irony. Read at your own risk.
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.
Are you adequate?
I have 64 GB of RAM and my swap partition is the same size at 64 GB. I thought 128 GB is a little excessive. What I would really like is if someone would make up an IDE interface to RAM modules and build a large amount of such RAM into the form factor of a hard disk drive. Then, you could populate this RAM-based "hard drive" with the necessary data during startup, and use it for swap and for all of your system's various "temp" folders. This would make swapping (and temp stuff) extremely fast to access, and more importantly, it would eliminate the need to encrypt your swap and/or temp partitions, as the data would simply disappear when power is removed. So when the agents (including Agent Smith) come to bust down your door, all you do is pull the plug and voila! Your secrets are safe. :-)
McCain/Palin '08. Now THAT's hope and change!
I've been setting up machines with no swap partitions for a few years. Swap partitions have a bad habit if collecting secure info you may have assumed was just in ram. All modern operating systems allow to you use a file or other blank space as swap means you don't need a dedicated partition. There is also the issues that if your starting to swap, where does it end? If your swapping on a machine with 4 or 8 gig of ram, will an extra gig help fix what ever is broken or just make the machine very slow until it gets around to telling the runaway program that there is no more memory. In the case of no swap, that tends to happen much faster. The only reason I see for swap partitions is that the OS will need a place to dump debug info if it crashes and the swap partition has traditionally been used for that.
forget about it was an inclusive instruction, not part of a for next loop. :)
8GB swap on a 120GB drive is 7%, not .07%. On a 200GB drive, it's 4%, not .04%, etc.
SirWired
yeah, I used to follow the rule, then with the upgrade from 1GiB to 2Gib, I changed my rule to 1x so a 2GiB swap..
Then just last month I got annoyed with the whole idea of swapping and just disabled my Windows XP page file and seeing that my peak only ever hits roughly 1GiB (this is with SQL Server Management Studio, Visual Studio .NET 2003 *and 2005*, Firefox 3, IE7, Outlook 2003, Excel 2003, and a few other programs, all at once)
So far I've been pretty safe (never had a BSOD or out of memory error yet)
So to summarize if you really run lots of large apps, maybe you should have a swap file.. (if you can't afford some cheap memory,)
if you want windows performance to be "snappy" disable your page file... I have yet to test linux, but I would assume it's similar, you can just disable the swap file and get slightly improved performance.
Anyway, my personal opinion is that Virtual memory is a hold back from the $20 a MiB pricing from the old days of RAM.. these days at $20 a GiB (or much less) it's just a 32bit problem I guess...
Well, you know what they say - 640K ought to be enough for anybody.
#DeleteChrome
Before 1GB was typical, I always used 1.5 * total memory.
Now with 1GB and more being typical, I've gone with .5 or .75 * total memory.
Hard OOM errors are really annoying, and sometimes hit the wrong process if it's unlucky enough to ask for more memory after another applciation has eaten 99%. Just make it enough that you know the disk is going crazy, go kill something. Even with all the wierd stuff I do I still don't run out of memory on 4GB. Actually I have some unused because I'm still running a 32 bit linux because I haven't installed the 64 bit version, but I don't care. And if I did manage to need more than 4GB I'd get 64 bit, 4x2GB and still not worry. And you actually don't pay much of a premium for 16GB either, a 4x4GB set costs about twice that of a 8GB set. Not that I'd have any clue what do to with that, but if you develop A3 posters in print quality maybe it's handy. In short, memory has run off the curve for me. Processors too, it's never very busy. The two things that still could improve are graphics and bandwidth (solution for latter: move, sigh).
Live today, because you never know what tomorrow brings
Is there any point to separate partitions for / and /home? I mean, if you were running different file systems on each of them I could see the point.
I have gone through four different version of Linux on my laptop: mandrake/mandriva -> fedora -> knoppix -> ubuntu. Guess how many times I've thanked 8 lb 6 oz baby Jesus that I had the foresight to separate the two? All my data from my college days is still intact under /home.
For this simple reason, I heavily recommend it.
My work here is dung.
It is handy when installing a new version of the OS. Just format the / partition and leave home alone.
I am not a script!
In case you want to switch distros and not lose all of your data.
At least that's why I do it.
http://support.microsoft.com/kb/197379 never had a problem.
I have a 4GB Win2k3 server as a development machine. I've installed a Gigabyte 4GB iRAM drive (with battery backup) and set my paging/swap file there for 2GB. The other 2GB are TEMP/TMP for java and other apps to use. SQLserver and Oracle databases are detuned to utilize smaller memory footprints for development. We also run the occasional VMWARE image.
The C: drive is on a different mirrored disk and controller from the other drives which splits up the I/O there.
Yup - its faster now
Ahh, groovy. Thanks for the awesome reply!
How we know is more important than what we know.
Just add more memory.
I have never seen my linux box with 5GB of memory run out of memory.
If you cant add memory just set it to 1x or 2x the memory size. If your working set will be much larger than your available memory your computer will be unusable anyway.
I also agree that the old "2 x RAM" standard is outdated.
If you are a typical desktop user--browsing, email, games, etc, you will likely never swap. If you happen to edit photos a lot then you'll use a bit more. In these cases doing 4GB swap for 4GB RAM should be more than sufficient, and even then overkill.
If you are a serous 'power' desktop user, heavy graphics / video editing or similar heavy-duty tasks, you will likely have significantly more RAM. If you ever did swap things would become so slow your productivity would be severely hampered.
Were you talking about a server I'd say the same thing. Your swap space on an active server (thinking database or application server) is really just there to keep you operational should some process go haywire, long enough for you to fix it. If you are regularly swapping on a server then you need to upgrade your RAM or adjust your software on it.
For a desktop linux system - not really. I used to do it because I was told it was safer/easier to completely wipe your OS and install a new one while keeping the home partition, but I've never actually done that - I usually keep a rolling upgrade, and when I want to install from scratch I usually buy a new hard drive anyway, so I can keep using my old system if the install has problems.
For a shared/server system it is useful to ensure that users can not fill up the partition, preventing the system from writing to files that it needs to. On OpenBSD it is a good idea because they have some additional security settings that are be applied per-partition, and you generally want different policies for /, /var, /tmp, and /home.
Summary: If your "working set" fits your RAM then there's no use for swap.
IMVHO the general rule should be "don't ever size your swap more than twice your RAM".
If you needed more "virtual memory" than that you certainly should buy more RAM.
Windows, up to Win2000, behaved very poorly without swap (at least half the RAM), but I never had a problem with Windows XP or Linux running without swap.
Yes. If an OS upgrade fails, then I can reinstall the OS (i.e. format the / partition) without having to move all my /home files to a backup drive first.
My standard (which is deployed on 10s of thousands of machines) is 2x RAM if your kernel writes crash dumps to swap (i.e. FreeBSD and many others), 2 GB if your kernel writes crash dumps somewhere else (i.e. netdump on Red Hat). The 2 GB provides enough of a buffer that the system doesn't immediately puke if you go slightly over your actual RAM, but doesn't allow you to run way over your actual RAM. On servers with 16 or 32 or even 64 GB of RAM and a 73GB SCSI or 80 GB SATA drive you can't go 2x RAM anyway.
This is for servers, desktops are probably a totally different story, but Mac OS X is my desktop OS and it just does some magic that I don't have to pay attention to.
It lets you leak more memory for longer, this is a necessary feature for running modern software.
“Common sense is not so common.” — Voltaire
The "rule of two" is due to Knuth's demonstration : "When the memory is 50% full, there is necessarily one free block at least as big as the biggest already allocated block", or something similar.
Today, I would say the swap partition is mainly useful to store the state of the computer when you put it in hibernation mode, that is a little more that the size of your RAM if you want to be really cautious, just in case.
That being said, A GB of disk is so cheap compared to 1 GB of RAM - which is already cheap, now - that there is no problem in doubling that size for very special purposes (alternating 2 different "hot" graphic users sessions or operating systems without rebooting, for instance). Just my two cents.
Signature omitted in order to save space. Thanks for your understanding.
home alone is a pretty nifty idea. Especially if you're a kid and it's around Christmas.
Yes there is, for a while I was literally reinstalling Linux every day because it would crash and the entire partition would go corrupt. Since I put everything on it's own partition that hasn't happened even once.
There is the point about putting home on it's own so that you can switch between distros, but the biggest reason is that it reduces the likelihood of everything going corrupt because of a read on a different portion of the file tree.
That being said, Linux always used to be a pain in the ass in terms of disk layout. If I understand things correctly, with LVM it's largely fixed, but whenever I do an install, I end up using like 5 or 6 partitions rather than 1 partition with several labels.
But, with ZFS basically here, that's largely moot since you can have a couple dozen partitions and still not have any particular troubles.
So MS recommends no more than 4 GB for the paging file. This is also the limit for 32-bit unsigned arithmetic, so there may very well be a limit to how much of the file Windows will use, and that limit may well be 4 GB.
So unless disk space is at a premium, just make your paging file 4 GB.
RAM has become cheap lately. Running Max memory on my systems is the norm now. Routinely checking my "top" or whatever I feel like using to check system status shows that swap space is almost never being used. On my laptop with 4GB, it is never touched when I check. On my servers, the same is generally the case.
Laptop I am on now: current use is 0k
On my VM server now: 104k
On one of my VMs: 137912k
The Laptop and VM server have 4GB RAM. The VM I sampled has 512MB given to it. I suspect I should go ahead and push that to 1GB to see if I can reduce the swap usage. The point is that if your machine is tuned and configured for the application, you shouldn't use swap very much. And if you have too much memory, swapping that much will likely exceed the ability of the hardware to efficiently move that amount of data without impeding over-all system performance.
Why would you return 1?
How much RAM do you have and use?
How much disk do you have?
What sort of usage profile is it?
The last is the most general. There's three categories: server, desktop and laptop.
Server:
If you can afford it, buy enough RAM that what you need will never exceed what you have. Using swap kills performance and if your swap ever has significant churn, it's probably worth the investment to add more RAM.
Desktop:
Desktop RAM has taken off far beyond what you'll ever use. You could probably dispense with swap as well, but for one thing: hibernation. More and more desktops are supporting the technology, and for the cost of 1:1 swap:RAM you can hibernate. If you honestly hate hibernate, then it all comes down to expecting to use more RAM than you have. Possible, but unlikely.
Laptop:
Certainly never go below 1:1 for the hibernation need. Going higher depends on how RAM starved you are versus how much disk you have. Lots of laptops have tons of RAM, but those cheap netbooks are pushing it lower. 1.5:1 is probably a good upper bound.
I Browse at +4 Flamebait
Open Source Sysadmin
I've started creating 2 root partitions on my hard disks. That's not trivial on my laptop (10% of the disk), but it made life a lot easier when upgrading from OpenSUSE 10.3 32-bit to 11.0 64-bit. I dd'd one partition to the spare, fixed up partition names in the spare, and then did an upgrade. Yes, it is possible to upgrade from 32-bit to 64-bit with OpenSUSE, although it doesn't get all of the RPM architectures right, so I had some stuff to fix up afterwards.
So arguably I didn't need it, because I didn't need to back it out...but it did make for peace of mind, and it will in future upgrades.
It's kind of obvious that the answer to the question really depends on "It depends on how much you use", but for curiosity's sake, what happens on a modern day linux system (Say it's the latest version of Ubuntu or whatever) when you run out of System RAM and don't have a separate swap partition? Will things just stop with an "out of memory" error as days gone by? Will the OS ask you to close some programs? Will it create/manage a good ol' swap file for you? Or will your computer explode in your face?
+1 IDisagreeSoHeMustBeATrollOrAnAstroturferOrAShill
But in my decade or so of using Linux, I eventually found myself not particularly needing a swap partition. I've never noticed a problem on any of my workstations that don't have one - although it makes complete sense for servers.
Today's weirdness is tomorrow's reason why. -- Hunter S. Thompson
I like to set up Linux so the "swap partition" as a file and I mount it via Loop Back. That way I can adjust the size to fit my need much easer. Realizing that 8 Gigs is too much then I can remake the file a different size. I am somwhat disapointed that Linux still hasn't came with dynamic sized paging for swap at least as an option, It may be slower but it can keep more disk free or if you use a lot of extra ram you can keep your system running.
If something is so important that you feel the need to post it on the internet... It probably isn't that important.
Unless you happen to (really, not just-in-case) need images from crash-dumps or if you have some sort of suspend-to-disk system, you should NEVER use swap.
Ever sit and listen to Windows randomly chug the disk for a while? Often, that's it doing stupid crap with swap when you want it to be working on something else. Swap is SOOO slow that even scenarios where the OS tries to shove stuff it thinks you'll never use again, which should be a good idea, results in you sitting and waiting while that happens at really irritating times.
On servers, it's much worse. A host constantly hitting the disk for swap will have much higher power and cooling costs, and the life of the drives (although still very long) will be reduced. Using anything mechanical you don't have to is bad.
Just buy more RAM. Anything arguments against are edge cases that you should engineer yourself out of anyway.
So, imagine you are using a machine with 1 GB of RAM and 2 GB of swap, following the old rule. That adds up to 3 GB of virtual memory. Now you buy your new machine, that has 4 GB of RAM. If you run it totally swapless (which is perfectly possible), and your use of it is more or less the same that the use you gave to your old machine, then why whould you even consider using swap? It's totally pointless to use the "double your RAM" method. If you don't want to go swapless, just put something like 1 GB and it should be enough. You can always add more if you need later. Reference link: http://kerneltrap.org/node/3202
It's weird that people ever specified the swap size as being related to the size of real RAM ... seems like it ought to be obvious, the size of swap is the difference between the size of RAM and the max amount of VM you'll ever use at one time. If you honestly have no way of guessing what that is, then there's no answer to the "how big should the swap partition be" question in the first place. Honestly I feel weird blindly adding swap partitions to all my Linux boxes these days when all my PCs have vastly more RAM than my old machines ever had of RAM+swap, and I haven't changed what I do all that much.
Anyway, is it seriously still required to be a fixed size? I mean of course you wouldn't want the VM system messing with partition sizes but I would hope that swap files could be grown as needed.
Or better yet, I have some dim memory that one of the PDP-10 OSes, might have been ITS, would simply use *all* unallocated disk blocks as potential swap space. It meant that the VM system had to be good friends with the FS driver (so nothing horrible happens when the FS driver creates/extends a file) but it seems like a pretty neat solution to the problem.
Maybe I am missing something here, but I find many recommendations made in here very strange: many argue that you should have no swap at all or just keep it very small. They argue that using swap would degrade performance.
But I wouldn't one have to make a difference between just using swap to page out unneeded memory on the one hand and trashing on the other?
If a single running application needs more memory at once than RAM is available, then pages need to get constantly swapped and that will case trashing and an unacceptable performance.
But if you have a lot of applications just loaded that essentially only wait to get used eventually, I think it can make sense to let the OS swap the memory needed by them. Re-activating the memory might take a couple of seconds even, but then pages for some other application that has not been used for a longer while will get swapped out.
No?
Turn it around and look at it:
You have 4GB RAM and want to know how much more RAM you need. Cost comparisons would figure in if we were comparing, but we're not. Take a look to see how much of your RAM is used during various tasks. If you're running out of RAM, you need more. Can your machine handle it? If not, you need another alternative. Now, can you afford it? Ditto.
If anything's using up your RAM, find out what, and figure out if more RAM makes sense in that context. A question for clarifying things should be "need more RAM/swap space for WHAT?" If specific apps make the suggestion, it may be worth listening. If the OS makes the demand before the software is even installed, I'd ignore it. If the OS asks for swap space based on load, as Windows does under "let Windows decide" it may not be accurate, but it's thinking along reasonable lines.
In addition to RAM load, take a look at RAM fragmentation. Some apps and OS pieces are very bad neighbors and your RAM ends up bogging down. These don't need more RAM, they need defragging or better RAM clearing built in, or you need it as a utility.
"I may be synthetic, but I'm not stupid." -- Bishop 341-B
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.
I configure my system with my swap set to /dev/rd/0. Seems to work OK.
Get your own free personal location tracker
I was wondering the same thing. I usually like to have 3 partitions...one for swap, one for / and one for /boot.....since I usually used something simple for boot like ext2....and reiserfs for /.
Light travels faster than sound. This is why some people appear bright until you hear them speak.........
I have 3GB of memory and even when virtualising I've never needed more than that.
It's time to get rid of swapping. Serious real-time OSs don't swap, and more of what's being done on the desktop today has at least soft real-time constraints, like playing music, videos, animations, games, audio, etc.
With QNX, running as a desktop system, there's a bar at the lower right of the screen showing how much memory is in use. If it reaches the right, you can't load any more programs, and requests by existing programs for more memory will be rejected. This doesn't crash the OS; the system is well-behaved in an out-of-memory state, and executing programs will continue to chug away as long as they don't demand more memory. There's no reason Linux couldn't be made to work that way. Applications need to be reworked to behave better in out-of-memory situations, though.
(Actually, QNX does have swapping support, but it's only used for a few programs, like compilers, which are inherently batch operations.)
I have one, although it doesnt work as a swap partition as in linux (et al) it's just a partition that holds the pagefile.sys(s) for my various Windows installs (2 XP, 1 Vista) and the only other partition on that HD is my "Downloads" partition, so if im not downloading, any paging that is done has a HD to itself to play with.
Arguably RH is the authority on the subject... See their documentation here.
-m
http://www.invisik.com
Linux will typically run the OOM killer and identify which process is the 'baddest' and kill it to free up memory. Windows might crash but it does that normally anyway.
I always wondered where this setting was...
Has anybody tried setting up a solid state disc that is dedicated as swap? The faster read/write times should make it ideal, and it is getting cheaper to buy SSDs all the time.
Why not purchase a 32gb SSD and set it as swap--it's almost like free RAM. Then when it dies from overuse, buy a 128gb SSD for the same price you bought the original one for.
Is there something I'm missing here, or is that actually an idea that would work?
I have a swap file of about 5X RAM - I certainly don't use it all but I do sometimes use quite a bit of it.
The reason is tmpfs. Junk that I don't need to persist always goes in tmpfs - which speeds up lots of stuff. At worst it gets swapped out to disk opportunistically, but the fact that the kernel knows that I don't really care about it at all means that it can take full advantage of ordered writes / caching / etc.
I also run gentoo - which means that I'm often doing compilations, which generate tons of files that I don't care about long-term. Those go in the tmpfs. For most software it probably never hits disk, but if I'm compiling firefox or whatever the swap comes into play. Performance is better than just compiling on disk - since a file that gets created and deleted 60 seconds later may never hit the disk at all.
But, gentoo users are a bit of a special case there. Most people don't generate large numbers of transient files.
If you have 4gb RAM and only a 10gb HDD, you have bigger problems than how much swap to use.
Today is red jello day - all workers must eat all of their red jello. Failure to comply will result in five demerits.
My basic formula for swap space is: worst-case memory usage that I don't want the system to fail under, minus the amount of system RAM I have, rounded up to the nearest even amount (I usually make it an even multiple of 16M or an even number of gigabytes). My minimum for swap space is the amount of system RAM, to allow for things like hibernation, but that's a personal preference. I don't like running without swap simply because there's no overflow, no buffer for the occasional nasty memory hog. And a lot of the time it's useful to have somewhere to put idle program address space, freeing up system RAM for I/O buffer cache. I've a number of programs that really only become active in the wee hours of the morning, and I'm willing to let them take a moment to swap in when I'm not around to get the better performance during working hours that comes from having the memory they'd otherwise be occupying available for buffers and cache.
And, on today's systems with 250+G hard drives, 2-4G for swap is almost negligible.
How many Windows users do you know with a swap partition?
Probably about as many Windows users as OS X users; both of 'em use a file/files as backing store for anonymous pages. (You could probably arrange to have those files on a separate partition, as per Vectronic's comment.)
The system is giving the program all that memory - to give nothing in return would be rude. That is why you should return 1 instead of 0.
In early Linux 2.4.x series, it was once the case that you need to put twice swap space as much as your RAM. The only reason this requirement existed was a badly designed and performed VM. In 2.4.10 the VM was replaced completely and in 2.6.x there was an even newer VM. So I don't think this applies anymore. You can put as much as you'd like as the swap. Only the total size (RAM + swap) matters.
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.
/^([Ss]ame [Bb]at (time, |channel.)){2}$/
I ran a magnetic finite element job using a commercial code on Windows XP (company required for this code) which used 15.5 GB of RAM (16 available) and 11 GB of swap. It took five days to run and I couldn't do anything else with the PC, but that's OK - I have an RHEL 5 box next to it.
FIrst off. Moderd OSes don't ever actually swap out programs. They simply delete the programs from RAM without needing to write them out to disk because the program is already stored on on the disk asthe executable file. Only RAM pages that have been writen ever need to be swapped out.
In the old days, the address space of an entire process was swapped out to disk. The term back then was "roll out" and "roll in". OSes have gotten smarter and now the way a program is loaded into memory is by "mapping" the executable binary file to RAM. The mapping does not actually cause any data to move from disk to RAM it is moved s it is accessed.
I have a Linux system here that has been up for days. Lots of stuff running. PostgreSQL DBMS, Apache, a web browser, and 12 terminal logins, a VNC session and I'm running another Linux system inside a VMware machine. I have only 4GB physical RAM, 8GB swap. I check and see that 2.8MB (yes M not G) of swap is in use. One a modern system 1/2 GB would be plenty of space.
640K should be enough for anybody. ;)
The best size for a swap file or partition is the largest amount of virtual memory that you'd ever need for the set of applications that you are running and then some. Take an inventory of applications that you are using and how much RAM they need while running. Applications (server or desktop) that make use of in memory databases are becoming more popular and will push up the swap file size requirements for your needs.
Generally I set a swap partition to be at least 20 GiB on machines with up to four gigs of RAM. Now for machines with 8 or more gigs of RAM I set the swap size to be four or five to eight times the RAM size. So eight 8 GiB of RAM would have something like 40 GiB of swap.
Although their is only 8 GiB of RAM on the motherboard that can take 16 GiB of RAM it is prudent to set the swap size to 64 GiB to 80 GiB. This way when I increase the RAM to the maximum of the motherboard I have plenty of swap space.
Planning for the future means setting up more swap space now.
With TiB drives going for just over $100 it's fine to use large swap space if you don't need it for data. Besides your OS should be on the boot drive without data being on that drive at all. Data should be on other drives in a RAID configuration if possible. This leaves plenty of space for swap space on a TiB drive.
Really it all depends on your needs.
-----
Metric units used in this post: http://en.wikipedia.org/wiki/Binary_prefix.
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.
As the island of our knowledge grows, so does the shore of our ignorance.
Swap file size doesn't have any strict correlation to your physical RAM. Some systems can work just fine without them, others will insist upon one. This is also affected by the amount of physical RAM that you have - the less RAM, the more frequently the system will have to rely on the swap file. It depends on how your system utilizes the swap file, and how the programs that you have installed use it. The only "sure" way to tell is to monitor swap file usage to see what the maximum value is.
This is a great idea. Even better if you have a desktop/server: put the partitions on a separate disk. Rather than using dd, rsync it nightly.
Bad patch? Bork something up? Disk fails? Flip some BIOS settings/cables and you're done.
My current employer utilizes a similar method on hundreds of servers for patches and upgrades.
As big as the e-mails promise.
Windows (XP/Vista atleast) can't be trusted with a swapfile, I noticed this the moment I put 2gig of ram in my system (years ago)... yet for some reason Windows still felt the need to page everything when only 500meg was in use. Now with 3gig and the problem hasn't changed, windows seemingly keeps as much ram free as possible, just incase it needs it... which it never does because its always paging everything :)
Turn off your pagefile, reboot your pc and you'll notice an immediate difference in performance.
as for FreeBSD, it doesn't appear to use it til its outta physical ram
have a nice day
Actually - I've got a 4 gig swap partition set up on an SD card. However, I never run any programs needing more RAM than what I've got. I suppose the purpose of my swap partition is to keep me from plugging other cards in my only SD slot.
Well this ought to change. My swap partition is going. Thanks for making me think a little.
I've always thought of swap space as the operating system's bungee cord. If a program decides to be stupid and allocate shit-tons of memory, you often have enough time to do a quick Ctrl+F1, log in on the console, and killall whatever while the disk is thrashing away. If you have no swap (or if you have it on a solid-state hard drive you silly bastard), you never get this opportunity.
Also, I thought it proper that the quote at the bottom of the page says, "Never trust an operating system."
On my Mac machines I have quite a lot of ram, 2gb on one 4gb on the other. I occasionally monitor memory usage as I'm a developer and that's just something I do. I've never seen my swap, even after days and days of editing video and so forth go over 2GB. Most of the time, however, it's around 256mb.
Furthermore, at one point several years ago I was pointed to a revealing explanation of why, even with quite a lot of ram, swap is useful. Something about optimization through intelligently hibernating shared but inactive libraries preinitialized into virtual memory as well as using it as a cache to reorganize active memory? Anyway I wish I could cite the article.
Point is, if I couldn't have a dynamic paging file I'd cap it at 2GB max 256mb minimum.
I read the script, and I think it would help my character's motivation if he was on fire. -Bender
You don't have all your /home files on a backup drive already?
I've a few 2-4GB IDE hard drives kicking around, so I'll put one on a chain of its own and make the whole drive swap. Might not be the optimal performance solution, but neither is having to page anything out of RAM in the first place.
My thinking is that everything going to swap is stuff I'm probably not going to need anyway and when I do, I'm probably not going to notice the extra few milliseconds it costs to shove it back into my nice speedy RAM.
But really, if you're swapping a lot, you probably need more memory. If you have a reasonably modern system, you should have about 1G - I don't care what OS you're using. If you have a laptop or similar system that you need to suspend RAM to disk, you can do this to a swap file, or to a hibernation file. YMMV on Linux as suspend/hibernate is hit or miss with various laptop vendors.
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
My suggestion is to use a whole lot less. I personally never use more than about 100MB swap unless the offending process should rightly be destined for the Out-Of-Memory process killer anyway.
I only ever trigger the out-of-process memory killer when doing development. If I do, it means that (a) the program needs to be redesigned to use less RAM because even if I had lots of swap it would be too slow anyway, and (b) the extra swap is just making it take longer to regain control of my computer.
If you plan to do suspend to disk, then you should have more swap, ideally a bit more than you have RAM. Maybe someone could comment on the sanity of the following strategy for this:
I would have 2 swap partitions. One with the amount of swap space that you want to have under normal usage, and another equal to the size of physical RAM. Set up only the first one to be used at system startup. Run swapon on the second one (to make a disk area the size of RAM available) right before suspending to disk.
Would it slow down the wakeup process too much to run swapoff on that extra space right after waking up? Or does the OS only recover things from disk as it needs them?
It really depends on how big your house is and how many people live in it. The general rule of thumb is no bigger than the room second smallest from the largest.
while on the other hand, some of us sad people have gone through four different laptops while still using the same version of linux...
Doesn't really matter how much ram you have, long before you get a Gig of swap utilized the system is going to be trashing to the point of being unusable under any but lab conditions.
No--programs that are stopped or idle can be pushed out to swap, and depending upon what you have running on your system, this might be a lot of stuff.
"Not an actor, but he plays one on TV."
If your program has a working set larger than the machine's physical RAM, it will be exceedingly slow (effectively running at disk speed rather than RAM speed). If your program's working set is 1/N of its total memory usage, then a swap space N times RAM will make sure you hit unbearably slow performance before you hit an out-of-memory error.
Patrick Doyle
I mod down every jackass who puts his moderation policy in his sig. Oh, wait a sec....
any more. my laptop still does until i go from 2gb to 4gb, but my workstation with 4gb runs w/ no swap, and runs better. bear in mind this is windows, i'm just returning to linux after a few years break, so haven't played with no swap in linux, but i imagine it's the same.
back in the day, the rule of thumb was roughly 2 to 2.5 times physical memory.
now, with 4gb (3.Xgb usable - 32-bit OS) i've never been without about 2.2gb free memory, even with bloat-tunes, wow, AV, and other crap running.
in my experience, for non-(actual)servers, no swap is the way to go, assuming you have 4gb memory or more.
not only is time travel possible, it's irrelevant.
has anyone tried running XP with no swap, playing games, etc? Do you even need it for photoshop, since it has it's own scratch files that you can define?
what I always do is partition a new disk with a small inner partition, and put nothing but the windows swap file there. Since it's the fastest part of the disk it seems to make sense. Then I have the windows system partition, and then a program files partition. This seems to prevent excessive disk seek, and XP systems I build are still zippy a few years later.
I also make the swap file a fixed size, and yes I use that old rule of thumb of double the RAM, since no one has given a good reason NOT to. Although it would be great just to not use a swap file, but I hear Windows likes to have one, even if it has plenty of RAM.
With Photoshop, I created an inner partition on my RAID just for Pshop scratch disks.
You can also mount partitions that have system files read only until you update, making compromises another degree more difficult.
Apocalypse Cancelled, Sorry, No Ticket Refunds
is that standard HD interfaces are slower than the RAM. I don't care if its IDE, SATA, u320 SCSI, whatever, they're all a helluva lot slower. Last I looked, which was a while ago, they only held a few GBs too. DDR2 is dirt cheap if you have a modern motherboard that takes it. I know the IRAM requires the older and more expensive DDR (DDR1) which would be expensive for 4x 1GB modules and the IRAM. A software RAMdisk and a UPS would seem a better choice for a hobbyist desktop, 4x2GB DDR2 could be had for less than $20/GB
The DDRDrive that was mentioned, is this out yet or still vaporware? They have the right idea with PCIe interface but it only holds 4 modules (DDR1?). Without battery backup to be an advantage, more RAM on the motherboard would again seem to be a more attractive choice.
The OP said he has 64GB already, may be more helpful if he elaborated on that. If thats 256 peices of 256MB modules I dunno WTF you'd do with that. But if 4GB modules installed in something like a 16-slot supermicro x7db8+ beast that could be fun
For all the talk about programs and data being swapped out, the biggest problems I've seen are systems to too much swap and not enough RAM. By the time RAM gets short enough for serious swapping, the system is already thrashing so heavily as to be unusable. For me the bottom line is that the machine must have enough RAM to fully hold everything that normally runs with room to spare + cache space, then think about swap to cover peaks.
That is not necessarily true at all. Linux likes to use swap even when there is plenty of RAM, since it can free it up for something more useful, like disk buffering. Anyway, you can be running out of RAM and eating into swap space and operate at nearly normal speed. It depends on how many processes are actively running, and what they are all doing. Swapping is not a bad thing. Excessing swapping to the point of "thrashing", is, however. In that case, actively running programs are competing for more memory and there isn't enough physical memory to satisfy them, even after buffers are reduced and everything inactive is already swapped out.
Now, if there is a BROKEN program that is gobbling up all the memory, yeah, it will always be a problem, since it will eventually consume everything, anyway.
It is unfortunate that most *ix systems don't handle running out of [physical+swap] memory very well.
We all know storage and memory prices will continue to fall as capacity rises, and 2x ram will continue to have about the same cost in terms of $ and percent of disk space used. However, where many people have been lead astray is that there exists a means to make your swap space as large as you want with no cost. Just do like me and map your swap space to /dev/null. Now you can have petabytes of swap space on any size disk with no additional cost. What could possibly go wrong?
I don't know about angles, but it's fear that gives men wings. -Max Payne
Now if I could only find an easy way to do the same thing with my MySQL server (I am a web developer and test on my laptop)...
... and it works like a champ.
now we need to go OSS in diesel cars
I have 8GB of ram and set it up for 16GB of swap... mind you it's never been used in any manner. For that matter I rarely see my available ram drop below 5GB free.
You've got 4GB of ram, you don't really need swap space. Swap space aka. virtual memory is only useful for pretending that you have more ram than you actually do. With 4 GB of ram, you pretty much have all the ram you're going to need...unless you are doing something that requires massive amounts of memory. I don't even use my 1GB of ram.
...and that is all I have to say about that.
http://jessta.id.au
There's no swap on my Ubuntu business server for extra security. No x windows. No desktop. No games. And zero problems.
I think I would rather have out of memory error then having the computer waiting for swap. Fail fast is good. I don't have enough apps running to run out of memory usually, and when my system does start swapping, it usually means something is wrong anyway. It would be nice for it to just crash then wait 10 minutes for it to finish swapping.
The above is not worth reading.
I never put / and /home on the same partition. As someone else pointed out, it makes changing distros possible without needing to restore a backup but it also makes upgrading the same distro easier. No need to format the /home partition when I went from Mandrake 10.0 to Mandriva 2007.1.
LK
"Hi. This is my friend, Jack Shit, and you don't know him." - Lord Kano
It does hurt to allocate a couple of gigs of swap.
:). If you have lots of RAM and are too lazy to guess, set F=0.
I use swap only to tell me that I'm low on RAM. Basically once the machine starts using swap and getting slightly slow- it means I'm low, then I can try to shut down stuff (without it behaving otherwise strangely, or dying abruptly).
Here's how I suggest you figure out _roughly_ how much swap you need.
1) Figure out the amount of Virtual Memory your programs and services _allocate_ without really _using_ - call this F. There are some programs that allocate hundreds of MB of memory but never use it. But note that there are some programs that allocate lots of memory and may use it
2) Figure out your drive throughput for swap access (swap in + swap out)- this is often related to random access throughput - and for a typical hard drive it could be in the order of magnitude of 10MB/sec - call this M. Note that many flash drives have pathetic random write speeds of 4MB/sec (or even less!).
3) Figure out the time you are willing to wait for stuff to swap in and out (e.g. time to get an ssh prompt- call this T.
Swap = F + T * M.
So for example, if you have programs that allocate a total of 100MB and never use it, and your drive swap throughput is 10MB/sec and the amount of time you're willing to wait is 15 seconds.
Swap = 100MB + 15 sec * 10MB/sec = 250MB.
As you can see allocating gigabytes can hurt - since it'll take days to swap in and out processes that are using gigabytes of swap. You'll run out of time before you run out of swap, and when that happens somebody will do a hard shutdown of the machine - and that means ALL processes will be abnormally terminated, rather than just one.
Yes, there are cases where the offending program might not keep accessing all of that swap, but when a program misbehaves like that, you'd rather find out sooner rather than have to shutdown the whole computer (because it takes ages to respond).
Running programs from swap is best reserved for those who wish to experience the 1950s drum memory days. If you want to do retrocomputing keep in mind that memory speeds are now much faster than disk speeds, whereas in the 1950s memory speed = drum speed, and most modern programs assume modern memory speeds.
Is there any point, with a 32bit OS, in having a swapfile bigger than 4 gigabytes?
I just (today) installed a new hard drive, 1 Terabyte, so I moved the swapfile to that drive, but kept it the same size.(2 gigabytes)
I have 3 gigabytes of RAM
I totally agree. In addition, there's also the issue of filling up partitions. Some times its desirable to have a partition (/var) dedicated just to things like logging, so if something goes crazy and uses up too much disk space, your programs are still able to log, and possible leave you clues as to what is going wrong, but I think this is a far less likely situation to occur.
You don't have a gig of swap utilized.
Patrick Doyle
I mod down every jackass who puts his moderation policy in his sig. Oh, wait a sec....
I rarely, if ever, use more than 4G of swap. And I'm talking on machines that do have 16 to 32G of FBDIMMs, and frequently have all of it in use. Why only 4G? Well, I like that number.. I've never once actually reached it. The software we use requires some swap to exist. But, I guess it all depends on WHAT you will be using the system for. If you're using it as a End-User System (I like that better than "Desktop" or "Laptop"), you may find out you need more, depending on what apps you're running. But, as others have stated, even if you create a 2G swap partition... if you run out.. create a swap file.. do a swapon on it etc.. and poof.. now you got that much more swap. It's like Windows' pagefile.. where it can determine how large a file it needs to create up to a certain limit.. but it's not automatic (and I'm sure there's a script/app out there in the linux/unix/bsd world that will automatically adjust your swapfile based on usage.
But, I think the Swap == 2x RAM deal has mostly gone away. It made sense when people had 256M ram, or on a decent midlevel system, 512 or 768M (I've also heard 1.5x and 2.5x from different sources), but nowadays, where you can have a a dual quadcore xeon with 128G of RAM... does it really really make sense to have 256G of swap? Unless you're doing something really really intensive, it just doesnt. Maybe highend CAD/CAM work, animation, etc, you might need it (Like you're making the next big Pixar movie on your 1 system!). But, really.. most users (even us on slashdot) arent going to need that much swap..
And I'd hate to tell the others at my company that we can only really use 2 drives in the 3 drive system, because we're using the 2x RAM == swap method, and needed an entire 400gig SATA drive for swap...(yes, using the supermicro systems that hold 192G ram, and quad six-core CPUs).
OMG... I have a sig?
Having pages on disk means you can use RAM for other things, such as disk cache. This makes sense when you've got "MemoryHungryAppYouArentUsing" minimised, and are using a program thats using half your RAM, and hitting a bunch of files on disk.
3laws: No freebies, no backsies, GTFO.
Feh. I have a ton of data from high school still available (well, kind of, they are old Mac OS .SIT compressed files, and I don't have any OSes right now that would understand their resource forks) using a slightly different tactic:
Back up your damned data!
I'm 29, BTW. The oldest file I have is a game I made in 1997, in Think C 5.0 IIRC.
Comment of the year
On what application do you get a 99.99999% TLB hit rate? I've never seen that on a real app.
Patrick Doyle
I mod down every jackass who puts his moderation policy in his sig. Oh, wait a sec....
i have 4 partitions on mine:
1 180(ish) gig fat-32 shared partition
1 10 gig ntfs windows xp partition
1 10 gig ext3 ubuntu partition
1 2 gig swap partition. (none of the responses so far have convinced me that changing this is really necessary)
this has similar benefits to your method; if i want to install a new distro, i can dump my /home to my shared partition and install away, then copy it all back to my new /home directory after the install.
(note: it feels neat to have mod points to use in my own /. submission. if it wasn't for this post, i would so be abusing my power right now, mwahaha!)
-I only code in BASIC.-
Heard of disk caches and prefetch?
8 gig of RAM fkn rules, its cheap as hell and Vista barely touches the disk until I use an app I haven't run in a while.
3laws: No freebies, no backsies, GTFO.
Swap is useless on modern hardware.
In the Pentium 1 era EDO RAM maxed out at 256MB/s and hard disk xfer was 10MB/s.
Now we have 16 GB/s RAM xfer rate and 60 MB/s hard disk.
Notice the difference? RAM transfer rates have gone up by 60x while hard drives only 6x. Hard drives did not keep pace with RAM and no longer provide a usable alternative to RAM.
Anyone who recommends swap doesn't understand what they're talking about. Swap is the new cargo-cult!
Over the past few years, colleagues and I have discussed this matter many times, and we seem to have settled on a 4GB swap standard for all UNIX/Linux systems. The majority of what we're working on are web and application servers, and honestly, if any swap ever gets utilized, it's time to add physical RAM. It's really there more as a temporary buffer in the event something spikes, but we monitor the systems close enough where that rarely even occurs.
When you're dealing with a business-critical application, you shouldn't be relying on swap to save you; if it's important enough to be running on server-class hardware, it's important enough to allocate enough physical RAM to keep the box happy. Yes, disk space is cheap, but RAM is cheap too. Losing business/customers because your server is running slow is not cheap; spend the extra bucks on more RAM.
Don Head
UNIX/Linux Administrator
I am one of those crazy power users. I've run multi-day mathmatical models ( GAMS, Integer solvers ), games, tonnes of applications, servers, you name it.
If you have more than 2Gb of RAM, don't use swap. Just turn it off. Seriously. The only out of memory error I've ever had since I turned off swap was while running a linear model that took 4 hours to finish. The PC had only 2GB of RAM, and JBuilder was using 500+ of it. Four years now.
With a 32bit OS, as is mentioned, there is no point at all in having a swap. In fact if you have 4GB of RAM and a video card with 512MB of RAM, Windows XP can only address 3.5GB of the RAM.
that matters. It's how you use it....
putting the 'B' in LGBTQ+
I am not even sure that with 4GB RAM 32-bit OS will ever try to use swap. Any kernel gurus?
If you're running Linux on IA32 then you can only address 4GB. Swap just extends your physical memory, so physical + swap cannot be more than 4GB.
So ... if you have 2GB of RAM, up to 2GB of swap could conceivably be useful. If you have 4GB Of RAM, then there's no point in swap at all.
These considerations go away if you use a 64 bit OS, of course.
I would recommend setting it to OVER NINE THOOOUUSSAANNNDDD
Until a few months ago, I regularly answered this question for enterprise Linux customers, so I humbly submit that my anecdotal experience is marginally more informed than most here.
Memory capacity and bandwidth is improving orders of magnitude faster than disk throughput and latency, and this has been true for decades. If the workload stays the same, you should generally have a lower swap/RAM ratio on newer hardware than older hardware, because it's so much cheaper these days to add more RAM, and adding more swap can actually make your system slower when you finally start using it, because it takes much longer to page in 8 GB of data from disk than 4 GB.
The kernel virtual memory (VM) subsystem is a briar patch of carefully-tuned code which, whenever altered, almost always causes a regression for some obscure combination of hardware and software that someone somewhere cares an awful lot about. This is not due to inherent bugginess, but rather the fact that the VM is essentially in the business of predicting the future, which is mathematically impossible to always get right. As a result, developers tend to be very conservative about VM optimizations, so the VM tends not to adjust its assumptions about hardware quite as quickly as the hardware itself changes.
The upshot of all of this is that as time goes by, swap becomes more of a lifeline for worst-case memory shortages and less of an optimization to make the system behave as though it had more memory. This is not to say you should do without it completely, but the ratio tends to keep going down. For desktop use, I've been using a 1:1 ratio for a while, and honestly, that's probably too large for how I use it. Digging out of 2X swap takes *more* than twice as long as digging out of 1X swap, because you end up thrashing back through the stuff you've already paged in and out before you get to the rest. Think of the Tower of Hanoi problem as an extreme worst case. Beyond a certain point, you really want the kernel to refuse memory allocations and/or invoke the OOM-killer to kill off your misbehaving app and restore performance for the rest of the system.
Whatever you do, you shouldn't go completely swapless unless you really know what you're doing. Having just a few hundred megabytes of swap on a huge 4-socket server gives you a buffer against out-of-memory conditions that could bring down the whole system. In this extreme case, it's actually *good* that swap is slower than RAM, because it stalls userspace page dirtying while waiting for I/O, leaving the CPU free for the kernel to scan for pages that should be paged out, faster than userspace can dirty them.
If you're stuck on a small system you can't upgrade, having a high swap/RAM ratio might still make sense, but modern hardware tends to have much more and faster RAM and only slightly faster I/O.
If you've got a carefully tuned database server that's reserving much of its memory for hugepages, you should start your calculation with the amount of *swappable* RAM, which is the RAM not set aside for hugepages. So, if you've got 16 GB of RAM, and 12 GB reserved in hugepages, you only want swap proportional to 4 GB of RAM.
The proportion itself is still a delicate matter. On a desktop system where you may open lots of applications, and then leave some of them idle for days while using other resource-intensive programs, it may make sense to go as high as 1x. On servers where latency is important, you probably don't want to go higher than 0.25. If you've got a batch compute system where you feed it a huge amount of work and expect it to be done when you come back several hours later, it can still make sense to have upwards of 2x as much swap as RAM. It might be sluggish to give you a login prompt, but that doesn't necessarily mean it's thrashing inefficiently if you have a fairly sequential access pattern.
If all of this confuses you, and your distribution recommends 2 GB by default at install time, odds are you'll do okay with that, at least for the near future. Once solid-state storage becomes mainstream, most of what I've said in this post will be completely obsolete.
There's no failure quite as dissatisfying as a complete and total solution to the wrong problem.
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.
There was a slashdot article on this a few years ago. It was a debate, but the kernel will try to swap out idle processes whether it's got memory or not.
It's been a long time.
For even greater flexibility have /home on an external drive and remote mount that. You have the advantage you mentioned and you have automatic backup* and can take it with you.
*Bonus points for a NAS with RAID.
Shai Schticks:"You don't make peace with friends, you make peace with enemies"
Yes. The i386 (whose memory model is still used today in all 'ia32' processors) can address 16 terabytes or so (don't know the exact figure) of _virtual_ memory. So while individual processes are limited by the 4gb (32-bit) barrier, there can be many such processes each with its own 4gb address space. You would then swap individual pages between HDD and system RAM as needed. In P6, PAE was added, so that you could 'swap' into high memory (system RAM addresses from 4gb to 64gb).
twice-memory came from the old (old) unix days (and is still applicable by the way) because a crash wrote memory to swap. the machine would restart, look for a crash signature in swap and if it existed, suck it back out onto disk for analysis.
Again, all still very applicable today (for unix).
having said that, so long as you dont need to analyse your crash dumps, your choice of swap size can be more flexible!
You are unlikely to be able to see all of your RAM unless you have PAE (CONFIG_HIGHMEM64G) enabled. Any memory mapped above 4G will be invisible otherwise.
Available swap will be used when there's memory pressure so that's a different issue.
I don't use swap for paging typically, but having a swap partition (not file) set to the same size as your RAM means that hibernate is possible.
fork() on most platforms needs to reserve the same memory as the parent process. The eventual exec() call may free up most of that memory, but if you don't have enough free memory to handle the fork() you'll get an error trying to fork processes. This is a pretty ugly problem for large enterprise server type of applications where the parent process may have 1, 2, or more GB allocated. In these scenarios, it's not always cost effective to buy more RAM if you know the fork'ed processes will release the vast majority of the memory when the exec() is called. Thus you make sure there's plenty of swap. when configuring such large scale deployments I tend to recommend 2x swap. Disk is cheap, and if you're in an enterprise deployment and you can't afford another disk for swap, something's seroiusly wrong with your budget.
Basic rule of thumb is the swap partition/file should be three times that of how much RAM you got installed in your system. Swapsize = (RAMSIZE * 3);
I have 1GB RAM on my 6-year-old PC at home, and allocated a 2GB swap partition. Monitoring swap usage suggests that the system rarely uses much of it, and the largest swap usage I have noticed is only 300MB. In principle, I could have allocated an even smaller swap partition, but since it's on a 400GB drive, the lost space is negligible.
The situation is quite similar on my 5-year-old laptop, which also has 1GB RAM, and a 1.5GB swap partition on its 80GB disk.
If I had more RAM, I'd have less need for swap space (except for suspend to disk on a laptop).
Those who can make you believe absurdities can make you commit atrocities. - Voltaire
http://www.tomshardware.com/reviews/hyperos-dram-hard-drive-block,1186.html
open source sub sim. I might start coding again for this. http://dangerdeep.sourceforge.net/contribute/
Why does everyone put their swap on a slow harddrive ? A Gentoo running mate of mine in the pub showed me how to map the swap file into RAM: runs much faster there.
(Although suspend does not seem to work now :-(
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.
These days I'm thinking zero. Disks are slow. Chip based RAM is fairly fast. Linux is certainly less irritating than Windows when memory gets low but still not great.
If I run out of memory it's usually a lot quicker to get an "out of memory" error and kill a few other applications than to wait for the swapping to sort itself out.
... to
swap = max mainboard RAM capacity
There should be conditions attached to this new rule though:
With a 750GB hard drive selling under $100, what has changed?
This is assuming that you have a 750GB drive. I don't. My laptop has 4GB of RAM and about 60GB of SSD disk. So no, I won't waste 8GB for useless swap. And even conventional hard drives for laptops are often not much bigger, MacBook Air come with 64GB, for example.
My experience: I used a laptop with 2GB ram for 2 years, as my main computer. I was doing quite heavy stuff, like running MySQL/Apache/memcached all the time, lots of open files, often Eclipse and often VirtualBox (which is memory hungry). I didn't see the machine swapping even ONCE, except from cases when I had some bug in my code which allocated infinite memory, in which case no amount of swap could help me. My new laptop does the same. All the servers I monitor do the same.
So my advice: start with a swap *file*, not partition, of 512MB. This way you have the flexibility to change it very easily and contrary to what some people might say, there's no performance penalty (especially if it's never used!). Quite probably is won't even swap. If it starts swapping you can increase it, or keep less programs open or buy more RAM. In most cases, when the PC swaps it will become so slow that you'll have to do something to make it stop.
The above assumes you're not interested in hibernation. If you are, then allocate a swap partition of 1x RAM, to be sure you can always hibernate. In theory you can hibernate in swap files, but in practice you'll regret trying.
I haven't bothered to look at the other answers but it's really simple.
It's best to allocate more swap than you think you will every be able to use.
Just because when you start to run out of physical memory the machine goes slower. When you run out of virtual memory (swap space) processes start getting killed.
With a modern disk on a 32bit machine I have had programs that use 3GB of virtual memory on a 512MB machine without a speed problem. So I would now say 4GB is the minimum. With a 64 bit machine you are limited by the SPEED of the disk so the problem is just how random the program is using memory. This is impossible to say as a general case so the twice memory rule is as good as any.
Of course this doesn't mean the OS needs swap, most will run fine without any but will benefit from a small area (say 128MB) to dump the data areas of programs that are started by never actually used.
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
I stopped having a swap partition about 7 years ago (whenever my machine's RAM hit the 256MB mark and RAM really stopped being an issue). RAM is copious enough that swap's not needed to run everything I want, and I like not having the chance of swapping sensitive information out to non-volatile storage.
Some of the suspend-to-disk packages need (or have needed) swap to work well, but most of the machines I run don't bother with swap nowadays.
rage, rage against the dying of the light
I have. But that doesn't mean I want to bother with restoring from a backup after I've reinstalled my OS.
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.
Man, that must be AWESOME porn. :)
awesome porn... starring the poster, obviously.
I have always been told that SWAP should be twice your RAM but no more then 512mb.
Oh, uh, good question. Now technically speaking, uhh, let's say, put me down as a... 'Whatever'?
a 5GB swap space. It's rarely ever used, but I don't want to get bit in the ass when I actually do need it and can't have it because resizing partitions isn't an option. I've had 1MB of the 5GB swap space used at the most (so far), so I guess I could tone it down and add 4GB to / . Either way, when you have a large enough hard drive, 5GB doesn't really matter anymore. If you've got an 80GB hard drive (Like I had before I bought my 500GB), it's a pinch. I had 2GB swap on that.
Is there any point to separate partitions for / and /home?
IMO there's no other safe way to do it. Here's an example why -
Let's say a runaway process fills up /var/log, trashing that particular filesystem. If /home is on that filesystem it also gets trashed and is the reason why I always put /var on its own partition if I'm building a server.
Also, on my test box that doubles as a home media server I tend to run late alpha or beta versions of Linux distributions - if something breaks and /home is on a separate partition I can reinstall or even change distributions without losing data or settings.
we see things not as as they are, but as we are.
-- anais nin
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.
I am TheRaven on Soylent News
For windows, if you are a consumer you need 4gb of memory. Always have a small amount of swap (100mb) as I find that windows becomes unstable without it. If your
RAM -> Swap
1gb -> 3gb
2gb -> 2gb
3gb -> 1gb
4gb -> 0gb
5gb -> 0gb *
6gb -> 0gb *
8gb -> 0gb *
* Why do you have more than 4gb memory? You need to look at your applications. If you are using photoshop you may need more memory. Rule of thumb: for each large application (photoshop, database) use an extra 1 GB of swap.
* If you have 8gb of memory and you are hitting swap you probably need to tune your servers and applications. If you have 10 applications you would have 10gb of swap. A well tuned server should use very little of that.
* If you have 4gb of ram and have 2 large applications then you have 4gb of memory and 2gb of swap.
Its basic math - you cannot divorce your needs from your usage and have to recognize that if you overload a server it will be sub-optimal. A server should ideally average 70% CPU and 70% memory usage to cater for spikes. Too much swapping will slow you down.
With a move to visualization it becomes more important to be friendly with shared resources and thats a whole different topic.
Your RAM doesn't require any swap space at all.
If you have enough RAM to run all your apps with no swap space and space to spare, go for it. It's the best. Chances are you will one day hit out of memory errors, though, but then you can just add some swap space again.
The 2x rule of thumb is meant as a recommended upper limit.
The whole idea of swap space is based on the assumption that you can never get too much RAM. Since RAM is expensive while disk space is cheap, and not all of the RAM in use is actually being addressed at all times, it makes sense to use some disk space to emulate more RAM than you really have.
But if you actually use enough memory to fill up more than 3x physical, chances are performance will really start to suffer because most of the time will be spent waiting for disk IO instead of doing jobs designed to work against low-latency RAM. It can still be the right thing to do sometimes, if you really need all that space for one app to work, and can live with the sluggishness, but for most users it would just encourage needlessly bogging down the machine.
sudo ergo sum
We're not in the old times where your 64MB Ram just weren't enough.
You don't need Swap. Really NOT.
You might want to have some, in that case a tad more than your RAM, if you want to do suspend-to-disk. But otherwise, Swap is just a waste of space.
"The more prohibitions there are, The poorer the people will be" -- Lao Tse
If they have a 10GB drive, chances are they need to upgrade to a faster hard drive as a number one choice. Other than SCSI, 10GB drives haven't been made in a while.
This was done so that you would be able to process a kernel core dump. The only way to save core, as the kernel dumping itself into your swap region.
Sure, swap was also used for paging from real memory, but anyone who works in computing "should" know that disk is much slower than RAM. Applications should only hit disk when absolutely necessary. Hence, if you are in disk swap 100% of the time, then you have under-scaled your hardware for the tasks it's performing.
Now if you plan on trying to debug kernel core files, keep more swap than memory. Every bit of memory has to be dumped for a proper core.
For people who are not debugging core files (which is a very large percentage), only create as much swap as you need. AKA. Add file swap when you get "Out of memory" messages.
-The wise argue that there are few absolutes, the fool argues that there are no probabilities.
I do the same, but i just have to back up /home and /usr/local first... The issue with separate partitions is you can't always anticipate your space requirements up front..
But the logical hierarchy unix uses to store it's files makes a lot of sense, and makes it easy to move from one machine or distro to another.
http://spamdecoy.net - free throwaway anonymous email - avoid spam!
Double your memory until you reach 1GB of swap. Basically, if your swapping anywhere near a GB you're PC or server is severely memory starved and probably has the performance of a sleeping turtle.
I used the 2xRAM rule of thumb until I got to about 2GB, when I decided 4GB of swap is just ridiculous. Now I put 1xRAM just in case there is some engineering quirk in some software that relies on it. 2xRAM these days simply must be waaaay more than excessive. 4GB of RAM should be enough for everyday *at this particular point in time*. ;)
I usually install stuff to ~/local/PROGRAMNAME/, and then make symlinks from ~/local/PROGRAMNAME/bin/* to ~/bin/, etc. A little like the GoboLinux. It might get trickier when one package depends on another, but I hadn't run into any of such. Also, if you're sharing /home with machines with varying architectures, a more complicated hierarchy would be feasible, like ~/local/ARCHNAME/PROGRAMNAME/, and maybe ~/local/ARCHNAME/bin/ for a collection of all executables for that arch, and a case statement in your .bashrc (or whatever shell you use) to set the PATH depending on the host name or uname.
I can see at least three advantages if this scheme... You don't need root to install your software, it's easier to maintain the stuff (the additional PROGRAMNAME/ directory), and there's no need to clutter /usr, /usr/local, or have another separate partition.
Eventually gets trickier if you'd like to share these packages with other users of the machine (that's the only case where I'd use /usr/local).
My relatively simple rule is twice the amount of RAM until you hit 1GB of RAM. Systems with between 1GB and 8GB of RAM will get a 2GB swap. Systems with 8GB or more I would probably give a 4GB swap.
That assumes the requirements of the system don't dictate having more swap than the rule above for some reason. And if they did, it probably means the system needs more RAM anyway.
I've read that the minimum should be 1.5 times the size of the installed RAM. The reason: If (or when) the OS crashes, the entire memory dump can fit inside the "swap file". Are you developing software that when it crashes you have to read a memory dump? Would you need to provide a memory dump to a software vendor to assist in resolving crashes on your laptop? If not, the 1.5 rule is probably not necessary in your situation.
Not even Windows crashes from out of memory conditions anymore these days. It will also kill the process deemed most offending and continue.
Why are most of the answers about Linux? Do we know the uber-parent is running Linux? No. Should they have specified? Yes. However, as they didn't, each post that attempts to be useful should, at minimum, cover NT, Linux, and OS X.
Slashdot: Playing Favorites Since 1997
I have a rig with 4 HDDs. 2x Raptors and two larger drives for just mass media.
One Raptor is used for gaming files (faster hard drive, faster loading of games and maps) and the other raptor is split for Vista and Ubuntu
The question is what drive should I be putting the swap on, especially if I am going to attempt to get games to work on linux
Set your swap up in a logical volume. You can always make it larger at some future date if you actually needed it. 99% percent of people won't if you just keep it one to one. Heck, above 4GB I'd start going half. The reason you don't want a large swap is that it takes a long time to write and/or read 8+ GB of data off of a standard hard drive. If you are using that much swap and often, you'd be much better served increasing your system memory. Swapping in general should be avoided because of its high cost, and should just be a safety net for those times you exceed system memory. If you are always exceeding system memory, then again, increase your system memory. IMHO anyway.
I'd just use the entire hard drive for swap and use RAM disks for my filesystems.
Having done this when I upgraded my aging Gentoo box (which I never managedto get configged sensibly) to Ubuntu, I will ALWAYS try to do it in the future. Being able to mount my old drive and copy over things like Apache configurations (or at least read them so that I could see what I wanted to keep vs what I wanted to change) was exceedingly nice.
For the average non-graphix oriented linux user in the modern 2-16gb-of-ram-world, a swap space of 2048mb is enough. To go over that means your hard drive takes longer to seek over a larger area. I'm sure there may be situations that demand more than 2gb of swap space, but as an average* linux user with say 4gb of ram, you don't NEED 8gb of swap. its overkill and you will actually see a performance DROP instead of increase. *by average I mean most common uses of linux, not average experience.
I'd never had a system with so much RAM before (1GB!), but then I'd never routinely used programs that used so much RAM before (Windows XP, WoW, etc.).
I wondered about this too (even though I'd used the old rule of thumb: allocate twice RAM size to swap file). So I found a freeware utility that measures how much of my Windows disk cache is actually being used. And then I ran all my usual things, my games, everything, over a period of days.
Guess what?
Windows Disk Cache would be used once, approx 25MB or so, at startup (I suspect Windows just feeling around to see what's there), and then never again touched.
So I pointed my disk cache file at an old raggedy 5GB hard drive I stuck in the system as Drive D: and never looked back :-)
posix_fadvise and posix_madvise seem to be standard posixy way to give hints to the cache. madvise(..) and fadvise(..) also exist granted some of the kernels don't properly use the hints.
That's a good strategy too, and I like the architecture thing you've got... I have a setup kind of like that at work since I sometimes have support i386 and x86_64 Linux, and Solaris SPARC.
But at home, I do have to have many packages I build available across accounts. I have a "usrlocal" group and /usr/local was set 775, plus a g+s. My primary account is in the usrlocal group, so I can put things there without su or sudo.
There isnt a good reason to swap when memory can do a much nicer job. The next generation of chipset needs to abuse the cheap ram in wild ways. I want a box that will take 128 gb, and will barely touch the hard drive. I dont want some DLL loading into memory.. I want ready and willing as soon as i need it. I want windows to load, and never need to re-read
Storm
So the general complaint with people who do not like swap files is that they are slow. Instead of eliminating the need for a swap, why not just bring your swap up to speed with a ramdisk?
There are two out that I know of. One by Aspacia, and one by Gigabyte. Both of which require external power sources, but connect directly via SATA, or through the PCI bus! You end up with a 'disk' the size of the modules you placed on the ramdisk card, and viola! Stick your swap file or partition on that disk and you now have a swap operating at the saturation point of whatever bus it is connected to.
Aspacia Rocketdrive: http://www.aspacia.com/Products/Hardware/SSD/rocketdrive.htm
Gigabyte iRAM: http://www.gigabyte.com.tw/Products/Storage/Products_Overview.aspx?ProductID=2180
Headache solved.
First, I make sure that my machines have adequate RAM for their usage. That includes sufficient disk cache.
At that point, swap doesn't do a whole lot. I don't need to move programs out of RAM to run new programs. And I don't need to move long-unused programs out to make room for disk cache.
Now, occasionally, truly obscene things happen that make the machine need far more memory than it actually happens. If the machine has cache, then it starts thrashing, swapping, and going into a big, unresponsive death spiral, affecting all other services on the machine. Not a good solution.
If the machine doesn't have swap, then the offending memory hogs get killed (or simply can't continue in their consumption), but other services have vastly more chance of continuing undisturbed.
Swap is nothing more than a way to replace RAM with disk. That made sense when RAM was outrageously expensive, but prices have come down to less than 1/1000th of what they were in those days.
Except in truly unusual situations, there's simply no more economic reason to replace a good medium with one that has a thousand times more latency, and less than a thousandth of the bandwidth.
Oh, you're not stuck, you're just unable to let go of the onion rings.
If you have 4 GB of RAM and you consistency see that a considerable (500 MB) amount of physical memory is FREE, I would NOT suggest that you have a SWAP space at all.
Then again, I am a windows user, and have 3 GB RAM and 0 GB SWAP. This lets my programs be faster and snappier.
So... why not spend an extra $10, and have an extra gig of memory that would, at the least, provide more disk cache - and possibly provide for situations when you actually need more than a gig?
The days of people only being limitted to a gig by economic, chipset, or number-of-slot limitations has mostly past us by. 8 gigs of good, decent memory can be had for less than $100.
Oh, you're not stuck, you're just unable to let go of the onion rings.
Its all just buffer cache between the CPU's registers and the disk's storage.
How about a new market for RAM?
RAM that is larger, lower power and slower to fit between VM and RAM; or possibly replace main memory while the current memory moves towards being a larger form of 3rd level shared cache between CPU (and GPU?)
It may be an extra level of little benefit at this time but as GPUs and CPUs converge another buffer to address the needs of a big enough class of applications might become viable.
Democracy Now! - uncensored, anti-establishment news
I don't break out /usr/local to a separate partition (although I can see why it can be both a good and bad idea to do so), but I definitely break out /var/log. If I have a log file get unusually large (/var/log/syslog due to iptables logging, for example), I don't want to fill / .
/home into a separate partition for the same reason you do :)
However, I always break out
MCSE? No, sir...I don't do Windows. Yes, I am an idealist. What's your point?
Actually this is the reason why I disabled swap all together on my box. I have 2 GB of RAM in my machine which is totally sufficient. Once I disabled swap the system became really snappy. Before when I Alt+Tab'ed between applications, I always got some time lack before the application appeared. If you don't use more memory than your physical RAM then disable swap! Thats the biggest boost in performance you will get on your desktop - sad but true.
Paging gives you a lot more than just extra memory when you run out of physical RAM. On a modern OS, disk reads work by mapping the relevant part of the disk to the virtual address space, then transferring these disk sectors to physical RAM when they're read. This way, the disk cache is neatly integrated into the memory manager, which I don't think you'ld want to lose, even if you do decide to get rid of your swap space.
Forgive me for not reading all the posts, but I did get through those moderated high, and I'd like to clear up the reason (if not the true historical origin) of the 2x RAM rule for swap.
The actual reason to create a swap area (through file, dedicated partitions, disks, etc) that is sized at 2x physical RAM is so that you can both:
a) reserve swap pages equal to total ram.
b) swap out idle process pages equal to total ram.
Many applications reserve virtual pages in the swap area to ensure that in the event the memory manager pages the application out to swap there will be enough swap available to hold the process. Oracle is a perfect example of an app that, by default, will do a disk page reservation for portions of the SGA and PGA. So if you've got a server with 8GB of memory + 8GB swap on which you've allocated 6GB to the oracle SGA and PGA, you'll see around 5-6GB of swap utilized once oracle's up and running, even though no portion of the process page space is actively residing on disk.
Now, if that's the case, then what happens when your memory manager needs to actually swap something out of physical memory to virtual (disk) pages? Well, the system has a lot less virtual page space to work with, and it's possible to encounter allocation issues if new processes are started. To avoid that problem, you add another 8GB of swap (working off the 8GB physical ram example). Now, even if you are running 8GB of programs which require a one-to-one ratio between physical pages and virtual page reservations, there is still enough swap available for the memory manager to swap ALL of the processes in physical memory out to disk and allocate physical memory to new processes.
Now, is it ever going to happen that you actually end up needing to both reserve swap == physical ram AND swap out your system's RAM worth of processes? Not if your admins have the first clue what they are doing, no. :) But by using the 2X rule, you pretty much idiot-proof your memory manager for any application profile and any OS.
Of course, if you are knowledgeable about your operating system and the actual usage of your server, you will almost never take this generalized approach. Modern Unix OS's and applications normally will have alternative configurations that allow you to avoid swap reservation (v_pinshm, for example, in AIX 5.3 and later), as well as tuning the behavior of the virtual memory manager to better handle situations where the system has a low free page count. It's important to remember, though, that the consequence of allocating too little swap is the memory manager killing processes to recover free pages, and in a production environment, the process it kills will inevitably be the one resulting in you receiving a 4am wakeup call.
Personally, I will usually run with swap space == total physical memory, and upgrade the server the minute I start seeing page outs to disk. That's probably not an option for the desktop unix crowd, but it's a good rule for any unix servers running an application that requires even the lowest level of guaranteed performance. Swapping is bad. End of story.
Thanks for your time, and as always, I reserve the right to be wrong.
If your using Exchange 2007 with 4 gigs of RAM I recommend at least 4 times that for swap, maybe 5, even if you only have a 1GB information store. Other than that (to get it off my chest) I just make it some remainder of the disks I use for a RAID array so for 4 GB on a desktop it comes out to 2GB.
BTW, exchanges 2007 admins I'd love to get information on what I f*ed up if you don't get that kind of RAM usage because I've done multiple installs that consume these kinds of resources and crash the Information Store.
1) Donot turn on swap.
2) If there's ever any problem with memory, create a swap file (if you don't have one yet) and type swapon on a live system.
1) is not the best idea, at least for Linux. One of the things the Linux kernel can effectively use swap for is defragmenting memory! Swap a chunk of memory out to disk, and read it back in at a more suitable location. A long-running, hard working kernel will reward you even for a measly 256M swap partition - eventually.
2) Swap files are significantly slower than swap devices. Consider this: Your swap file lives on a filesystem. Your system decides it's struggling with memory and begins trying to swap some cached files out (it may assume that swapping them out and back in again is faster than re-reading off the original disk)... potentially onto the same disk the originals come from, causing more thrashing. It may even have to consider whether it can to swap out bits of the swap file! Plus you're dealing with filesystem layers which will only slow down the process... so give it at least one device/partition as a priority, and add swap files with a lower priority for temporary/emergency purposes only, if you care about performance.
The amount of swap any system requires is very situation/application dependent. If your system isn't using swap much at all, then good for you! Don't throw a lot of swap at it! But be nice to your Linux kernel, and give it something to use for its own sanity.
Here's the thing - unless your main nonvolatile media is as fast and smaller than your RAM swap is still useful. What can happen is that pieces of RAM that are very rarely used (e.g. a program that starts up does something then goes to sleep indefinitely) gets swapped out (which initially seems bad because you're going to pay a large price if you ever have to swap it back in). However that RAM is now free for other uses like caching your disk. So disk access to data you've already read which may involve seeking on rotating media and a lot of waiting now become as fast as your RAM. If you have no swap this tradeoff can never be made and the RAM is effectively never reused.
Looking around this Kenreltrap article contains a thread where someone asks is swap necessary? which might provide a better explanation than the one I've given.
The memory manager should be able to cope without swap - there's even a kernel compilation option to not have support for swap at all...
I'm using an EeePC without swap and (thankfully) it doesn't suddenly burst into OOM errors at the drop of a hat so I'm curious about your final paragraph. Are you thinking of overcommit related issues? Could you link to a reference about the poor Linux MM behaviour when running without swap (note this is different to using memory for cache)?
..shows a massive improvement. When data you are fetching is scattered over the "disk", the lack of having to wait for the drive to seek to the data before reading it is huge. Sequential throughput of a read on an EeePC SSD is lower (perhaps only 25Mbytes/s?) than that of a regular laptop disk (the speed that both EeePC internal drives get configured to is UDMA 66) but it's hard to arrange for all workloads to be sequentially arranged on disk without perpetually defragging and having only a single reading process at any one time. On parallel read with no writes at all (e.g. early startup) workloads there's often a noticeable win.
Hmm. That's a real problem alright (but probably only noticeable in longer running but partially idle workloads). There are patches floating around that might help to solve in the form of Rik van Riel's split LRU patches. Note tat patch is not yet in mainstream...
Guess how many times I've thanked 8 lb 6 oz baby Jesus that I had the foresight to separate the two? All my data from my college days is still intact under /home.
I never bothered to separate / and /home way back when. Guess how many times I've cursed 8 lb 6 oz baby Jesus that I didn't bother? Zero.
I keep these things called "backups". One day, I wanted to switch from Slackware to Debian, so I followed the following procedure:
Glad you did plenty of good praying, though. I'm sure it will help you in the afterlife, despite it's lack of relevance with respect to your superior foresight.
They don't grade fathers, but if your daughter's a stripper, you fucked up. --Chris Rock
(Reposted to combat stupid children who mod everything as troll)
(and stop modding down people you don't agree with)
I was excited when i bought one, only to find its not very good, Windows stutters and freezes and is not a fast machine.
The claim is that it would last about 170 of normal use - but now everybody (like you) are saying ooh, you can't write on it because that will wear it out.
Blaa
If Google really cared they would fix Android Chrome to reflow text, instead of discriminating