Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

How Big Should My Swap Partition Be?

timothy posted about 6 years ago | from the wait-until-ram-is-infinite-then-double-it dept.

Upgrades 900

For the last 10 years, I have been asking people more knowledgeable than I, "How big should my swap be?" and the answer has always been "Just set it to twice your RAM and forget about it." In the old days, it wasn't much to think about — 128 megs of RAM means 256 megs of swap. Now that I have 4 gigs of RAM in my laptop, I find myself wondering, "Is 8 gigs of swap really necessary?" How much swap does the average desktop user really need? Does the whole "twice your RAM" rule still apply? If so, for how much longer will it likely apply? Or will it always apply? Or have I been consistently misinformed over the last 10 years?

Sorry! There are no comments related to the filter you selected.

What Has Changed? (5, Informative)

eldavojohn (898314) | about 6 years ago | (#25225907)

'Is 8 gigs of swap really necessary?'

With a 750GB [] hard drive selling under $100, what has changed?

Yeah, your 256MB of space was trivial when you had a 30GB hard drive ... and 8GB of space is still trivial with a 750GB 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.

Re:What Has Changed? (3, Funny)

Zosden (1303873) | about 6 years ago | (#25225963)

Old memes
640k is enough...
in Soviet Russia drive partitions you.

Re:What Has Changed? (5, Interesting)

meringuoid (568297) | about 6 years ago | (#25226063)

Yeah, your 256MB of space was trivial when you had a 30GB hard drive ... and 8GB of space is still trivial with a 750GB hard drive.

I have an Eee 901. It has 1GiB of RAM and 20GB of disk space. A swap partition on the 'twice your RAM' rule would be far from trivial.

I decided to be bold and installed Hardy with no swap partition. It seems to work just fine so far; Firefox greys out for a few seconds sometimes while loading pages, which might have to do with my reckless configuration, but on the whole it's pretty snappy.

As for my desktop PC, it has 4GiB of RAM. I followed the traditional rule when I installed on that. I don't think that swap partition has ever even been used.

Re:What Has Changed? (3, Interesting)

RiotingPacifist (1228016) | about 6 years ago | (#25226229)

consider using a swap file for your setup id recommend 256mb of swap, with 1.25gb of ram (apart from when i left wireshark running for toolong) ive not seen it creep above ~100mb for long.

Re:What Has Changed? (1, Interesting)

whoever57 (658626) | about 6 years ago | (#25226091)

With a 750GB [] hard drive selling under $100, what has changed?

The relative speeds of disks and memory have changed.

I am thinking of reducing the amount of swap on my primary compute server -- the reason is simple: if the machine starts using appreciable amounts of swap, it becomes so slow, it is unusable. So, really, by reducing the swap, what I do is get the OOM killer to take action and kill some processes sooner. I may have an unusual situation that when my machine is out of memory, the cause is almost certainly due to a proces that I want killed anyway.

Re:What Has Changed? (3, Informative)

srothroc (733160) | about 6 years ago | (#25226103)

Just some stupid math, but if you figure that you had a 40 GB HD when you had 128 MB RAM, you'd need 256 MB for swap space; that's about .006% of your hard drive. Windows installs were also correspondingly smaller at that time.

Now, if you suppose that someone has 4 GB RAM and a 750 GB drive, they'd be using 8 GB for swap space, which represents about .011% of their hard drive... and Windows installs, games, and applications are much bigger.

HOWEVER, if you look at smaller drive sizes, which are still common in the modern day -- I know plenty of people who just use 120 GB or 200 GB drives; not everyone likes all their eggs in one basket.

8 GB swap on a 120 GB drive represents about .07% of the drive. On a 200 GB drive, it represents about .04% of the drive. Still and order of magnitude larger than was required back when "swap space should be double your amount of RAM" was a standard rule of thumb.

Just some thoughts.

Re:What Has Changed? (0)

Anonymous Coward | about 6 years ago | (#25226159)

It really all depends on your usage and what you need. I have four gigs of RAM and my swap partition is only 1 gig is size. Despite the fact that my swap space is 1/4 of my physical RAM, my swap space has never been anywhere even close to approaching full. It hardly ever gets touched even when I'm running a virtual machine in VirtualBox. Also, in the rare circumstance when something is swapped out to disk, I've never seen the usage go above several megs.

What I did to figure this out was started with the 2x rule of thumb and then monitored my swap space from time to time. Eventually I had an enough RAM and used so little swap space, I re-evaluated the amount I needed and the next time I installed, I reduced the swap partition size.

I should probably also note, that I close programs when I'm not using them. I close Firefox when I'm not surfing. I turn off the VirtualBox services when I'm not running a virtual machine. The only programs I tend to leave running, other than UI and systems programs, are Pidgin and Amarok. My server applications are on a tower I use for server like apps such as my LAMP stack and file shares. That box has significantly less horsepower and only has 1 gig of ram and it's swap partition is also 1 gig in size and it hardly ever gets used.

Re:What Has Changed? (3, Informative)

RiotingPacifist (1228016) | about 6 years ago | (#25226283)

i assume you dont hibernate, thats the only reason i have 1x my ram in swap. Although using something like "hibernate" instead of ubuntu's tool will happily compress it so i could really get away with about 60-70%

Re:What Has Changed? (1)

Zekasu (1059298) | about 6 years ago | (#25226185)

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 only think that part about Firefox is applicable to Firefox 3, if you know what I mean.

Also, I rarely am able to exceed 4GB total memory use, even with WoW and some other things up at the same time. To be honest, I run out of CPU cycles before I run out of memory.

Re:What Has Changed? (1)

Sensible Clod (771142) | about 6 years ago | (#25226207)

Since I installed Fedora 9 on my 3GB RAM and 850 GB RAID5 machine, I have zero swap and no issues so far. I very rarely use anything with huge memory requirements. I think the best answer to this question is: It depends on how much you use. Especially the largest thing(s) you use.

Re:What Has Changed? (1)

FooBarWidget (556006) | about 6 years ago | (#25226247)

"With a 750GB [] hard drive selling under $100, what has changed?"

The coming of laptops. My laptop from 2007 only has an 80 GB hard drive. I'm a Linux user so the hard drive is partitioned with 10 GB for / and 42 GB for /home. I need Windows for games, so 23 GB for Windows, which proved to be barely enough for the few games that I'm playing (Starcraft, Portal, some MMORPGs). However, I don't want to reboot to Windows every time I want to test a website in Internet Explorer or every time I need to write Windows software, so I installed XP within VMWare, and the VMWare image resides in my home partition. This takes 20 GB of disk space. This only leaves about 20 precious GB. I download a lot of anime so 20 GB is really very little.

I have 2 GB of RAM. Reserving 4 GB swap would be an utter waste of disk space that I could use for more useful things.

Re:separate partitions for / and /home (1)

QuantumG (50515) | about 6 years ago | (#25226347)

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.

Re:What Has Changed? (5, Insightful) (912690) | about 6 years ago | (#25226307)

The real question is; is that 750GB drive really 20 times faster than the older 30GB one?

Re:What Has Changed? (1)

Gewalt (1200451) | about 6 years ago | (#25226309)

Since I hate 'just taking smart peoples word for it' I have been actively testing this myself for years. On windows, some drivers crash if they can't load themselves directly into swap/page. So, I give windows an 8mb swap file. It's happy. On Linux, I don't use a swap file at all. It's happy.
Yes, I'm serious. I don't use pagefiles, the very concept makes no sense, and certainly does not improve performance.

None (0)

Anonymous Coward | about 6 years ago | (#25225945)

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)

Re:None (3, Interesting)

compro01 (777531) | about 6 years ago | (#25226119)

Delaying is largely the point as I see it. If you're out of ram and it's eating into the swap, things are going to slow to a crawl and you'll know something is wrong, so you can look for, find, and kill whatever is running amok before it consumes all and triggers a panic/BSOD/etc.

Re:None (4, Informative)

hey! (33014) | about 6 years ago | (#25226211)

Well, I do occasionally need more than 2GB of RAM, without there being a memory leak. I've been running GIS programs, an IDE, a couple of RDBMSs, and then I fire up the old compression program...

Which brings me to my point. The question "how much swap do I need" is probably meaningless, even for a given amount of memory. There are people who find 2GB with no swap fine, and others, like me, who probably could get by with 2GB of RAM and maybe 512MB of swap, and others who might need more.

I think the 2x RAM rule of thumb has one virtue: excepting certain exotic kinds of systems, it's fairly safe that anybody who finds themselves needing more than that is probably feeling a world of pain that can only be fixed by getting more RAM. On the other hand, in most cases 2x RAM amounts to a trivial amount of disk. Probably most people could get by with 25% of RAM, but the value of thinking about whether that is true for you is very likely less than the cost of the disk space.

Common sense applies. If you have some kind of scientific computing device with a gazillion bytes of RAM, your swap requirements might not be related to your maximum RAM requirements at all. If you're running some kind of operating system that launches a bunch of rarely used garbage, you probably ought to think about your swap. I had awful problems with Vista until I figured out the page file Windows created had something like eight thousand fragments. I was actually better off getting rid of the page file

With a caveat... (1)

michaelepley (239861) | about 6 years ago | (#25226299)

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?

Re:With a caveat... (1)

compro01 (777531) | about 6 years ago | (#25226397)

Windows can. You can set minimum/maximum swap file size and it will grow/shrink the swap as needed, though that has a tendency to severely fragment the swap file after awhile if you don't have a sizable amount of contiguous free disk space.

That's not the point of swap space. (3, Informative)

Estanislao Martnez (203477) | about 6 years ago | (#25226367)

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.

I'm no expert, but... (1)

Redlazer (786403) | about 6 years ago | (#25225955)

I'm not sure anymore, but I don't think "double your ram" is really necessary anymore. The size of programs is not increasing at the same rate as our RAM - now we could easily house most programs entirely in RAM (including most of the OS), so I doubt its REALLY necessary.

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.


Definitely not twice... (5, Informative)

42forty-two42 (532340) | about 6 years ago | (#25225965)

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.

Oh, nonsense (4, Informative)

Anonymous Coward | about 6 years ago | (#25226097)

2X RAM was the standard rule of thumb at Sun, for SunOS long before Windows was around.

If anything, Microsoft ripped it off from Sun.

Re:Oh, nonsense (0)

Anonymous Coward | about 6 years ago | (#25226233)

It was *MY* idea I tell you.


Re:Definitely not twice... (5, Insightful)

pete-classic (75983) | about 6 years ago | (#25226145)

your system is completely unresponsive due to every program being mostly swapped out.

Uh, report this to your vendor as a bug. No amount of swap space should cause your system's memory manager to make such lousy decisions.

And, in fact, having an "unreasonable" amount of swap can actually pay off. If your system can swap out really stale memory to disk and use the RAM to cache stuff on disk that you might actually want, you're going to see a really big performance gain.


Run multple instances ;)Re:Definitely not twice... (0)

Anonymous Coward | about 6 years ago | (#25226351)

long long int *x;
int main()
long long int i;
long long int *p;
long long int *q;
int bignum=1024+1024;
printf("mallocing alot\n");
        if(p == NULL) {
        printf("error no more memory.\n");
printf("entering loop\n");
printf("Filling memory with 1's.\n");
for (i=0; i (1024*1024*bignum)/8; i++){
p[i] = 1;
} /*printf("Comparing stored value to 1\n");
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("freeing memory\n");

Re:Definitely not twice... (0)

Anonymous Coward | about 6 years ago | (#25226175)

I've always used 1.5 X (memory size) so 2GIGS: 1.5 * (2048) = 3072mb pagefile

Re:Definitely not twice... (-1)

Anonymous Coward | about 6 years ago | (#25226205)


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.


If you don't have the swap around for that 12GB process, however, your machine will simply lock up. How is that better than having to wait for the system to finish thrashing?

Re:Definitely not twice... (1)

680x0 (467210) | about 6 years ago | (#25226317)

No, if a program requests 12GB, and your machine doesn't have that much (RAM + swap) space available, the allocation will fail. If the program is smart and checks the allocation return value, it will tell you it's unable to do whatever it was trying to do. If it isn't smart, it'll likely try to access the space pointed to by NULL, and crash.

Rules of Thump are useful, until thumps become old (0)

Anonymous Coward | about 6 years ago | (#25226277)

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.

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...

Re:Definitely not twice... (1)

Bryansix (761547) | about 6 years ago | (#25226389)

Not quite there. I have a server that runs SQL and IIS on the same box and it's running a .net website with over a million lines of code in it. I had to bump up the Swap a lot even though the box has 8 Gigs of RAM. (Yes it's 64-bit)

What Oracle Wants (4, Informative)

stoolpigeon (454276) | about 6 years ago | (#25225967)

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.

If your database server (1)

XanC (644172) | about 6 years ago | (#25226235)

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.

Re:What Oracle Wants (2, Informative)

RiotingPacifist (1228016) | about 6 years ago | (#25226321)

for a server thats probably about right, on a desktop where stability is not quite as important id go with about half that

Which OS? (0)

antdude (79039) | about 6 years ago | (#25225991)

Linux? Windows? Mac OS X?

Re:Which OS? (2, Funny)

Anonymous Coward | about 6 years ago | (#25226231)

How many Windows users do you know with a swap partition?

Depends on what you are doing (1)

ChienAndalu (1293930) | about 6 years ago | (#25225993)

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.

4 gigs? (0)

Anonymous Coward | about 6 years ago | (#25226001)

Guess what... you probably could get away without ANY swap! How often are you planning on using more than 4 gigs of RAM?

More sensible suggestion... (4, Informative)

Vexler (127353) | about 6 years ago | (#25226003)

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."


Re:More sensible suggestion... (1)

sofar (317980) | about 6 years ago | (#25226051)

yes, well not entirely

you want a LITTLE BIT of swap in all cases.

- for netbooks (asus eee pc) I recommend 128mb of swap (max).

- for most laptops up to 256mb swap is more than enough.

desktop swap size may be bigger depending on your personal needs. If you gimp gigantic images, use more.

Re:More sensible suggestion... (1)

ColaMan (37550) | about 6 years ago | (#25226369)

Sorry, your attempt at being authoritative has completely failed for me. You can't just throw out statements like this without at least trying to back them up with facts (or at least plausible assertions).

you want a LITTLE BIT of swap in all cases.

Why? A little bit of swap does SFA if some big memory-hogging app gets loaded.

for netbooks (asus eee pc) I recommend 128mb of swap (max).

Why? With a SSD that has speedy reads and sluggish writes, you might as well not have it and just get more physical ram if you find your apps keep getting suddenly terminated.

for most laptops up to 256mb swap is more than enough.

Why? With 2GB of ram becoming more common on laptops, an extra 10% does SFA.

Mod parent up (1)

John Hasler (414242) | about 6 years ago | (#25226361)

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.

Just test? (4, Informative)

rasteri (634956) | about 6 years ago | (#25226007)

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 need crashdumps, same rule applies (4, Informative)

bugg (65930) | about 6 years ago | (#25226019)

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.

Re:If you need crashdumps, same rule applies (1)

allenw (33234) | about 6 years ago | (#25226221)

On some operating systems (Solaris comes to mind), the crash dump is stored in swap compressed, so 2x may still be overkill even if you are doing crash dump testing.

1x System RAM (1)

dopaz (148229) | about 6 years ago | (#25226023)

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.

256M (1, Informative)

bluefoxlucid (723572) | about 6 years ago | (#25226027)

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.

Re:256M (1)

Drinking Bleach (975757) | about 6 years ago | (#25226215)

swapd sounds very interesting, thanks for mentioning it. I currently have 1GB of RAM and almost never swap; the swap partition is only 1GB, but it'd be nice to get rid of it :)

Swap size (1)

Wowsers (1151731) | about 6 years ago | (#25226029)

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.

It depends. (1)

stevedmc (1065590) | about 6 years ago | (#25226035)

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...

How big? (2, Funny)

zoomshorts (137587) | about 6 years ago | (#25226039)

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.

For Suspend to Disk more than actual RAM (5, Insightful)

Britz (170620) | about 6 years ago | (#25226041)

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 ...

Re:For Suspend to Disk more than actual RAM (2, Informative)

FauxPasIII (75900) | about 6 years ago | (#25226291)

For built-in suspend this is true. TuxOnIce [] offers, among other things, suspend-to-file support which eliminates the need to keep gobs of swap around if you don't want to.

Re:For Suspend to Disk more than actual RAM (1)

RiotingPacifist (1228016) | about 6 years ago | (#25226341)

certain tools can compress your ram before you suspend (also means a faster restore) so you can get away with about 70% of your ram (especially if your ram isnt 100% used)

Re:For Suspend to Disk more than actual RAM (0)

Anonymous Coward | about 6 years ago | (#25226393)

So, you still need RAMx2 (in case your RAM was 100% full when you tried to suspend)?

Depends on how much you need to address at once (1)

GaelTadh (916987) | about 6 years ago | (#25226055)

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.

Re:Depends on how much you need to address at once (1)

fred fleenblat (463628) | about 6 years ago | (#25226259)

I think mmap since kernel 2.4 (maybe even earlier?) swaps right off the file system w/o moving it to the swap device. You'd have to do MAP_PRIVATE and scribble all over the segment to start eating into regular swap space.

Re:Depends on how much you need to address at once (1)

GaelTadh (916987) | about 6 years ago | (#25226345)

Sure you don't map into regular swap but you cannot address more than swap and physical.

Depends on what the machine is used for (1)

corsec67 (627446) | about 6 years ago | (#25226067)

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.

Forget the RAMx2 rule (4, Insightful)

jmorris42 (1458) | about 6 years ago | (#25226069)

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.

if you run Firefox and OpenOffice at the same time (0)

Anonymous Coward | about 6 years ago | (#25226073)

I'd suggest about 50G of swap.

It Depends, but at least as much as RAM (5, Informative)

rcoyner (1376393) | about 6 years ago | (#25226077)

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: []

Re:It Depends, but at least as much as RAM (-1, Troll)

dAzED1 (33635) | about 6 years ago | (#25226177)

or, you could just turn the damn desktop PC off when you're not using it anymore, and stop pretending the 30 seconds it takes for it to boot is somehow destroying your life. "Hibernate" does not mean "use no electricity."

Re:It Depends, but at least as much as RAM (4, Informative)

Anonymous Coward | about 6 years ago | (#25226275)

Yeah, hibernate actually DOES mean "use no electricity". Perhaps you mean "suspend"?

Don't do 2 times your RAM. (0)

Anonymous Coward | about 6 years ago | (#25226083)

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.

swap for what? (0)

Anonymous Coward | about 6 years ago | (#25226085)

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 (1)

HTH NE1 (675604) | about 6 years ago | (#25226093)

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.

Re:Reasonable Limits Aren't (1)

HTH NE1 (675604) | about 6 years ago | (#25226165)

Or no swap at all. That still fits the axiom. The point is, always make your limits unreasonable in the right direction, or time will make them so.

Re:Reasonable Limits Aren't (1)

HTH NE1 (675604) | about 6 years ago | (#25226225)

Or no swap at all. That still fits the axiom. The point is, always make your limits unreasonable in the right direction, or time will make them so.

...or time will make them so in the wrong direction.

(And always read your postings before submitting. Preview only helps if you actually review the result.)

Re:Reasonable Limits Aren't (1)

merreborn (853723) | about 6 years ago | (#25226273)

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.

That'd be a spectacular waste of electricity, seeing as the drive would be spinning all the time, but almost never actually used.

Depends on if you want suspend to Disk. (0)

Anonymous Coward | about 6 years ago | (#25226099)

Depends on if you want suspend to Disk in linux

Determine it yourself (0)

Anonymous Coward | about 6 years ago | (#25226105)

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).

How big should your swap partition be? (0)

Anonymous Coward | about 6 years ago | (#25226109)

I find this an odd -- yet fitting -- question to ponder, having just watched the "2 girls 1 cup" video for the first time.

The TRUTH (1)

alexborges (313924) | about 6 years ago | (#25226111)

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.

2x RAM was very helpful (0)

Anonymous Coward | about 6 years ago | (#25226113)

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.

Eee PC... (1)

metageek (466836) | about 6 years ago | (#25226115)

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.

my formula: (1)

sparcnut (775902) | about 6 years ago | (#25226117)

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.

/tmp on tmpfs and large swap (2, Insightful)

hpa (7948) | about 6 years ago | (#25226133)

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.

Just ran into this today... (1)

Hokie06 (986634) | about 6 years ago | (#25226135)

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.

0 MB (2, Insightful)

timeOday (582209) | about 6 years ago | (#25226139)

I have run linux systems without swap for years without trouble, including the laptop I'm on right now.

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.

As much as you think you'll need (2, Informative)

discord5 (798235) | about 6 years ago | (#25226143)

How big should my swap be?

It really depends on what you're planning on doing with the machine:

  • If you're using XFS on large volumes (eg 10TB on a fileserver), you'll need a lot of swap for xfs_check.
  • If it's a desktop, you probably don't want to start swapping too much, so you want lots of RAM. I usually add as much swap as I have RAM. I gave up on the "twice the amount of RAM" rule years ago. If you're swapping that badly on a desktop you won't have a comfortable "desktop experience" anyway.

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.

Oodles (1)

Rinisari (521266) | about 6 years ago | (#25226147)

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.

New rule of thumb, Swap = 1.2x of Ram (1)

zx-15 (926808) | about 6 years ago | (#25226149)

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.

Re:New rule of thumb, Swap = 1.2x of Ram (1)

NotQuiteReal (608241) | about 6 years ago | (#25226339)

I used to use the SQRT(2)*RAM size. Now I find that Pi/3 * RAM size is just fine.

Of course, some folks consider me quit irrational.

In 10 years experience.. (1)

ZERO1ZERO (948669) | about 6 years ago | (#25226161)

you hould have an idea of just how much memory / swap you tend to use, and you must have at one point done something dumb, like open 500 25 meg images or something by mistake, and thought Shit! and checked the mem usage, just for laughs..

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.

As with anything... (0)

Anonymous Coward | about 6 years ago | (#25226163)

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.


Personal research? (1)

daveywest (937112) | about 6 years ago | (#25226179)

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.


Re:Personal research? (-1, Troll)

unity100 (970058) | about 6 years ago | (#25226209)

I have 4 gigs of ram on an intel iMac

thats because you spend your days swapping music to your ipod, arranging your photo album, and doing other 'cool' but trivial things that are the hallmark of 'just works' of mac.

booooooooooooooooo. you can go mad now. all of you.

Keep swap low (1)

shellster_dude (1261444) | about 6 years ago | (#25226181)

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.

Depends on what you run. (1)

427_ci_505 (1009677) | about 6 years ago | (#25226189)

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.

If it's a server... (1)

cgroneman (1376403) | about 6 years ago | (#25226193)

... 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.

Monitor you page in / out counts (1)

q256 (469707) | about 6 years ago | (#25226199)

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).

what are your apps? (1)

WindBourne (631190) | about 6 years ago | (#25226227)

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.

Vista Swap Size (1, Flamebait)

Dolphinzilla (199489) | about 6 years ago | (#25226237)

Minimum of 5 TB for a Windows Vista Swap file..

No Swap Works for Me (1)

TheTempest (99802) | about 6 years ago | (#25226249)

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...

What if we just got rid of paging? (3, Interesting)

Databass (254179) | about 6 years ago | (#25226257)

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?

I still use a 32-bit CPU (1)

Sloppy (14984) | about 6 years ago | (#25226271)

So I figure 4GB of total virtual memory is enough for anyone. Um, I mean, enough for me.

Been There Done That... (3, Informative)

killmofasta (460565) | about 6 years ago | (#25226301)

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.

Zero can work fine for Linux. (1)

gweihir (88907) | about 6 years ago | (#25226313)

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.

Use a swap file instead. (1)

astrosmash (3561) | about 6 years ago | (#25226331)

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

Load More Comments
Slashdot Login

Need an Account?

Forgot your password?