On Wed, Feb 19, 2020 at 10:13 PM Chris Murphy <lists@colorremedies.com> wrote:
My test: Fedora Workstation 31, laptop with 8G RAM, 8G swap partition,
fill up memory using Firefox tabs pointed to various websites, and
then I followed [1] to issue two commands:

# echo reboot > /sys/power/disk
# echo disk > /sys/power/state

I experience twice as many failures as successes. Curiously, the
successes show pageout does happen. Before hibernate there is no swap
in-use, but after resume ~2GiB swap is in-use and RAM usage is about
50%.

Sigh. Turns out this is "my" mistake. 🤦 Hibernation apparently gets affected by sysctl value vm.swappiness, in my case vm.swappiness=0. When the value is zero, the hibernation never swaps out the extra memory over 50% and therefore can't hibernate. When I set it to any positive value (including 1), it works as you described. And all those people on kernel mailing lists probably also used vm.swappiness=0 and didn't realize. This might even be a kernel bug, because the documentation doesn't specify this should affect hibernation behavior, and I'd expect it _should_ affect only live system usage and not hibernation. But I can't really tell.

I'm sorry for having confused up this discussion :-/

In case it's interesting, my testing approach was to open up gimp, open a picture and enlarge it to 40000 px wide, which takes over 8GB RAM. In total, I have then about 9GB RAM usage out of total 16GB RAM. Then I issued "systemctl hibernate". With vm.swappiness=0, there's the out of memory error I already posted before. I tested that the same occurs when I directly instruct the kernel to hibernate:
# echo disk > /sys/power/state
-bash: echo: write error: Cannot allocate memory

When I switch to vm.swappiness=1 (or the default 60), I can hibernate just fine, and I resume with ~6GB RAM in memory and ~3GB in swap. If it is still relevant, I can provide exact numbers from /proc/meminfo. But I guess now that we see it doesn't affect people by default, it's no longer that important. This also invalides most of my previous suggestions about ideal swap size. OTOH I'm very happy that you proved me wrong and I discovered this, because now I can again hibernate even when my memory is quite full.