Ubuntu – How large of a swap partition is needed to hibernate

hibernateramswap

I've read this question, but it doesn't definitively answer my question.

If I want my computer to be able to hibernate, do I need to have a swap partition as large as my RAM, or will Ubuntu wisely be able to hibernate if the swap partition can fit the currently-in-use RAM? I'm about to install Ubuntu on a computer with a lot of RAM, and a relatively small hard drive, so I don't want to use more hard drive space than necessary.

I wanted to avoid giving my actual specifications to keep this question more general, though I'll give them if necessary.

Best Answer

It's hard to predict: your swap needs to accommodate

  • what's already in the swap when you hibernate
  • what's in RAM when you hibernate, but only the part that's not disk cache or buffers; the RAM image is compressed if you use uswsusp
  • a few kernel data structures

So you can fail to hibernate even if your swap is bigger than your RAM, because most of your swap is already in use. And convertly you can successfully hibernate with a swap that's smaller than RAM, if you're not using much of either at the time.

If you want to avoid a fixed-size swap partition because your disk is very small, you can go for a swap file instead. It's easier to resize, and hibernation to a swap file is supposed to be supported (not sure if it currrently works out of the box, that's come and gone between Ubuntu releases; IIRC it did in 9.10 but it had to be set up in 10.10).

Related Question