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.
I haven't made a swap partition in years. I've got 2GB; if that's not enough, then one of the processes is leaking memory like crazy and using a swap partition is just delaying the inevitable. If you ever do need to use extra memory, you can always make a swap file (not partition)
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?
Linux? Windows? Mac OS X?
Ant(Dude) @ Quality Foraged Links (AQFL.net) & The Ant Farm (antfarm.ma.cx / antfarm.home.dhs.org).
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.
Guess what... you probably could get away without ANY swap! How often are you planning on using more than 4 gigs of RAM?
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.
It depends on the size of your hard drive. I wouldn't recommend an 8 gig swap partition if your hard drive is only 10 gigs. Think about 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
I'd suggest about 50G of swap.
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/
With the exception of specific applications, having large amounts of swap space is not overly important in this day and age. Its a good idea to have it around for infrequently accessed bits of memory to be tossed to, but if your system actually gets to the point that you're swapping actively accessed memory to disk, you're going to see serious hits on system performance. I recommend only having ~2G of swap on systems you're not using suspend to disk on, and just matching the amount of ram in your system (maybe a hair more) on systems you're going to suspend to disk on.
Note: This is very general. You need to be aware of what you're using the machine for in order to make a good call. Some applications (I'm looking at you Oracle) depend on you having gobs of swap available.
unless you're suspending to disk or something that requires a mirror of actual RAM on the disk, kind of hard to come up with a reason for swap.
my box is linux running 4gb ram with vmware taking up 2gb. still plenty to run openoffice, firefox, etc without any swap at all.
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.
Depends on if you want suspend to Disk in linux
If you're on Windows, it's easy enough to determine how much you actually use (it might also be easy on Linux, I just don't know how). One of the menus of the task manager has a place to select which columns to show, two of the available options are Virtual Memory and Peak Virtual Memory. Show those columns, leave task manager open (it helps to show it on a second monitor), and then run a bunch of applications and start using them. The second monitor helps with games, I was able to run Crysis the other day with task manager open on another monitor to watch the resource usage as I was playing and loading things (if anyone cares, it used between 950MB-1350MB on a XP system with 2GB physical). Also on the bottom of task manager is a "Total Commit" line that shows the used amount of RAM+virtual and the total available.
The numbers for task manager probably aren't going to be exact, but when we're dealing with 4-8GB it doesn't matter if it's accurate down to 1KB (or even 1MB).
I find this an odd -- yet fitting -- question to ponder, having just watched the "2 girls 1 cup" video for the first time.
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
In my experience, the 2xRAM guideline was useful for engineering workstations, because a working problem larger than that would effectively not complete in a reasonable time.
I.e., you could run a problem that spilled into swap about that much, and still get results in a small-integer multiple of the expected time. Like, noticing swapping and deciding to get more soda, or lunch.
If you needed to run a problem that required 10x RAM, you might as well just fail quickly. Then the operator could make sure you were going to both add a swapfile, and start the run on Friday before going home. Or else reconsider.
There is probably a similar experience with multi-user systems, perhaps a different rule-of-thumb, based on how many users would be compiling or running, and how many buffers would be visible, etc. That scenario probably has NFS-mounted homedirs, and so a file in swap is significantly faster to access when the user goes back to it than re-reading it from disk.
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
swap_size = min(2gb, max(512mb, phyram * 2))
With more than 2gb your machine will surely crawl due to massive disk storms, with less than 512mb the Linux VM may not be happy (sometimes it just HAS to swap or go to the oom-killer). 512mb is probably overkill to prevent that scenario, but that's what I use.
perl -e 'print $i=pack(c5, (41*2), sqrt(7056), (unpack(c,H)-2), oct(115), 10);'
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.
the answer is: It depends.
If this is a personal computer, set it low or not at all...see what happens. If you need more, increase it (don't be afraid to use swap files).
If it's a server, try to get a feel for the software that will be running on it and set it accordingly. Over allocating isn't a bad thing unless you have resource limits.
--AC
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.
I noticed when I exceeded 2 gb on both the Wintel and Mac side my page swaps dropped to 0 page in/out.
With a 0 swap in / out I have eliminated ALL my swap spaces. I have over the years encounter too many problems with hard drive failures / errors and the operating system to not recover from simple errors which will occur with year of writing the same data over and over (frequently it is the few processes that access these swap spaces anymore).
Also if you are running Photoshop - creating a dead drive space for just the swap disk is useful when working on LARGE data . . . Earse this space / drive from time to time to eliminate stupid errors that develop over time (shame there are few simple methods to do the same for vitual memory spaces).
Once upon a time, a soon to be mommy and daddy loved each other very much (the lust was strong as well as the drinks)
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.
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.
Indeed, that was a common saying during the 90s. Since then, lots of things have changed. Among others, memory is cheap and disks not at all dramatically faster, to the point that managing them (HDDs) might actually slow down your system. There are reports that disabling your swap completely actually *increases* your system performance, because the VM code management overhead is gone.
In practice, you will need some swap so that your system can gracefully degrade in times of memory need, and will just eventually slow down instead of crashing applications (and data) here and there. Read for more on OS terms: "Trashing"
If you look here, on middle of page #6, even High Performance Computing sysadmins (Hi LCG people!),
are nowadays departing from 1:2 memory:swap ratio.
http://arxiv.org/abs/0705.1915
In fact, my recommendation would be to go towards something like 2:1, 4:1 or even more conservative scenarios, unless you have a *reason* to do else.
The graphs mentioned above do the same. Note that for practical reasons it is customary to keep the memory:swap ratio a (negative) power of two.
Note that swapfiles can always help you in case you run tools like "varnish" and find out you are low on virtual memory.
"Old tradition" is not a good guide in systems administration. Thank you for asking, you are one of few, that actually challenge bad habits...
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.
#include /*printf("Comparing stored value to 1\n");
#include
#include
#include
#include
#include
#include
long long int *x;
int main()
{
long long int i;
long long int *p;
long long int *q;
int bignum=1024+1024;
p=x;
printf("mallocing alot\n");
p=malloc(1024*1024*bignum);
if(p == NULL) {
printf("error no more memory.\n");
exit(1);
}
printf("entering loop\n");
printf("Filling memory with 1's.\n");
for (i=0; i (1024*1024*bignum)/8; i++){
p[i] = 1;
}
for (i=0; i (1024*1024*bignum)/8; i++){
if (p[i] != 1) {
printf("compare error\n");
}
}*/
printf("exiting loop\n");
printf("malloc'd alot\n");
printf("Done\n");
sleep(5);
printf("freeing memory\n");
free(p);
return(1);
}
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
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.
Everything is just right about that comment, except that thrashing is thrashing and not trashing...
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 server has 4GB ram and I don't choose to even bother with a swap file. If Linux _needs_ a swap file then we can question the stability of Linux's memory manager. I have tested it various times under load and the ram usage never goes about 2.75GB.
Also even if you do maje a swap file or partition disk space is cheap enough that those 8-12GB space is so small compraed to the price of HD 4 years ago. I have a RAID 6 2TB array even I didi choose to have a swap partition I could easily afford even a surprising 15GB swap. Chances are with 4GB of ram you can completely shut off paging and still have a stable server.
This is one of those things which is a matter of taste. Some people thing having swap 2 x ram is enough some make it the same amount as ram and other who live of the edge turn it off and use swap files as needed. Since swap files can be disabled enabled on a live system there is no need for a complete partiton dedicated for this.
IF the server is loaded and the server laggs a bit adding a swap file will temp resolve the issue without the need for a reboot.
This is the case on FreeBSD not sure how it works in Linux nor do I care much to even test it.
It's what you do with it.
Also, you might want to consider some kind of memory protection if you're gonna be doing a lot of swapping. Leads to viruses, you see.
I believe you need to have swap space that is *at least* equal to the amount of RAM in your machine. When I set up a machine with less swap space than the amount of RAM installed, I saw applications crash under load with "... bad alloc ...", or "Could not fork: not enough space". I reinstalled the OS with swap space equal to RAM and all of my problems magically went away.
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
We run on machines with 8GB of Ram, IT set the swap to 1GB. If you actually run out of ram, RHEL4 crashes in linux. (It begins by going real slow, but in the end, does nothing at all).
Compiling with -j 80 will crash it.
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
On Windows you could set it to automatic management.
Most newer machines are running atleast 3GB+ RAM.
So i don't understand where Swap will be required for common usage.
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.)
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. :-)
<outrageously thick Australian accent>
I see you've played baby-Jesus-thanks-counting game before!
</outrageously thick Australian accent>
Arguably RH is the authority on the subject... See their documentation here.
-m
http://www.invisik.com
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?
Alright, don't know if anyone brought this up yet, but whatever the guy said about oracle... correct. That is about the norm. For a SERVER...
I say once you get to =>2GB of RAM... use 2GB max of swap/virtual memory. The other thing about swap files vs swap partition... garbage. The only time you see a payoff with any swap file, is if you dedicate the swap file to an independent physical drive. If you put a swap file anywhere on a RAIDed volume, you'll actually lose performance, i.e. a partitioned space on a RAID5 volume for example or if you create a swap file on a whole mirrored set.
Hope that helps.
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.
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.
In windows, I have a pretty powerful desktop/workstation setup. Windows Vista 32bit though so only 4Gb ram. Whenever I set the swap file greater than the default 3.9 managed by Vista, I found many common games would crash with page address errors.
Your prof is incompetent. Either he doesn't get operating systems, or he simply couldn't get you to get operating systems. Regardless.
Memory isn't sliced into pages for any reason that has to do with paging to disk. Ram exists in pages to make dynamic allocation possible. You want a contiguous 1MB block of memory to store some image? Okay, we can piece one together from 4k chunks scattered about. Oh no pages? Well damn, you simply do not have a contiguous 1MB chunk free, it's all split into lots bits from space left over as programs started and stopped.
The 36 steps is also completely misguided. Yes. There are lots of steps involved at some point or another, but 99.99999...% of the time the system is performing two steps: TLB cache hit on Virt->Phys, and fetch the memory. The case where it has to go to swap is slow and complicated, but since the disk is 1,000,000x slower than your CPU it really doesn't matter much how computational expensive paging in is.
42
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.
Look, if you code your overlays (http://en.wikipedia.org/wiki/Overlay_(programming) properly, you shouldn't need much more than 512K of swap space. Just think through your program carefully and keep in mind the most likely execution paths.
Swapping is what happens when you run out of RAM. If you have plenty of RAM, you don't need swap. If you have a small amount of RAM, you'll need/use more swap. If you need more than 2GB of swap, what you really need is more RAM because you're swapping too darn much. The ideal computer would need 0 swap because it has infinite RAM. Swapping is not desirable. Assuming that we're only talking about laptops/desktops here (not super, research computers or specialized equipment):
while swap = 4GB
swap = ram / 2
if that rule leads to poor performance, you either need to: :)
1) get more ram
2) stop using vista
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
No, "how much swap do I need" is not meaningless. It's just very hard to answer in practice, for the following reasons:
Of these, I think the second is the hardest one, in fact, so the reason it's hard to estimate how much swap you want is because the load on most machines is hard to measure and predict.
Anyway, a simple (or simplistic, perhaps) theory that applies here is that to maximize your machine's throughput, you need to minimize disk I/O. To minimize your disk I/O, your kernel's whole working set needs to be in memory during every interval you measure this working set.
A working set is the set of all the memory pages and disk blocks that your processes touch during a specified time interval. If the working set is bigger than physical memory during an interval, then at some point the kernel will need to do disk I/O, which is what you minimize. If the whole working set is in memory, however, you are (almost) guaranteed that the machine will not need to go to disk during that interval at all. (Big exception: writing to disk.)
So what you really want to do is to have enough physical RAM so that the whole working set fits in RAM over some well-chosen small interval size, and enough swap to fit all your non-working-set virtual memory pages in the same time. You want to pick the interval size on the basis of your disk throughput and latency. The goal, again, is to minimize the time the system spends waiting on disk I/O, whether the I/O is for file blocks or swap blocks.
The most important, counterintuitive rule to remember: the cost of the following two things is more or less the same:
If the kernel swaps out a memory page and later has to read it back in, it breaks even if in exchange for that cost, it avoids reading the same filesystem block twice by caching on the first request and then using the cached copy on the second.
You don't have all your /home files on a backup drive already?
When you run your system, you can look at the %utilized swap space in system monitor. Use an estimate of your "max daily load" to get how much swap is actually used. Then allocate 10% to 50% more swap space depending on how confident you are with your estimate. Be sure to use a nice power of 2, 256MB, 512 MB or 1GB.
As a point of reference, I run Ubuntu 8.04 with 2GBs of RAM and 1GB of swap. With Firefox, a bunch of other apps, and a virtual machine of Windows running with 512MB explicitly allocated for the virtual machine, I have never exceeded more than 1% swap utilization (102MBs). With 4GB of RAM I would recommend 512MB ~ 1GB of swap space.
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?
Doubtfully, anyone interested in this will have gone on by now, but I hope someone gets some use out of this information. First off, this is only for Windows 2000 and XP, so I don't know if it will work for Vista. I can't imagine that something similar doesn't exist for Linux, Mac OS X and/or one of the BSD variants (I haven't read all of the threads). You might want to read through this page, 'How can I optimize the Windows 2000/XP/2003 virtual memory (Pagefile)?' http://www.petri.co.il/pagefile_optimization.htm -- Bill James (Microsoft MVP) has a convenient tool, 'WinXP-2K_Pagefile', for monitoring the actual usage of the Page file, which can be downloaded {here}. A compiled Visual Basic version is available from {Doug Knox's site} which may be more convenient for some users. The value seen for 'Peak Usage' over several days makes a good guide for setting the initial size economically. Available here: http://billsway.com/notes_public/WinXP_Tweaks/ http://billsway.com/notes_public/WinXP_Tweaks/WinXP-2K_Pagefile.zip or here -- http://www.dougknox.com/xp/utils/xp_pagefilemon.htm http://www.dougknox.com/xp/utils/XP_PageFileMon.zip Currently, I'm running Windows XP Home with 1 GB of RAM. I have my swap file set to 500MB and currently, the 'WinXP-2K_Pagefile' script says I'm only using 86MB of it. One of the scripts logs the maximum swap you've used in a session, though you have to check it. The most I've used is 486MB and it warned me that swap was getting low. Needless to say, you milage will vary. -- You also might want to read through this page. 'Virtual Memory in Windows XP' http://aumha.org/win5/a/xpvm.htm I hope this helps.
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...
Linux's kernel assumes that there is swap, especially for OOM conditions. First, there is the overcommit behaviour -- by default it lets you overcommit by your total swap size + 50% of RAM. If you have no swap, it will only overcommit to 50% of RAM, which is bleeding stupid.
Also, tmpfs is NOT taken into account by the kernel when it's figuring out how much freeable RAM there is (file cache is considered freeable, because it's not really needed and can be flushed to disk). I'm pretty sure this is a bug, but try reporting it to the kernel people and they'll probably say "why would you ever run without swap?"
This means that if you have 2 GB of RAM and 1 GB of files in /tmp and /tmp is in RAM, the kernel thinks it has 1 GB more available memory than it really does. When it runs out of memory thinking it still has 1 GB left, bad things happen (specifically it dumps the entire file cache, even important libraries, and must then read those from disk every time it needs them -- you don't really appreciate how much faster RAM is than disk until you've tried to recover a system from this).
You can (and I do) run without swap, but you either need to keep well below the RAM limit or write your own version of the "free" command that subtracts what's in /tmp. You will probably also need to change the overcommit_ratio and overcommit_memory parameters.
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....
I have to run Linux and Windows, so I use an ext3 partition for /home and redirect the Windows users' "My Documents" to each /home/someone. I use the ext2 IFS driver to read the partition. I have no problems with strange characteres and the configuration dot files appear as hidden. The result: flawless use and reinstalation of both Windows and Linux. If you need to use more than one *nix, you have to pay attention to user's ids, though.
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.
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.
FYI. According to Red Hat Enterprise Linux's deployment guide:
If M 2
S = M *2
Else
S = M + 2
where M is the size of physical memory in GB and S is the size of swap partition in GB.
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
Total Memory + 2 is the general rule. Tis true, i read it on the internet
Am I wrong, or is it pointless to have more than 4 GB of RAM (be it real or virtual) if you are using a 32-bit processor?
We're all being lied too.
1-GIG is plenty of ram.
If you must have swap make a file and use it.
search on how to do this.
There's no swap on my Ubuntu business server for extra security. No x windows. No desktop. No games. And zero problems.
I wrote a small script to collect data from "free" and write it to a text file, with info about ram usage. Idea was to figure patterns on my ram usage.
I inserted the script on a cron job, to run every 5 minutes. That started in 16 april, now the text file is 12749 lines long, 1.3MB.
The system is a debian notebook with 2GB ram and ~1GB swap. I am an average user, running no scientific computing, and eventually doing some video/music stuff. Browsing, emailing and writing ooorg documents most of the time.
Guess what? Swap usage equals zero all the time. Unless "free" is seriously bugged, swap is irrelevant to me.
I am happy to provide either the script or the text file to anyone interested. Just reply here.
If you are really curious, do the same for your system. It is very interesting.
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?
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
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.-
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.
If I do not miss any relevant technical detail, what matters in terms of memory capacity is:
1.- The amount of RAM + Swap
2.- How much memory your OS + applications demand
Do not forget this: your PC uses RAM first. When it's full and more memory is requested (by the apps or the OS itself), starts using Swap. And swap is slow as hell (it is mapped in the hard disk. 100 times less bandwidth, 1000000 times more access time. buagh!). So if you can pay for some more GBs of RAM, I advise you to buy them before cause your PC to use Swap regularly.
So, giving some examples for current days:
- In an office + internet PC you will have enough with 1 GB. Always if you don't use Vista.
- In a 2D graphic design station, ... I don't know. May be 2 GB ?, you will have to gauge your needs by yourself. windows' task administrator and ubuntu's system monitor allow to know this numbers.
- In a 3D design station, probably 4 GB will be needed.
- In an audio/video edition machine, probably also 4GB or more will be needed.
One last example: if your OS + apps need 8 GB of memory and you have only 4 GB of RAM, you are doomed to put the remaining 4 GB in form of Swap; otherwise your system will become "out of memory" in the middle of your work session.
I would recommend setting it to OVER NINE THOOOUUSSAANNNDDD
there have been systems that allocated a page of swap for every page of ram that you have. those systems limited you to whichever was smaller, swap or ram. there have even been linux kernels that did this.
nowdays this is usually not the case (and defiantly isn't on linux)
if you end up using very much swap your system is going to be spending so much time accessing the disk that you probably won't be able to use it anyway.
so the only reason to have a huge swap partition is if you have your system set to write your memory image to the swap partition when you hibernate.
it defiantly doesn't make sense to always make swap = 2x ram. I am looking at a server that will have 128 G of ram, and uses 144G high-speed drives in a raid 1+0 array. why should I dedicate _four_ hard drives (out of 6 possible in the system) to swap?
most of my systems are never going to hibernate (I want them running and serving, if I don't need them I can turn them off), so I allocate 1-2G of swap 'just in case' even on machines with 64G+ of ram.
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.
A better way to interpret this figure is to apply it against the amount of ram in a new, average PC. How much ram -you- have in particular is not relevant.
The idea is to give people a reasonable cushion for incremental increases to memory usage over time. A reasonable cushion can be considered 50-100% of the base memory for the average user. This cushion is sufficient even if you have more demanding applications because presumably you bought more physical ram to make up for that, as is the nature of the skepticism here.
So, say the average right now is 2gb of ram. That means your swap is going to be 3-4gb. But you're a power user, and your app profile needs 8gb of ram. So you've equipped 8gb of ram. That 3-4gb swap cushion is still fine, because it will still cover incremental additions for the foreseeable future, based on the rate of current growth.
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.
I hate it when idiots quote the 2x formula!
If you spend a lot of money for a high end server then why would want to page at all? Today, paging space is a safety net. Some of us actually think about memory performance issues on NUMA systems and others are complete idiots who think that it's okay to have a database sga size so huge that it get's paged out to disk.
Do you know what happens when you have a 32GB paging space and half of it gets used? The system will be thrashing and users will timeout waiting when trying to connect. It will seem like it is hung, but it's not, though it might as well be hung.
If you tune the system correctly and use a smaller paging space you can have the system start killing processes to fix the problem. I know AIX allows you to specify that root processes are not killed and it will kill the youngest processes first which usually fixes the problem.
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.
The swap space should be sized for how much the user "actually" needs.
Light users might only need 128 MB of swap per GB, even no swap if more memory is present.
However multitasking very memory intensive applications (the gimp, 7zip sometimes Firefox) would probably need 2x maybe 3x of RAM to run without running out of memory and crashing, though it'll slow down the system if the swap is in demand.
It's also better to over allocate swap if HDD space is available.
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.
There are several things to consider.
I find there's no point in putting 2xRAM on a home computer - it would not be needed.
The question is different with servers where availability matters.
If you are using single servers (i.e. not in high-availability clusters), you want some spare swap in case some service leaks RAM. In this case, 2xRAM seems to be a good rough estimate - it would be sufficient until the system gets really slow from swapping, without getting out of memory and starting to kill services.
If you are using high-availability clusters, not much swap is usually required at all - you have sufficient amount of RAM for normal duties and if it starts swapping a lot it will get thrown out of the cluster.
The origins of 2xRAM come from BSD Unixes that first added virtual memory, IIRC. At those times, usable RAM was the amount of swap and physical RAM was just a cache for it - so you needed more swap than RAM to make any use of the swap. Modern systems like Solaris, Linux and Windows use swap as an addition to physical RAM, dunno about modern BSD.
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);
My mac at work always has a 10+ GB swap file, and I normally only use a text editor, firefox, itunes & many many terminals.
10GB's for that?? I was shocked too..
I've seen it up over 20GB's for some of our graphics designers.
This would be 1:5 in relation to physical RAM. I normally follow the 1:2 rule as well, and it works on every other OS...I dunno why os/x is such a hog.
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
There are other reasons for splitting the memory into pages than the ability to swap out the memory piecewise. Think protection for example. Think systems with multiple processes, e.g., almost all current systems.
Hey, you relied on some other's opinion in the past when choosing the 2x RAM rule. Let's keep on with this criteria and let other people choose the best for you: when installing your OS choose the "autopartition the hard disk" option. You won't need to think about that http://ask.slashdot.org/comments.pl?sid=982541&op=reply&threshold=1&commentsort=0&mode=thread&pid=anymore.
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 :-(
Is 4 GB of RAM really neccessary? If it is, then you may want to have the double as a backup for swapping on your hard drive. But more than 4 GB of RAM cannot be handled with 32 bit addresses. So you need at least PAE or even 64 of these bits.
I'm runnning XPSP3, and I have 4GB of RAM. I have turned off my swap file entirely. This has resulted in an enormous speed increase! I swear by it, and if you have enough RAM I always recommend this.
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:
Need to design the hardware. Which is well hard. Much harder than remembering where base 2 and base 10 is used.
Serial protocol: in BAUD not bits per second. So you're wrong there. But converting to bits per second still uses a single line. So base 10 and base 2 have the same signalling needs: one line. No addressing.
Memory: binary computer with binary addressing. So write an address decoder (and TLB/lookahead circuitry) that uses base 10 for a base 2 CPU. Dare ya. Now use base 2. How much easier was that?
HDD: base requirements are same as computers: they still have to address a block as a "memory" (remember when computers were described as having 20MB of memory? That "memory" was the HDD). Above that, at the CHS level, it has to fit into the size of the tracks (you can't have half a cylinder and it's pointless having half a head/platter) so that can't be a whole number of either base 10 or base 2.
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.
For a standard desktop PC (or laptop), it will typically have 1+ GB of RAM. Just use 1 GB of swap. If you have 2+ GB of RAM, you'll likly never use the swap anyways. I do this type of setup all the time with machines that have 1 to 3 GB of RAM, and I'll see swap rarely being used. So no, don't follow the 2x rule blindly.
Obviously, if you forsee use of memory intensive applications, adjust your swap space accordingly.
Swap USED to be 2x RAM because that made the page finding function easy (1. half = 1:1 RAM mapped, 2. half = additional space to swap to).
This has long changed, and the swap mapping is no longer as dumb as that (Unix-wise).
Kernel-hackers suggest a swap-size dependent upon the harddisk speed - for normal IDE disks it should be around 256MB, for really fast disks you might go with 512MB.
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. :)
As all the prior replies show, the answer is, it depends upon what you're doing with the machine.
IN MY WORLD
Right now, I'm looking at TOP from a 12-cpu virtual server running SUSE 10. The system runs DB2, and is running about 100 concurrent transactions for clients in Europe. This is one VM on a massive machine (z10, 64 processors, 256GB main memory) so the physical memory this kernel sees is not what is on the machine.
Current stats:
Mem: 6170276k total, 3383108k used, 2787168k free, 64768k buffers
Swap: 324928k total, 165740k used, 159188k free, 1921828k cached
If I start to see swap grow, we're going to ask to pin more memory on the VM.
-end
awesome porn... starring the poster, obviously.
We're still jabbering about swap space? Really?
I have run various Linux distros over the past 5+ years without any swap partition or file and had *zero* (noticeable) issues with performance. From small desktops to beefy laptops to rather large servers running all kinds of loads. I even edit swappiness = 0 just to make sure the system doesn't wonder off looking for something that isn't there.
Now I would *never* do this under Windows, as the performance hits are obvious and immediate when you switch it off.
Personally memory is so cheap I max out the machine, then buy the biggest HDD. As an example, if your OS is only every using 1GB RAM under your heaviest load, why would a swap space of any size be more useful/better than, say, an additional 3GB of physical RAM you have to spare on a 4GB box?
Can someone cite specific examples of issues caused by not having any swap?
Being a 900 eeepc user with _no_swap_ and 1GB of RAM, I'm more than happy with it :) I can run Firefox with lots of tabs, MATLAB and openoffice at the same time and Linux doesn't complain about it.
Being an sysadmin with a server (2GB) some RoR apps, postgre, moin, postfix, mailman, ... I rellied on swap (rule used: RAM=SWAP ) . ;)
But now, with 8GB and the same 2GB of swap, little swap is used (9MB after 1 month of uptime
It depends of your use, but for desktop??? Swap is just needed to hibernate (in that case: swap=RAM)
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
I work at a research institute. We often have 8-12GB image files from an electron microscope. We need large RAM and swap (our image processing workstations are dual quad core with 32GB of RAM).
That said for the average user I'd say once your kicking around 1GB of swap the rest is useless. Reason: disk is so much slower than RAM that you'll get frustrated that your computer is so slow long before you fill it and you'll close apps. If you find running a modern game, converting a bluray movie, and doing a full virus scan is too much to do at once, guess what? You'll probably close something.
In practice we don't run into swap issues with any of our systems. For example our biggest (in terms of load/users connected) system at my work, our fileserver that is sharing ~1000 SMB/NFS shares of a total of about 250TB and doing live scanning of the data for backup with "only" 12GB of RAM uses 100-200MB of its 25GB swap file at any time. That doesn't seem to be because of need either because only about 20-40% of the RAM gets used. My guess is that the OS likes to keep some stuff in the swap file regardless of free RAM.
Anyways, I highly doubt a typical workstation user will hit the load that this thing has on it constantly. So a 2X multiple is probably not needed for most people, I'd say a 0.5-1X is probably fine.
Reading the discussion, there doesn't seem to be one answer that suits everybody's needs. Why don't you make a few attempts, record how long it takes to do some of your typical work for each setting, and post your findings here?
It certainly beats having sleepless nights over this for another 10 years...
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
(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
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.
With most systems coming with 2GB of RAM, I would say swap is no longer necessary. My first computer came with 4k of RAM and there was no need for swap space.
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).
I would have a question. I have 512MB of memory on my old laptop and working support for suspending to swap. And lack of space - 30GB.
Question: Does swap partition needs to be at least as much as 512MB if I want to use suspending to swap? Or simple 300MB will do?
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.
Personally I haven't used swap (or almost haven't used it) since memory sizes went above 1GB. It's way less demanding from you hard drive.
Windows has a bad habit of swapping memory do disk even when it's not necessary, and in Linux I simply never had to. No application I used completly filled the memory, except from some games which had memory leaks and after some 12 hours of continuous playing crashed. Having swap would have extended that to 36 hours probably but wouldn't have solved the problem.
Not to mention, if you are still using a 32bit OS, going above 4GB will not help you unless you run multiple applications all having high memory requirements. A single application will not be able to use more than 4GB.
Some applications may make their own kind of swap by mapping memory to a file on disk, or just plain writing and reading from disk the data they work with. (I have in mind Gimp and Cool Edit).
Even on a desktop machine with 4GB of RAM, setting swap space at 2*RAM (8 Gig) or even more is perfectly reasonable if you plan to make /tmp a swapfs/tmpfs and you know that /tmp will occasionally be used for large collections of temporary files (for instance: large compiles, copies of mail spools, software installation bundles)
On my personal Gentoo machine, I have 4GB RAM and an 12GB swap partition, and I have an 8GB tmpfs filesystem mounted on /tmp. portage uses /tmp for it's temporary directory (instead of the default /var/tmp). Thanks to this configuration, the temporary files for most emerges ("emerge" is application compilation and installation) stay completely in RAM, which makes emerges fly, yet I still have enough room in /tmp should I need to emerge a huge app like OpenOffice.
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
You don't want / and /home. What you probably want is / and /home/username/Downloads. home stores a lot of incompatible useless and texty(meaning far larger than they need to be) hidden .config files.
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
There is no point in trying to create a "rule" for this. If you have a lot of RAM but don't usually use a lot of it, make your swap a couple gigs. If you use your RAM fully a lot then make your swap bigger. If you had 2 gigs RAM and a 4 gig swap but were still getting low memory warnings you wouldn't say "oh, I can't increase my swap because of the 2x rule", you would just do it. It's going to be different for everyone. Just figure out how you use your computer and set it accordingly.
Most normal desktop users are probably safe with the anaconda (Fedora/Red Hat installer) automatic selection limit of 2GB. That's ample to park the idle system daemons and parts of your login today.
Ram is fast. Swap is slow.
If you have a specific application, then measure it and plan appropriately. Does it do well with a lot of swap? Is its worse with a lot of swap. Best to find out and plan.
We're a chip company with desktop workstations and a compute farm ranging from single processor, 2GB RAM to 16 cores and 128GB of RAM.
Most EDA applications we've seen (ex: Cadence, Mentor Graphics) deal poorly with having more than 10% of their footprint in swap when doing computation.
Providing 256GB of swap on our 128GB machines always leads to trouble. Users/tools will try to allocate it and thrash - making progress at less than 1% speed.
Many of the software licenses for these EDA tools are 10x to 50x the cost of enough RAM to run them effectively anyway. Why destroy the productivity of a $100k software license by trying to save a few thousand on the system running it.
So we load up on RAM, limit the swap to 2GB, set vm.overcommit_* and have fast, stable machines.
Whats a swap partition....?
What the meaning of getting 4GB ram and 8GB swap on a 32bits system (without adress extension) ?
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.
More to the point, check out the swap entry of the chapter on file systems features.
I'd just use the entire hard drive for swap and use RAM disks for my filesystems.
The reason is simple: fork()
Say you've got 1 GB of RAM, and you're running a Perl script which has sucked up a large amount of data, and is presently consuming 640 MB of RAM. Now your Perl script wishes to execute cURL to download a file. So what happens?
Well, Perl tries to do the fork() & exec() thing, but it fails on the fork() think because there isn't enough system memory to have two copies of that script running. Now, yes, when fork() is called, the data isn't actually copied, but instead turned into copy-on-write pages, and yes, when exec() is called, it'll all go away, but for the system to complete the fork(), it needs to have enough memory available to hold two copies of that script, in the unlikely event that fork() isn't followed by exec() but instead each script continues to do its own thing.
What the swap does is allow the system to say "well, if fork() isn't followed by exec(), then at least there's this swap that can be used" so that the fork() can occur.
Now, you'll never actually use the swap. Just try "dd if=/dev/sda of=/dev/null bs=1048576 count=1024" to see how long it takes to read a GB from your hard disk. Terribly long time, right? Needless to say, if your system ever actually used that swap, it would become unusable. However, it still has to be there, otherwise your system will never be able to use all of its RAM since it won't be able to overcommit on memory usage during those short periods of time during which it looks like more memory will be used than actually will be.
Ok, this really shows my age, but hey it's an opportunity to pass on some wisdom and possibly trivia to all you UNIX/Linux newcomers. I used to work for an AT&T VAR back in the early 80s servicing the old 3B1 and 3B2 and then later the 6386WGS series. Keep in mind that this was back in the day when 2MB Ram and a 30MB drive were enough to run a 4 user, green screen ERP system.
According to an AT&T UNIX System V systems programmer recommended swap was 2.5x system memory and if swap utilization ever surpassed 50% then more memory was required. The rationalization given was the since swap memory was so significantly slower than RAM, it gave an admin time to find runaway processes and kill/fix them before they consumed all the memory (real and virtual) and hard crashed the system. Yes, you could limit the amount of memory per process and the number of processes per user, but in a multi-user system those limits are useless and they also did not protect you from bugs like memory leaks. The old System V Streams were particularly flakey and account for a lot of problems like this.
He went into great detail about it all and I would assume that in multi-user systems and network services like SMB, httpd, it still holds true today. In a single user, graphical, desktop environment, I'm not so sure. It is more an issue of sum total memory to accomodate the largest, single app that would be run. I think you should have some swap, but depending on how much RAM you have compared to your largest app. As an example, I would think that a machine with 32GB of RAM certainly wouldn't need more than .5-1x swap if that.
I would also keep a few more things in mind. The first is that new OSs like Linux are more agressive at memory management than older systems were back when the 2x rule was coined. Linux systems will "park" sleeping processes and daemons in swap to open more RAM for applications. That being the case some swap should be used to make the most of your memory. The second issue is that years ago you didn't have options for swap. It had to be on a "raw" partition (core dumps on kernel panics used this as a default destination as well so if you wanted to do a post mortem on a crash you had to have swap in a partition) and if you ever had to expand it you basically had to wipe the drive clean and repartition, re-install the OS and restore the data. This was very ugly to do so most admins opted to error on the high side. Today you can use a swap file directly on the FS which allows for re-sizing almost at will. What I don't know and maybe someone can answer this is if you still have to have a small raw partition for core dumps.
would someone please tell us what role low memory plays. i have 3 gig of memory and and 8 gig of swap and i often trigger the oom killer because i have run out of low memory.
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.
You know, I've always wondered about doing this. When you nuke / and rebuild a new system, what do you do to ensure the user and group ids on the preserved partitions match up to the correct users you (re)create?
ac
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 :-)
I recall reading in the Gentoo Handbook that on systems with less than 1GB of RAM, you should follow the guidelines of "make your swap partition twice the size of available RAM".
However, that being said, on my laptop with 2GB of RAM, I have yet to see anything get written to (and consequently read from) my 512MB swap partition.
Additionally, on systems with SSD (solid state drives), the creation of a swap space may not only be impractical, but also somewhat damaging. SSDs haven't yet gotten to the read/write transaction limits that regular HDDs have, and a swap space that gets made heavy use of may burn out that small space that you have dedicated towards it, thus killing precious space on your already-small SSD.
From him, I was told 1.25 x RAM. It always seems to have worked for me. Enough to hibernate, plus extra for insurance :P
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.
For desktop use I tend to make a swap partition a little larger than the max amount of RAM that machine will have. I have 4 gigs of RAM in my main desktop so the swap has never been used except for suspending to disk. Running multiple virtual machines seem to be the only thing that gets my memory usage over a gig.
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.
a few gigs of faggotry
Basically.... monitor your memory usage. Get an idea for a peak, and then add your physical memory to that peak, you have a safe amount of memory for most intents and purposes. Typically your swap should atleast be the size of your RAM(unless you have crazy amounts of RAM, like over 4 GB and you don't do 3d rendering, memory-intensive scientific computation.. etc).
Page/swap can take memory leaks fairly gracefully compared to the system needing to increase its swap to satisfy programs (it may 'freeze' during this process). So more is 'safer' than less. Though you certainly won't see performance increase, unless the extra swap it's used often. VM size varies quite a bit depending on how much you multitask.
In Windows the swap file is used regardless. So always leave it enabled. If you NEVER use all your RAM, 1(XP)-2(Vista) GB swap should be bare minimum(older computers used for light computing could get away with 512(more or less than 128MB) or even 256 MB(128 MB)). It's really not hard to keep an eye on your mem usage, and discover optimal values that make best use of disk space while providing optimal performance). Some programs purposely use swap. NEVER DISABLE IT! It'll be used anyway and you'll be suffering performance hits. It basically turns it into fully dynamic paging, adjusting as Windows 'thinks' it needs to.
If you don't atleast have a page file the size of your RAM Windows can't do certain functions like dumping your RAM.
Performance is best seen when your paging file is not on the same physical drive as your system or programs files or other drives you use often. Ideally it is split between multiple physical hard drives. For instance I have 1 GB of RAM. 3 physical disks. I have 1 GB swap on both of my 500 GB drives, and I use a 30 GB drive for windows and program files. Leaving me with 3 GB of memory. I do heavy multitasking and CAD/rendering and other memory intensive tasks.
Depends on the workload. The real benifit of swap is being able to able to swap out idle memory from idle processes.
Such workloads are hard to find.
If you're multitasking heavy on a desktop computer, chances are that a lot of swap won't do you much good, as your processes will not spend a lot of time idle.
You only need enough swap to help warn you via thrashing that your workload is too damn big. Pick too little and you'll have no warning. Pick too much swap and you lose the benifit of the OS killing your hoggy processes for you. This is great big favour if you're not going to do it yourself.
But, if you're a sysadmin type and prefer killing (or suspending!) your own processes mannually, even under high load (which can be damn hard!), then go with big swap. Whatever you do though, use your ears (heavy hard disk activity) or use your eyes (load monitor) and don't tolerate inapropriate loads. Stop them.
No matter what though, the quantity of swap you choose will not really make a difference on weather you end up thrashing or not. If you're thrashing, get more physical memory, or do reduce the workload. But please, for the sake of the children don't let the thrashing continue. The sound of a drive working its butt off to load and reload the same pages over and over gain for over a minute gives me nightmares.
If you don't mind taking responsibility for stoping big loads, you can never have too much swap. The only thing you can have is too much demand, and too much swapping.
Now, if your workload is one, big, memory intensive app, a lot of swap can be a godsend. It can make the impossible, possible. If you're lucky, you might even be able to avoid thrashing if only a fraction of the pages are in demand at a time. I don't know how often that is actually possible.
If you can, avoid such applications. Smart programmers don't put everything in RAM, for data heavy apps they use database management systems, and for multimedia/graphics/sound/video heavy stuff they take advantage of thier privledged ability to be able to more acuratly pridict where future demand is, form thier own caches and do thier own paging. In the free world, Audacity comes to mind as a good example, its a non-linear audio editor that keeps little chunks of what you're edditing on disk. Even though it is non-linear, there are strong chances for locality of reference in such an application. Applications that write to disk also benifit from the operating system allocating RAM to disk cache, which makes reads and writes to common pieces of data not very costly. A bad example of putting things in RAM from the free world was GnuCash, which until recently did this. (theier trunk version now uses a DBMS). I never really found it causing me to thrash, but boy! did it ever take a long time to save, which also had the added benifit of being all to XML!
The thoeretical ideal place for a lot of swap is a multiuser system where many users log in, launch apps, work, lock thier terminal or screen and walk away. A lot of swap here could make it possible for more users to be active, and make RAM availible to the active users for disk cache.
I've never made a swap partition bigger than 512MB and i've never had a problem.
Just go to Start menu, Control Panel, System, Advanced, Performance Settings, Advanced, Virtual Memory/Change, and set the "Automatically manage paging file size for all drives" checkbox. That's the last you need worry about that.
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.
Agreed 100000%. I have gone through god knows how many distros and some multiple times. All while keeping my same /home. Also being able to move /home to different hard drives as size needs increased. My /home has been my /home since 1998 (and it still isnt paid off yet :()
Swap is not the same thing in all cases.
There's nothing to prevent an OS designer/implementor/maintainer from doing something really oddball that would require 1.33x+ physmem for example.
However, the two most common possibilities are:
1) VM = size of swap
2) VM = size of swap + physical RAM
Linux has flipped back and forth between #1 and #2 a bit - I'm not sure where it's finally wound up.
There was a time in the Linux world where if you didn't have at least as much swap as physmem, you'd be fine for a while, but then as soon as there was memory contention, your system would go into a thrashing tailspin that you'd often have to reset out of.
So don't ask "what size should my swap be?" - instead ask "what size should my swap be for the OS I'm using on this system?"
And yes, keep in mind things like kdumps that are written to swap (not all dumps go to swap anymore, but certainly some still do), and things like hibernation that will write to swap. Note that sometimes when memory images are written to swap, they'll be compressed - other times not.
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.
It obviously depends on what you are using it for. But, on my systems, I've aimed for 2GB of total virtual memory. I have one machine with 512MB, 1.5GB swap. One has 1GB, 1GB swap. One has like 448MB (because of 64MB shared video memory) so I gave it 1GB+64MB. So with 4GB RAM I would leave swap at *0*, and (if you use Linux exclusively) even consider jettisoning a few sticks and save the cost of RAM if you build a second system... it doesn't chug through RAM the way Windows does.
On the other hand, my Ubuntu boxes auto-create swap, and for a system with 768MB made like a 2.2GB swap. I didn't override it, although for my use it's a bit excessive.
(Some) games use lots of RAM. GIS uses lots of RAM. Some times of software development use lots of RAM (I'm running gentoo, though, and 2GB seems to be fine for compiling, openoffice is the biggest and peaks at about 1.5GB while compiling it..) Normal web surfing, word processing, etc. etc. just doesn't use too much.
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