Occassional failure to resume: pci_pm_suspend(): nv_pmops_suspend+0x0/0x20 [nvidia] returns -5

To be more precise: since upgrading recently my Fedora, I had a systematic error when putting the computer to sleep, everytime: the screen would show some kernel messages, then flash a few times (trying to do something and failing), and I’d end up with the lock screen showing once again, and the computer still on, but keyboard/mouse/trackpad completely unresponsive. No way to do Ctrl+Alt+Del, Ctrl+Alt+F2, etc. So I had to force shutdown my computer (holding the power button for a few seconds) and restart.

I tried following some recommendations from another page which said to write to sudo emacs /etc/modprobe.d/nvidia-power-management.conf the following line:

options nvidia NVreg_PreserveVideoMemoryAllocations=1 NVreg_TemporaryFilePath=/tmp/nvidia

It didn’t help. So I disabled the option:

options nvidia PreserveVideoMemoryAllocations=0

And I am again able to put the computer to sleep and resume it.

But I’d like to not have to do it manually, since it’s probably going to break something in the future. If your solution is better, I’d please like to know what it is.