Linux – What happens when you try to hibernate but there is not enough swap available

hibernatelinuxmemoryswap

I have a Linux box with a swap partition of size RAM + x. Suppose more than x of the swap is already in use. Now I try to hibernate. Will the kernel

  • randomly kill sleeping and/or not sleeping processes until there is enough swap free to hold the RAM
  • not hibernate and warn/ask to proceed?

Or will this situation never happen because the kernel always reserves enough swap to safely hibernate?

Can I configure the behavior?

Edit: If this makes a difference, I'm currently using Ubuntu 12.04 with Linux 3.2.0-39-generic and hibernate with pm-hibernate.

Best Answer

on later versions of linux kernels you are required to have a swap to hibernate. But there are work arounds. you can setup a swap file anywhere without partitioning.

Read about it here. https://www.kernel.org/doc/Documentation/power/swsusp-and-swap-files.txt

a quick solution (credit to Robert Munteanu)

Create the swap file : dd if=/dev/zero of=/swapfile bs=1024 count=8388608 ( 8GB )
Setup the swap file: mkswap /swapfile
Only when you need to set suspend you can activate it: swapon /swapfile
When you resume you can deactivate it: swapoff /swapfile
Related Question