Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Changing laptop suspend from s2idle to deep sleep #blog

One thing I noticed ever since I bought my second Dell XPS was that the battery life was relatively abysmal when the laptop was asleep. I'd suspend my laptop at work, bring the laptop home, and the next morning I'd be down 25-50% of my battery life! More than once, I'd leave my laptop for a couple days and come back to a completely dead laptop1.

My first inclination was that the laptop was waking up on its own. It does happen occasionally with Linux (which, in an of itself, is pretty concerning2), but in this case, I was reasonably certain it wasn't the case, as evidenced by the battery drop overnight when waking a still-sleeping laptop.

While there are a plethora of articles online about sleep/standby (suspend to RAM) and hibernate (suspend to disk), the root cause was that some hardware configurations support three different modes of sleep: s2idle, shallow, and deep.

According to the Linux Kernel documentation:

[Suspend-to-idle] is a generic, pure software, light-weight variant of system suspend (also referred to as S2I or S2Idle). It allows more energy to be saved relative to runtime idle by freezing user space, suspending the timekeeping and putting all I/O devices into low-power states (possibly lower-power than available in the working state), such that the processors can spend time in their deepest idle states while the system is suspended.

[Standby] offers moderate, but real, energy savings, while providing a relatively straightforward transition back to the working state. No operating state is lost (the system core logic retains power), so the system can go back to where it left off easily enough.

[Suspend-to-RAM] offers significant energy savings as everything in the system is put into a low-power state, except for memory, which should be placed into the self-refresh mode to retain its contents.

You can see what mode your system is currently set to, by calling cat /sys/power/mem_sleep as any user (source):

julian@roci:~$ cat /sys/power/mem_sleep 
[s2idle] deep

On my laptop, the hardware supports s2idle and deep, which represents Suspend-to-RAM. The tradeoff of switching to deep sleep is that the laptop will take a little longer to resume. An s2idle wake would be near immediate, whereas a deep wake would take perhaps 5 seconds; a tradeoff I was more than willing to accept.

To change this setting temporarily:

julian@roci:~$ sudo su
root@roci:/home/julian# echo deep > /sys/power/mem_sleep

The first line logs me into the root user via sudo, and the second changes the sleep mode.

Persist the change across reboots

To make this change permanent, you can pass a setting to the Grub bootloader (source). As the root user:

  1. Edit /etc/default/grub using your favourite editor. Use nano if you do not have a favourite editor (trust me on this one, you don't want to get stuck inside vim)
  2. Find the line beginning with GRUB_CMDLINE_LINUX_DEFAULT
  3. Add mem_sleep_default=deep within the quotes. For me, the line would now read: GRUB_CMDLINE_LINUX_DEFAULT="quiet splash mem_sleep_default=deep"
  4. Save and exit the editor
  5. Execute update-grub to re-generate the grub config

I've found that even with the above steps, occasionally my laptop will be set back to s2idle. I have not figured out why that is the case. Think you might know why? Let me know as a comment here.


In other places...

It seems I may not be the only one frustrated by this. I discovered today that this feature is called "modern suspend". Of note is that on Windows systems, modern suspend cannot be changed unless the OS is completely reinstalled. Dell's workaround to this issue is to create a shell file that shuts down the computer, and to use this option instead of sleeping 🤯. It is wonderful to know that this is a configurable option in Linux.


Footnotes

1 With a desktop at home, I occasionally leave my laptop in my bag for days on end. Modern suspend essentially precludes me from being able to reliably pick up my laptop and go. There have been times where I am on the train, am notified of a work emergency, and open my laptop to discover that I have 5 minutes of battery life left.

2 One time, my laptop woke up while I was in line at an airport screening checkpoint. Imagine my surprise when I pulled out a too-hot-to-handle laptop with its fan at full blast!

Revisions

  1. 24 September 2021 – encountered a discussion about this on Hacker News, and updated this post accordingly with some fresh thoughts
@yeahman45
Copy link

yeahman45 commented Jul 9, 2022

nice man! thx!
have you been able to make it permanent?
I have added mem_sleep_default=deep to grub but it does not seem to work.

@julianlam
Copy link
Author

julianlam commented Jul 9, 2022

@yeahman45 no, unfortunately not. I thought that simply running update-grub would do the trick, but no such luck.

@yeahman45
Copy link

yeahman45 commented Jul 10, 2022

I have 2% drain per hour in deep sleep though; is it normal?

@satsking
Copy link

satsking commented Nov 8, 2022

Hey, I'm a complete n00b when it comes to Linux but I am trying it to get away from centralized products.

I did something similar in Pop OS that i found on another thread before finding this:
cat /sys/power/mem_sleep returned [s2idle] shallow (i am assuming my laptop doesn't support deep then?)
changed to shallow with sudo kernelstub -a mem_sleep_default=shallow and then restarted. checked again and got s2idle [shallow].

Then I closed my laptop and went away for an hour while it charged. came back and it was super hot and wouldn't wake from sleep.

I reset it by holding down power. Then restarted it and the fans went full blast.

Can anyone tell me what I need to do to prevent this over heat? Should I go back to s2idle?

@julianlam
Copy link
Author

julianlam commented Nov 9, 2022

@yeahman45

I have 2% drain per hour in deep sleep though; is it normal?

Definitely not, that's shallow sleep (or rather, maybe your computer's still running 😬 )

@satsking Assuming you're using a System76 laptop, you're better off asking them directly, as Pop!_OS is meant to work best with their hardware (not explicitly so, just implicitly)

It sounds like your laptop also didn't go to sleep.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment