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.

2 Answers 2


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

  • 1
    Disk cache is not compressed
    – psusi
    Jun 23, 2011 at 15:08
  • 1
    the way you have it worded made it sound like you were saying that the cache is compressed, not the hibernation image. For the hibernation image to be compressed you need to install the uswsusp package. The default kernel implementation does not compress.
    – psusi
    Jun 23, 2011 at 15:23

This question continues to surface in common queries when sizing swap to set up hibernate. The original answer is correct in that it could vary incredibly based on your workload, but I don't feel like that's a complete answer.

The complete answer is that you can tell how much you need based on your specific workload, then you can size appropriately.

The basic tool is the kernel messages during hibernate. You want to see how much memory was used with this command:

sudo cat /var/log/syslog | grep 'PM:'|grep kbytes

You should get output like:

Aug 14 11:03:20 mike-XPS-15-9570 kernel: [17594.823584] PM: Allocated 11809876 kbytes in 2.65 seconds (4456.55 MB/s)
Aug 14 11:03:20 mike-XPS-15-9570 kernel: [17605.365657] PM: Wrote 11787284 kbytes in 9.09 seconds (1296.73 MB/s)

Then the strategy is to run your maximum load, and trigger a hibernate, see what swap space was required, possibly add a margin of safety, then make your swap space that size.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .