I am new to Linux and want to install ubuntu on a computer that has 32GB of RAM. I've read a lot about the recommended size of swap for people with much smaller RAM capacity, but nothing for my size. Can anyone help me? Thank you, I really appreciate your time!

Thanks for all the input. I think I have a better understanding of this issue regarding swap. Some of the answers to my question said it depended also on other specifications as well. I have 32GB of RAM as stated above, a 1TB SSD(main drive), and a 2TB regular hard drive, and an i7 CPU. I only do every day tasks, no server or rendering. At this point I think I will refrain from using hibernation.

marked as duplicate by karel, Melebius, Fabby, Thomas, pomsky Sep 4 '18 at 16:50

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Quoting from Centos,

Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space. While swap space can help machines with a small amount of RAM, it should not be considered a replacement for more RAM. Swap space is located on hard drives, which have a slower access time than physical memory.

If you're using Ubuntu as your primary OS and have 32GB, you need little to no swap space if you use Ubuntu for normal day-to-day tasks and not big rendering, server running, etc.

The reason why you've read about using swap space for lower levels of RAM is because in that case, swap space is used to fill in for the lack of RAM that they have. In your case with 32GB, and assuming that you're not using Ubuntu for really resource-heavy tasks, I would recommend 4 GB to 8 GB.


If you want hibernation to work, it has to save everything in RAM to swap space so that it can be restored when the computer is turned on again, so you'd need at least 32 GB of swap space.

If you don't care about hibernation, unless you plan to use more than 32 GB on a regular basis, a small amount like 4 GB or 8 GB would be fine for now. Swap space can be resized later.

  • How does that work if the 32 GB are full and we have already swapped something out? – Paŭlo Ebermann Oct 6 '16 at 23:11
  • I have 16 GB of RAM and only 1 GB of swap. Obviously hibernation doesn't work, but I haven't had any issues with such a small size. – Nathan Osman Oct 7 '16 at 0:20
  • But why, in Linux, have one file with 2 purposes, a swap file that serves the purpose for both providing some extra memory for apps (swap) and also for storing the state of the entire system (suspend-to-disk/hibernation)? In Windows, there appears separate file for each purpose. For swapfile.sys for Windows 10 (pagefile.sys does the same job for older versions) and hiberfil.sys is for the image of the system state in RAM for when the system is hibernated. Wouldn't that be easier for decision making as to what size of swap to use (and what size needed for hibernation)? – therobyouknow Aug 31 '18 at 21:44
  • And what if you only have one app in RAM running, not using all of the RAM, say 1 or 2Gb out of 32Gb - why would hibernation require all of the RAM to be copied into the disk? – therobyouknow Aug 31 '18 at 22:09

If you want to use suspend-to-disk, you need 34GB swap. If not, you not need swap space.

  • What about having a way to get memory that's dirtied at startup out of RAM? How can you do that with no swap space? – David Schwartz Oct 7 '16 at 0:24
  • This is the only correct answer. Swap is actively harmful when you have huge amounts of ram; all it does is create a failure mode where the system bogs down forever swapping and you have to reboot to recover. The only reason to enable swap is to make hibernation work. – R.. Oct 7 '16 at 3:10
  • @DavidSchwartz Systems with significant physical memory don't need to swap. The OS is free to move virtual pages of memory about within the physical memory, and can choose other strategies for reducing memory usage besides swapping, such as using zram to compress older, unused pages. Also, any memory used during start up will naturally be recycled/overwritten when its no longer useful and other processes need the physical memory. There's no context in which you'd need to explicitly clear any such memory, and, unless one is using more than 32GB of memory actively, no need to swap. – phyrfox Oct 7 '16 at 6:28
  • You didn't answer my question. How do you get memory that's dirtied at startup out of RAM? I'm asking about all the pages that are dirtied by processes that launch at startup and may not run again for days, if ever. Are you saying that just because you have lots of RAM, it's acceptable to waste a chunk of it that could be used as a disk cache to hold modified pages that may never be accessed? Because if so, I certainly don't agree. – David Schwartz Oct 7 '16 at 16:03
  • Take care about the difference of GB and GiB. 1 GiB = 1.074 GB. RAM is normally measured in GiB. So to write 32 GiB to disk, you may need 34.3 GB – jms Oct 7 '16 at 17:17

The answer depends on the usage of your computer and the size of the hard disk:

  1. Usage: it should be at minimum the size of the RAM, if you use hibernation.
  2. Disk size: this is the How much you can afford from hard disk without annoying yourself with "out of storage space". In your case, I guess that you having a 1TB as Hard Disk size. So, a 32BG swap is not that big deal.

To resume:

  • if you use hibernation: 1*RAM<= swap size <= 2*RAM (32GB..64GB)
  • if not: SQRT(RAM) <= swap size <= 2*RAM (6GB..64GB)

For more information check : https://help.ubuntu.com/community/SwapFaq#How_much_swap_do_I_need.3F

  • You're welcome @linuxnewbe. – Mohammed Hannechi Oct 8 '16 at 1:12
  • Why doesn't Linux/Ubuntu have a separate file for hibernation, separate from the swap file? Doesn't Windows do that? – therobyouknow Aug 31 '18 at 21:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.