320

I read many places that the rule of thumb for swap space is to double the amount of physical RAM. However, 32 GB does seem a LOT. Do I need that much? Do I need it at all with this high amount of physical RAM?

  • 92
    to be completely honest here... you don't even need SWAP, you already have 16GB of RAM unless you seriously think you will ever run out of RAM, you don't need it. – Uri Herrera Jun 16 '11 at 18:55
  • Thanks Uri, I think you can add this as an answer, so I can accept it unless someone comes by and proves otherwise :). This is what I thought, I just wanted to be sure. – Tamás Szelei Jun 16 '11 at 18:59
  • 69
    That "rule of thumb" originated at a time when most PCs had RAM in single-digit megabytes. It hasn't been meaningful for 10+ years, but it just...won't...die! – Nicholas Knight Jun 17 '11 at 06:21
  • @Nicholas, absolutely correct – Uri Herrera Jun 17 '11 at 06:52
  • 23
    @TheX: maybe in some years when people see your comment they will laugh :) – Benoit Jun 17 '11 at 08:57
  • 1
    Though the 2 questions are similar the other one has no mention of hibernation... – Ashu May 13 '12 at 07:07
  • what about "vm.swappines=0" in /etc/sysctl.conf this option will swap only in case out of memory. BTW swap should be no more than 8G to not waste your space and if you are on SSD 4G should be fine. Thanks. – Mustafa Apr 18 '13 at 00:03
  • @UriHerrera - swap is most certainly needed regardless of how much RAM you have – warren Jul 15 '13 at 19:47
  • @warren What for? the purpose of swap is to have 1) RAM for when you don't have enough of it, aka to have virtual memory and 2)Hibernation and Suspend, if for whatever reason you don't need any of those two you don't need it, which is/was the case of the OP and the original question. – Uri Herrera Jul 15 '13 at 20:08
  • @UriHerrera - many applications rely on it (the JVM being one) – warren Jul 15 '13 at 20:23
  • @warren JVM makes use of a lot of virtual memory as it's name already implies that, I for one don't use a JVM so I don't need swap but that's about me, reading the original un-edited question you'll see that the OP asked this because of the "rule of thumb" mentioned in prev. comments that you need to have such a high swap space if you have lots of RAM, so, the OP doesn't need it either. Besides I guess there's a way to make JVM use real RAM instead of virtual memory, but that's just off-topic in this question. – Uri Herrera Jul 15 '13 at 20:48
  • @UriHerrera - the JVM is not the only applciation which needs a swap space to run, VirtualBox, and many others do, too. In short, though, why would you not put a swap space on a system when it's so cheap to do? – warren Jul 15 '13 at 21:01
  • @warren I'm pretty sure that software doesn't need swap space to run, at least I'm sure Vbox doesn't need it. Because of the simple fact that swap runs on disk space, and if there's enough RAM to run everything (which is faster) why would anyone want to use swap (which is slower than RAM)?, except for what I've already said. – Uri Herrera Jul 16 '13 at 20:55
  • @UriHerrera - some apps takeover what are normally OS tasks, and force themselves out to swap and back in again – warren Jul 16 '13 at 20:56
  • @warren If software even on this day and age still needs to use swap instead of actual RAM then there's a problem with it, I mean the kernel itself doesn't need it and even has an option to not use it why would anything else less important need it or use it. Just got through the Ubuntu FAQ about swap and this question. – Uri Herrera Jul 16 '13 at 21:05
  • @UriHerrera - not arguing it should need it. But the fact remains that some does. – warren Jul 16 '13 at 21:06
  • @NicholasKnight annoyingly this 'rule of thumb' is in the Ubuntu Disk Space guides linked from the main Graphic Installation guide – icc97 Feb 06 '15 at 10:25
  • 1
    actually I realised that its not quite as bad, its swap = RAM rather than swap = 2 x RAM – icc97 Feb 06 '15 at 10:31
  • @warren sounds bad design to me (as a programmer) to force use of swap space for heap allocation... and I mean bad design for both the application and the OS to allow applications to manage it. I really don't believe that happens and would appreciate some reference. I didn't find any myself. – GabrielF Aug 06 '15 at 03:21
  • @GabrielF - I outlined this in my blog post 4 years ago, and it, in turn, sources this Sun bug report. – warren Aug 06 '15 at 13:50
  • @dn-ʞɔɐqɹW I'm quite sure it's the other way around if they are at all duplicates. My question was asked in 2011 while the other was asked in 2015. The question also references this one and explains why it's not the same. – Tamás Szelei Feb 28 '16 at 12:14
  • @TamásSzelei: yes, but the answers on your question are outdated by now, so I'm asking for a reverse duplicate. See also official Ubuntu documentation – Fabby Feb 28 '16 at 12:17
  • @dn-ʞɔɐqɹW Fair enough, but why do you think it is outdated? What changed? – Tamás Szelei Feb 28 '16 at 12:19
  • Sorry. Was still editing the comment. Please read official Ubuntu documentation and you'll understand. – Fabby Feb 28 '16 at 12:20
  • @dn-ʞɔɐqɹW The recommendation on the page you linked states roughly the same as most answers here (i.e. square root of RAM). So again, what do you think has changed? Please don't link another wall of text, just state your opinion plainly. – Tamás Szelei Feb 28 '16 at 12:26
  • Find out! See my approach here: http://unix.stackexchange.com/questions/190398/do-i-need-swap-space-if-i-have-more-than-enough-amount-of-ram/190534#190534 – Elder Geek Feb 28 '16 at 14:41
  • @ElderGeek: your answer is the most correct I've found. It's use-case dependant and that's what I'm trying to stress with mine and to base it on maths. There are a lot of opinions out there but it should be roughly between round(sqrt(RAM)) and 2*RAM (which on a 128GB RAM system is between 11 and 256GB) The larger RAM systems haven the more difficult to calculate the "optimum". Care if I plagiarise some of your answer's idea? (that is "test it")... – Fabby Feb 28 '16 at 20:05
  • @TamásSzelei: Read the other question and answer again. Yours is specific for 32GB RAM, and there are a lot of answers so the information is spread everywhere. That other one is more generic and also asks about the why and the answer gives some information not found here, so IMO yours should be duplicated to that one but the community will decide. – Fabby Feb 29 '16 at 01:07
  • 1
    @dn-ʞɔɐqɹW Feel free. I'm doing further research and testing regarding using zram for swap (which throws all the previous calculations out the window) but change makes life interesting. I benchmarked a zram drive (they show up in disks) and got 1GB/sec. Can't touch that with an SSD let alone a platter.... – Elder Geek Feb 29 '16 at 03:27
  • @ElderGeek: drop by in chat sometime: I'm interested in your research (or post a Q&A on this) – Fabby Feb 29 '16 at 08:42
  • @dn-ʞɔɐqɹW You just changed your argument and repeatedly did not back up the previous one (previously you said that the answers here are outdated, now you are saying that the other question is more generic). Even though this question does not explicitly ask for explanation, it does have answers with plenty of explanation. I'm honestly baffled by you people. Take a look at the editing history and see why this question is specific to 16GB RAM (not 32 like you said, which makes me even question if you read it at all). – Tamás Szelei Feb 29 '16 at 09:41
  • @dn-ʞɔɐqɹW The community will of course close the question, it's only a matter of time, since there are no "against closing" votes on the site. – Tamás Szelei Feb 29 '16 at 09:42
  • 1
    I have 6GB and no swap and it is enough for IDE coding , Unity3D and 2GB VirtualBox.All at once – Suici Doga Mar 07 '16 at 13:16

22 Answers22

273

Here's a very good recommendation from Red Hat: Recommended System Swap Space

An excerpt from the same link:

In years past, the recommended amount of swap space increased linearly with the amount of RAM in the system. However, modern systems often include hundreds of gigabytes of RAM. As a consequence, recommended swap space is considered a function of system memory workload, not system memory.

And another excerpt from an older version of the page:

However, given that swap space is usually designated at install time, and that it can be difficult to determine beforehand the memory workload of a system, we recommend determining system swap using the following table.

RHEL 8 table:

Amount of RAM    Recommended swap space       Recommended swap space 
in the system                                 if allowing for hibernation
--------------   --------------------------   ---------------------------
⩽ 2 GB           2 times the amount of RAM    3 times the amount of RAM
> 2 GB – 8 GB    Equal to the amount of RAM   2 times the amount of RAM
> 8 GB – 64 GB   At least 4 GB                1.5 times the amount of RAM
> 64 GB          At least 4 GB                Hibernation not recommended

At the border between each range listed in the table above, for example a system with 2 GB, 8 GB, or 64 GB of system RAM, discretion can be exercised with regard to chosen swap space and hibernation support. If your system resources allow for it, increasing the swap space may lead to better performance. A swap space of at least 100 GB is recommended for systems with over 140 logical processors or over 3 TB of RAM.

Original RHEL 5 table:

Amount of RAM in the System     Recommended Amount of Swap Space
4GB of RAM or less              a minimum of 2GB of swap space
4GB to 16GB of RAM              a minimum of 4GB of swap space
16GB to 64GB of RAM             a minimum of 8GB of swap space
64GB to 256GB of RAM            a minimum of 16GB of swap space
256GB to 512GB of RAM           a minimum of 32GB of swap space 
ssapkota
  • 2,751
  • 83
    The square root of the RAM in GB, rounded up to a power of two. – starblue Jun 17 '11 at 07:57
  • 2
    There is inconsistencies in the 'new' table - according to the guide 16GB of swap space is appropriate for a 32GB system, but 4GB is appropriate for a 64GB system... – Charlie Dec 07 '16 at 05:29
  • 2
    @Charlie That's because you're unlikely to run out of working memory with 64GB RAM.. – paddotk May 28 '17 at 17:49
  • @Charlie It's not about the amount of system memory, it's about the likelyhood of running out of system memory and how big that shortfall is going to be. – Phill Healey Jul 18 '17 at 20:19
  • What's the practical difference (besides speed of swapping) between a 32 GB system with 16 GB of swap and a 48 GB system with no swap? Because it seems everyone recommends swap space no matter how much memory you have... – Cole Tobin May 08 '20 at 19:07
  • 1
    @ColeJohnson the practical difference is that if you run out of memory on a 32GB system you have some buffer remaining. As soon as a system starts swapping it becomes noticeably unresponsive and you have a chance to investigate. With the 48GB system and no swap, you have more time/memory to execute "normally", but once you run out of space the kernel starts killing processes. On a typical enduser system, you probably end up rebooting once swapping starts so it hardly makes a difference. On a server processing an important workload, it makes sense to have that buffer. – a2800276 Jun 10 '20 at 06:37
208

It entirely depends on what you plan to do with the machine. For example if it were a Sap server then yes, I would add 32gb swap ( we have boxes at work with 128gb ram and 32gb swap ). If you were manipulating massive pictures and video then it makes sense to have a little swap. 32gb is probably overkill.

However I would not say zero swap.

In the unlikely event that you run out of RAM - perhaps opening a big file, perheps a long running tab in firefox, it doesn't matter, in that event your kernel OOM killer will kick in and start killing applications to get memory back. Under those circumstances it's entirely possible that you will lose data as applications get killed. However if you have a bit of swap then the system will carry on, grabbing swap and allowing the system to continue. System slows down as heavy swapping happens, you notice and investigate before all swap exhausted. Also disk is very cheap, so why not have swap?

Anyone who says "you don't need swap" without asking you what you're actually doing with your computer is making assumptions. Whilst you may well do very little with your computer that eats RAM, it's still best to ask the questions about what you're planning to do with it before making the rash judgement that you don't "need" swap. In my humble opinion

Marco Ceppi
  • 48,101
popey
  • 23,667
  • 17
    Can you elaborate why said no to zero swap? Others seem to agree that there's no need for it unless I want to hibernate (which I don't). – Tamás Szelei Jun 16 '11 at 22:24
  • I agree it depends on the application, but if that application would require 8Gb of SWAP in an 8Gb RAM system, it requires no SWAP in an 16 RAM system, I would say. – Jochem Jun 17 '11 at 13:26
  • 4
    @popey - So what then if the system runs out of swap? Back to square one, there. – user Jun 17 '11 at 14:11
  • @popey. thanks for the info. But what do you mean by "you will lose data"? – db42 Jun 17 '11 at 14:48
  • If you have, say, 4gigs of ram and a terabyte of storage space, why would it not be an idea to use some of that space disk space for swap data? I don't mean as a permanent swap file/partition, used for nothing else - just as a last resort if it means that otherwise you'd get apps/data kicked out. What would be the downside of that approach? –  Jun 17 '11 at 20:34
  • 13
    Having a system with 8 GB of RAM, I can say this: any time I have had a program run away and dip into swap, my system will become mostly unresponsive. It's better to let the OOM killer run than to have to force an unclean reboot anyway; if you have that much RAM, unless you're doing very very heavy work that requires gigabytes of RAM, you'll be fine. Even when you do have heavy lifting, there's usually a way to process it that doesn't require swap space (which is less efficient than sane large-dataset handling in the application itself). – Michael Trausch Jun 20 '11 at 03:59
  • 6
    Space may be cheap on HDDs, but on SSDs it's hardly cheap; not as expensive as DAM, but still. – Mircea Chirea Jan 08 '12 at 15:36
  • 4
    If your systems use 31GB swap and you need the last GB, they will probably be very sloooow. IMHO if you constantly need more than 2GB swap you should install more RAM. – Martin Schröder Dec 13 '13 at 13:55
  • Hey popey, mind re-reading through this answer and making sure it is up to date? – Seth Mar 01 '16 at 02:28
  • 2
    I don't believe the answer needs changing. As a test (and as a result of negative feedback I've had about this answer) I ran my 16GB Thinkpad X220 with no swap for a while. On multiple occasions memory pressure caused the kswapd process to go mental (looking for swap) and made the machine completely IO starved and completely unusable while thrashing. Making a small amount of swap made this issue disappear completely. So I still stand by the response that "no swap" isn't always the right answer, no matter how much RAM you have. – popey Apr 24 '16 at 19:40
  • OOM killer is a pain when I have 8GB ram and 2GB swap. System freeze and I have to wait like 1 hour time to get normal operations... – kelalaka Nov 02 '18 at 09:52
65

Argh. The answers on this post are so very wrong, and this comes up as one of the first results in a Google search for "How much swap?"

First, a good point of reference is the Ubuntu Swap FAQ

This FAQ makes an important point that no one here mentions, and that is (emphasis mine)

Sometimes, a large program (like OpenOffice, Neverwinter Nights, or a video editor) make the entire system need extra memory. A significant number of the pages used by these large programs during its startup may only be used for initialization and then never used again. The system can swap out those pages and free the memory for other programs or even for the disk cache. In these cases, swap will be used to help the system handle any extra load.

So, swap is not just for hibernation! This activity, swapping out unused pages, can be beneficial in some scenarios and detrimental in others. Beneficial because it can free up memory for the system to use elsewhere, but detrimental when that swap out is too aggressive, and swaps out pages you actually do want. This is especially true on a desktop system where applications can sit idle for long periods of time, but the user still expects immediate performance when bringing it back to life. The control for how aggressive this is, is referred to as swappiness

The Ubuntu Swap FAQ discusses this lightly under What is swappiness and how do I change it? The default value on an Ubuntu system is 60, while the FAQ recommends a value of 10 for a desktop machine.

So, I would say that it is generally very important to not have a system with absolutely no swap space, as some people were recommending on this question, unless you know for certain very specific usage scenarios for your system and are very aware of the consequences it could have. (Personally, there is no situation where I would run a system without swap) In an Out of Memory scenario with no swap, the system will start killing processes (generally the one that caused the OOM)

brent
  • 758
  • 7
    Upvote for the link to the FAQ, and for introducing some sanity amidst the opinions and anecdotal evidence. – Marty Fried Jun 24 '12 at 17:04
  • 2
    The point is there is no such large programs yet and your link saying just opposite of this. See this https://help.ubuntu.com/community/SwapFaq#How_much_swap_do_I_need.3F – Anwar Oct 18 '12 at 16:48
  • 4
    To relieve memory from extra load, I'd prefer zRAM and swappiness=60 , rather than traditional HDD swap. – Barafu Albino Jun 30 '13 at 07:27
28

Probably not. If you plan to hibernate your computer (suspend-to-disk) then you'll need at least 16 GB. If you won't hibernate, it is enough to let a few gigabytes for swap (4-8 max.)

bandi
  • 2,640
  • 2
    I have no swap at all and can hibernate/suspend my laptop just fine. – scribu Jun 17 '11 at 09:05
  • 9
    @scribu this sounds interesting. I suspect that there is maybe a swap file somewhere because for completely powering off your laptop (i.e. unplug and remove battery) the contents of the RAM must be saved – bandi Jun 17 '11 at 20:34
  • 12
    It is quite possible to hibernate with 16gb of ram and 4gb of swap: you just need to be using less than 4gb when you go to hibernate. – psusi Jun 24 '12 at 03:48
  • 1
    @psusi Linux will try to compress memory. Less swap = more aggressive compression. – val - disappointed in SE Jun 02 '19 at 08:58
21

From experience I can say this:

For what I have seen using 4GB of ram for 3 years, Ubuntu has had a swap usage of around 60MB but only when doing some very intensive tasks. A couple of weeks ago I started using a PC that had 16GB of ram and the swap usage has stayed in 0% for ever. I have done multiple compiles, video rendering and other intensive tasks. There has never been a change in swap. Not even a 1KB change.

Basically, in Ubuntu, the more memory RAM you have, the less likely you will use or need swap for any task. 16GB of ram, or even 8GB of ram is more than enough. I have done with the 16GB PC 8 Virtualbox PCs (each between 1GB to 2GB of ram). I have compiled and rendered a 720p video and not even in those conditions has the swap changed.

With that said, the rule of twice as much memory ram should not apply on Linux based systems, even more so if you have more memory. You should however have the same size of swap equal to your ram size or if you are planning to hibernate, since the process of hibernation grabs everything in ram and puts it on swap, which is why you need a minimum size equal to your ram size for swap.

The other detail is that some apps (not all) will still force to read from swap. So having a bit is good. Disabling it altogether is very bad in the case you get to the point of out of memory or OOM. At this point if you do not have swap, there is no way the kernel can swap in/out different ram app usages and will eventually start killing the less used ones.

If it helps with home desktop decision making, after updating this answer in more than 4 years, I have used a 16gb, 32gb and now a 64gb ram PC. Testing with only 128MB of swap revealed that I had no need for larger swap except if I wanted to hibernate. I have used cloud environments on them, lxc, virtualbox, wine, you name it. I have rendered videos with openshot, kazam, handbrake, audacity. I have used gimp, blender, Inkscape and even the full LibreOffice suite. I even played on steam and in none of those scenarios the swap was used. Of course, it will eventually get used if you end up using the full ram amount in one way or another but in general the more ram you have, the less swap you'll need.

Just my 2 cents.

Luis Alvarado
  • 211,503
9

No, you don't need 32 GB as long as you don't use features like suspend to disk.

7

In most cases, I'd say you don't need any at all. Perhaps if you edit very large image files, or some other app that needs lots of ram, you might need some.

I've never seen any used at all on my system, similar to yours. In fact, at one time, I had it disabled for a week or two accidentally, and never noticed any problem. But I still keep about 5GB for my swap drive, mainly because I have over 1TB available, and don't use all the space as it is.

Marty Fried
  • 18,466
  • I remember seeing it used once, when I used Wubi and I hibernated. – Vladashram May 13 '12 at 02:05
  • 2
    If you use hibernation, that may be a good reason to have enough swap space to save the machine's state. I'd guess you would never need more than the amount of available memory, unless perhaps you are using enough at the time to be using swap space already. – Marty Fried May 13 '12 at 02:16
5

If you use hibernate, it's safe to have as much swap as your amount of RAM.

For a general rule of thumb on how much swap to have, read here:

https://help.ubuntu.com/community/SwapFaq

In your case I'd say 4 GB would be enough to match your RAM.

roadmr
  • 34,222
  • 9
  • 81
  • 93
4

If your ram is higher than 1GB, it is usually enough for ubuntu. The "Swap = RAM x2" rule is for old computers with 256 or 128mb of ram.

So 1 GB of swap is usually enough for 4GB of RAM. 8 GB would be too much.

3

From Ubuntu's SwapFaq:

Why do I need swap?

Memory consuming programs Sometimes, a large program (like LibreOffice, Neverwinter Nights, or a video editor) make the entire system need extra memory. A significant number of the pages used by these large programs during its startup may only be used for initialization and then never used again. The system can swap out those pages and free the memory for other programs or even for the disk cache. In these cases, swap will be used to help the system handle any extra load.

Hibernation (suspend-to-disk) The hibernation feature (suspend-to-disk) writes out the contents of RAM to the swap partition before turning off the machine. Therefore, your swap partition should be at least as big as your RAM size. The hibernation implementation currently used in Ubuntu, swsusp, needs a swap or suspend partition. It cannot use a swap file on an active file system.

Unforeseeable Circumstances Unforeseeable events can and will happen (a program going crazy, some action needing much more space than you thought, or any other unpredictable combination of events). In these cases, swap can give you an extra delay to figure out what happened, or to finish what you are working on.

Optimizing memory usage Since mechanical hard drives are considerably slower than RAM (SSD - Solid State Drive - storage is not as slow as physical drives, but still slower than RAM), when you need a file (be it a data file like a video, executables like Firefox, or libraries), the Linux kernel reads the file into RAM and keeps it there, so that the next time you need it, it is already in RAM and data access is much faster. The portions of RAM that accelerate disk read are called "cached memory." You will notice that they make a huge difference in terms of responsiveness. The Linux kernel automatically moves RAM reserved by programs--but not really used--into swap, so that it can serve the better purpose of extending cached memory.

Optimizing Swap performance Because swap space uses a disk device, this can cause performance issues in any system that uses swap space significantly because the system itself may also be using the same disk device at the same time that it is required for swap operations. One way to reduce this problem is to have swap space on a different physical drive so that the competition for that resource is either reduced or eliminated.

How much swap do I need?

For less then 1GB of physical memory (RAM), it's highly recommended that the swap space should, as a base minimum, be equal to the amount of RAM. Also, it's recommended that the swap space is maximum twice the amount of RAM depending upon the amount of hard disk space available for the system because of diminishing returns.

For more modern systems (>1GB), your swap space should be at a minimum be equal to your physical memory (RAM) size "if you use hibernation", otherwise you need a minimum of round(sqrt(RAM)) and a maximum of twice the amount of RAM. The only downside to having more swap space than you will actually use, is the disk space you will be reserving for it.

The "diminishing returns" means that if you need more swap space than twice your RAM size, you'd better add more RAM as Hard Disk Drive (HDD) access is about 10³ slower then RAM access, so something that would take 1 second, suddenly takes more then 15 minutes! And still more then a minute on a fast Solid State Drive (SSD)...

Example Scenarios

    RAM(GB) No hibernation  With Hibernation  Maximum
      1      1                2                   2
      2      1                3                   4
      3      2                5                   6
      4      2                6                   8
      5      2                7                  10
      6      2                8                  12
      8      3               11                  16
     12      3               15                  24
     16      4               20                  32
     24      5               29                  48
     32      6               38                  64
     64      8               72                 128
    128     11              139                 256
2

If you use hibernation your swap should have at least the same amount as your physical ram.

gemue2010
  • 374
2

You only need swap if you want to use hibernate for the rest it is a wast of space on your harddrive.

Rens
  • 557
  • 6
    Hibernate need swap space but not as bi as the RAM size, only as big as RAM usage at the moment of hibernate. Sleep do not need any swap, because the RAM is still active and hold the data. – Donny Kurnia Jun 17 '11 at 04:11
  • @Donny Kurnia thank you I didn't know that. But my laptop likes to use swap when it goes to sleep. I look if I can edit it. – Rens Jun 17 '11 at 06:14
  • 1
    you can do experiment by disabling the swap sudo swapoff -a then sleep your laptop. – Donny Kurnia Jun 20 '11 at 07:56
  • @Donny Kurnia I've did it and sleep does still work. – Rens Jun 20 '11 at 15:11
1

I have a laptop with 4GB of RAM and Ubuntu 16.04. After boot it consumes around 1GB of RAM and even then Inkscape (for example) won't run (System monitor shows more than 50% of free RAM). Inkscape freezes After I apply a swap file it runs as expected, even with no one single byte of swap being used).Inkscape running So I recommend a swap partition (or swap file). About the size of it, you can use david6 rule.

Danilo
  • 127
0

No, you definitely don't need 32GB. As a rule for a desktop system I'd say your swap should be somewhere between 4GB and physical RAM + a couple GB. So for 16GB physical RAM, swap may be 4GB to 18GB, perhaps.

The stuff you will need to swap to the swap space will roughly equal the amount of physical RAM in use by applications that stay resident - that is, system services and applications that stay running while you are using them (as opposed to tasks that run once then quit). On a desktop system let's say you may leave open a browser, word processor, email program and graphics or video editor while you work on something else. Those may easily occupy over 2GB, maybe over 4GB. So maybe 6GB of swap is appropriate.

As a general rule it's doesn't hurt to have a few GB more than you need, too. Swap usually won't be used if you have a lot of RAM but it helps out on the occasion when some process is using an excessive amount and you start to get low, and can prevent the system killing processes.

Note: if you want to use OS hibernation you'll need all 16GB as mentioned, but modern computers don't benefit much from hibernation. If you have a fast SSD, booting may be as fast or faster than resuming from hibernate, and modern computers use negligible energy while in sleep mode that the energy usage benefit from hibernate is not a big factor.

thomasrutter
  • 36,774
0

If it is a laptop then keeping at least the swap equal to the amount of RAM, to fully allow hibernation. I would still keep an amount equal to the amount of RAM even if a desktop, but that is just me; it will get little use in a desktop.

haziz
  • 2,929
0

Keep this in mind -

You should typically size your swap space to approximately 2x main memory for systems with less than 2GB of RAM, or approximately 1x main memory if you have more

So If you have 4 Gb ram you should never ever need swap unless hibernating
Swap required would be around 3 - 3.5 Gb, not more than that.
So use your common sense and dont waste disk space

Ashu
  • 9,482
0

If you're building very big files, say for instance if you're building machine translation systems on a laptop (yea ok why would you wanna do that? I for one can say that my professors are making me ;-)) the answer is a clear yes, actually at this moment I'm regretting not making it 32GB swap....

For casual use of Ubuntu for office work and internet no you're never going to use even 2 GB of swap but in reality there is no clear answer, it all depends on what you are going to do on your computer...

0

Too much information, and variance in opinion.

My suggested Ubuntu desktop guidelines:

 amount of RAM      recommended swap    with hibernation
----------------    ----------------    ----------------
 less than 4GB        2x RAM size         3x RAM size
   up to 8GB              4GB             2x RAM size
   up to 16GB             4GB            1.5x RAM size
  16GB or more            4GB           No extra needed
david6
  • 14,499
0

I think you got it the other way round. SWAP Recommendation, you would need ~16GB. So SWAP should be 1/2 of the actual RAM size. But still thats a LOT of space. Depends what you need it for. I'd say, if you don't use "hibernate", keep around ~4GB to ~8GB if you can afford the disk space. Since you have 16GB, I assume you may be using a computer which needs powerful resources... so maybe it might be beneficial to have 16GB to 32GB SWAP as well.

I have 2GB RAM and 1GB SWAP. I do pretty much fine with it, but that's just my opinion. Look at the other comments/suggestions and see what they say.

0

I could not find references to quote here, but if you are going to use an application where you need to swap out entire data in RAM, you would atleast need 'RAM size+128 MB' or '1.25 times of RAM Size' (i forgot which one was correct) assuming you have RAM more than 2 GB. If RAM is 2GB or less, it is recommended to have twice RAM size as swap.I followed this recommendation in my previous organisation for IBM AIX based on a document from IBM. I believe this holds true for most of *nix since the use of swap is move data from RAM safely in case RAM is not enough to handle the data to be loaded in memory. 'free' command can be used to evaluate how much swap is used in reality.

Jamess
  • 3,123
0

I have a Mac laptop, which I leave on for months. Although much better than Windows, memory does creep in, particularly with your browser, if you keep it up. So eventually, memory fills up. Now if you have swap, as other people have noted, you can survive, notice and kill something. But more to the point, if you have swap, some pages get swapped out and you can keep going.

So if you're planning on leaving the machine up for a long time, swap is a handy way to free up memory from zombie junk. Granted it will take you longer to fill up 16g than me with 3gb, but it's still nice. For this purpose, 4Gb will do.

Dov
  • 811
0

No one seems to have mentioned another reason to have significant swap space is to have the system noticeably slow down rather than fail to run programs as you start running out of memory. If you have a load balancer in front that redirects on failure you may want to keep swap small (say 1GB), If you want programs to slow down first, then I would consider 4GB + square root of memory size, and if you want them to really slow down before things die, then keep to min of 1.25 time memory size (as long as impatient humans don't give up first - this would be more appropriate for background jobs).

I configure 1GB for my development and production machines as a standard, then it doesn't matter how much or little real memory they have, they have enough to compile all the programs I want, and to swap out practically never used programs to use the freed up memory for disk buffering.

In comparison, I have 64GB of swap on my 32GB laptop, which is a bit of an overkill, but I wanted to make sure it always kept working even if slowly, and I knew I was going to run multiple memory hungry virtual machines. An unexpected effect is when you have 32GB+ memory range then resuming from hibernation (which reloads 32GB of memory) is noticeably slower than a cold boot.

iheggie
  • 159
  • 4