New Linux kernel patch lets you cancel hibernation mid-process
A new Linux kernel patch is set to allow users to cancel the process of their machine going into hibernation, but the bigger context of the work may be more important. Collabora's Muhammad Anjum has proposed a power-button interrupt mechanism that could revolutionize the way we interact with our computers when they're in a suspended state.
Hibernation can take a while, with some machines taking up to 20 seconds to complete on Anjum's machine. The proposed change is simple: it adds a mechanism to cancel the process by pressing the power button. However, as Anjum explains, this is trickier than it sounds.
Hibernation is a tricky area in general, and Ubuntu leaves it disabled by default due to potential data loss issues. Hibernation problems can cause severe consequences, such as data loss or system lockouts, making it essential for users to be aware of the risks involved.
The current state of hibernation support is somewhat neglected, with many users failing to update their system firmware regularly. This can lead to hibernation issues, especially on older machines that require more frequent updates. The fwupd toolkit, a helpful tool for updating system firmware, has its own set of limitations and snags.
How Hibernation Works
Hibernation is the deepest of the four sleep levels defined by Intel, which includes Suspend-to-Idle, Standby, Suspend-to-RAM, and Hibernation. When a user tells their machine to hibernate, it saves all data in memory onto the SSD or hard disk, creates a snapshot of the OS's state, and then turns off.
One of the benefits of hibernation is that it uses no power at all while the computer is in this state. This makes it an attractive option for users who want to conserve energy or take their laptops on the road.
Downsides to Hibernation
However, there are downsides to hibernation too. Unlike Windows, Linux hibernates into whatever swap space is being used for virtual memory: a swap file or dedicated swap partition. This means that hibernation needs a swap volume as big as the physical RAM in the computer.
This can lead to issues if the user's machine is actively using some swap space, resulting in insufficient empty swap available for hibernation. Additionally, having unused swap space lying around just in case can be seen as a waste of drive space, especially on modern PCs with large amounts of RAM.
Hybrid Sleep: A Clever Hack
A clever hack called hybrid sleep tries to deliver the best of both worlds by creating a hibernation image on disk and then suspending to RAM. If the machine has enough battery, it wakes up from sleep; if the battery dies, it wakes up from hibernation instead.
With this mechanism in place, users can potentially experience faster wake-up times and improved performance. However, this feature is still in its infancy, and more work needs to be done to make it a standard part of Linux distributions.