Currently I have laptop with 16GB of RAM and 512GB SSD. I always use "full encrypted disk" option in installation creator which automatically create 16GB swap partition. Now I want to buy laptop with 32GB of RAM and I guess creator will try to make 32GB swap partition. Do I really need such big partition for occasional hibernation? I mean, does it really dump whole 32GB into swap or only real used memory which often will be much much less? Can I reduce swap partition size after installation? I have also vm.swappiness=1 instead of default 60

I'm reading that ubuntu 18.04 has option for swap file instead of partition so maybe I should wait for KDE Neon LTS based on 18.04 (current release which I'm using, is still on 16.04)

marked as duplicate by user68186, karel, Fabby, Thomas, Eric Carvalho Aug 31 '18 at 19:38

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.

  • 2
    Even with 8 GB of RAM most people would never see there swap used unless there was an errant program. Then it simply allows a graceful shutdown and reboot. I wouldn't worry about swap if I had 32 GB of RAM. – WinEunuuchs2Unix Aug 27 '18 at 11:08
  • I have 32GB ram, and with quite a lot of programs open, including android studio, VScode, and two android emulators, I still have 15GB free and zero swap used. I created a swap partition out of habit, and because I wanted to see if I really would need any, which so far I never have. I'll be canning my swap partition soon to reclaim the disk space in to my lvm2 pool. Honestly I think you'd have to run a few kvm before you seriously eat in to your ram, or do a mass concurrent photo edit. – nobody special Aug 27 '18 at 11:47
  • Ok but what is going on when I hibernate/snooze/sleep (don't know how to call it) my laptop e.g. by closing laptop's cover? Is it dump 32GB of RAM into swap partition or keep it in RAM? – Dibo Aug 27 '18 at 12:05
  • Normally when you close the lid, the laptop goes to sleep. The things in memory stays in memory and everything else shuts down. The memory continues to draw power from battery to keep going. If you leave it like that for a month, eventually the battery will die and the laptop will shut down losing what was in the memory. – user68186 Aug 27 '18 at 13:04
  • Not all laptops can use hibernate with Ubuntu. That's why it is not default. If yours can and you set it up, then the memory contents are written in swap partition when the laptop hibernates. This is the only time you will need as much swap as your RAM. – user68186 Aug 27 '18 at 13:07

The answer depends on what exactly you want to gain from having swap?

  • Improve performance in general case - then swap will not help. Even 16Gb of memory is more than enough to run any Linux with any typical workload. You swap will not be used at all.
  • Improve performance when working with extra large files with application that is not designed to handle them - again, swap on a typical disk will not help. It is too slow to allow working on data from swap, even with SSD. Special extra-fast storage devices are used in this case.
  • Allow for hybernation - if you want hybernation to work, your swap must be larger than the memory, no matter if memory is 16Gb or 512Gb.
  • Do kernel debugging - some of development tasks require swap, but I can not tell you the details.

Do not mix PC sleep and PC hybernation. Sleep needs no swap, is fast to start, but drains battery a little. Hybernation requires huge swap, is slow to go into and start from, but you can disconnect your battery and put you notebook on the shelf for a year in the meantime. What happens when you close the lid depends on settings, but going straight to hybernation every time is not a good idea.

  • Don't forget hybrid sleep, where the laptop writes the memory to swap to hibernate and then goes to sleep. That is mixing sleep and hibernate. – user68186 Aug 27 '18 at 12:58

Heres is almost the same question which may help you: I have 16GB RAM. Do I need 32GB swap?

But I can recommend you if you plan to use the hibernation to set your SWAP with the size of the RAM + 4GB or 20% of the RAM in case of almost full RAM and start to hibernate. Else set the SWAP to be 20% of the RAM.

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