Score:8

What does this command do (echo deep | sudo tee -a /sys/power/mem_sleep)?

br flag

I have solved the problem of my laptop waking in 20 seconds like this - see links there. I would like to understand how this works.

That solution is to somehow modify a variable in /sys/power/mem_sleep, namely s2idle to deep.

Looking at that file it contained this single line:

s2idle [deep]

which was already confusing , given both variables seemed mentioned there, one in brackets.

I didn't need to decide anything though, because, as instructed in the second comment, I haven't tried to change that file as such, but I have used the command:

echo deep | sudo tee -a /sys/power/mem_sleep

Looking again at that file it seemed unchanged though.

After restart the waking from suspend is instantaneous, but that file has the same single line s2idle [deep] that it had in the first place.

I have trusted that solution but:

  • I don't know how to reverse that in case I had to

  • The file seems unchanged so what changing/reversing could mean?


Maybe interesting to notice, there is a file at that location sys/power/wakeup_count which contains this single line: 20. Could those be the 20 seconds that I had experienced before?

Pilot6 avatar
cn flag
This command wrote `deep` to the file. But it had already `deep` selected. It is a default value. The value in brackets shows the value selected. You can try to write `s2idle` and see what happens.
br flag
@Pilot6 - Could it be that in a buggy way that option was not "read" and became active after my command?
Pilot6 avatar
cn flag
Well, it could be the case...
br flag
@user68186 - Indeed that file and all the others at the same location/folder are marked as recently modified. But the file looks like it was before my command although the suspend/wake behavior is different.
br flag
@Pilot6 - `This command wrote deep to the file`. - `try to write s2idle and see what happens`. You mean to run `echo s2idle | sudo tee -a /sys/power/mem_sleep`? And should that trigger the line `[s2sleep] deep`?
Pilot6 avatar
cn flag
Yes, this is correct.
mathtick avatar
in flag
HOW TO CHANGE!? IS EDITING THE FILE ALLOWED? It appears not.
br flag
@mathtick - All that remain obscure, the document cannot be manually changed, but it can be changed by that command as seen in my linked answer (see first line of the question) . By the way: don't use uppercase letters.
Score:4
cn flag

You wrote deep to that system file. That file has fixed values that you can see. The one in brackets is the selected value. So it doesn't look like you changed anything.

The meaning of the values is:

The /sys/power/mem_sleep file controls the operating mode of system suspend. Reading from it returns the available modes as "s2idle" (always present), "shallow" and "deep" (present if supported). The mode that will be used on subsequent attempts to suspend the system (by writing "mem" to the /sys/power/state file described above) is enclosed in square brackets.

  Writing one of the above strings to this file causes the mode
  represented by it to be used on subsequent attempts to suspend the system.
  See Documentation/admin-guide/pm/sleep-states.rst for more
  information.

The /sys/power/wakeup_count file allows user space to put the system into a sleep state while taking into account the concurrent arrival of wakeup events. Reading from it returns the current number of registered wakeup events and it blocks if some wakeup events are being processed at the time the file is read from. Writing to it will only succeed if the current number of wakeup events is equal to the written value and, if successful, will make the kernel abort a subsequent transition to a sleep state if any wakeup events are reported after the write has returned.

Source: https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-power

br flag
(you seem to have posted twice). Do you know what each variable means? `"s2idle" (always present), "shallow" and "deep" (present if supported)` - I might test them but maybe that is risky?
Pilot6 avatar
cn flag
Oops. I'll fix it. The second part is about wakeup_count.
br flag
After doing the `s2idle` selection the file was changed as expected (brackets moved onto that). But that didn't change the behavior of my laptop regarding wakeup time. It's still instant. So the problem was different in the first place. Now I don't know what option is better. In the initial comment that provided the solution it says `deep` maybe helpful for power consumption etc. But the initial problem seems buggy, fixed now, but which I cannot track anymore.
br flag
`The second part is about wakeup_count` - my secondary question was in fact "what *is* wakeup count?" And by the way what is the difference between `deep` and `s2idle` - and `shallow`?
Pilot6 avatar
cn flag
`deep` is default if present. Explanation of `wakeup_count` has been added.
br flag
This looks like a bug (after some update, the initial problem re-appeared and was fixed in the same way: the file `/sys/power/mem_sleep` was already in the form that the command is supposed to trigger, but the latter is needed nonetheless. - Do you have an idea against what package this could be reported (or checked if already reported) as a bug?
Pilot6 avatar
cn flag
It can be reported against kernel. `ubuntu-bug linux`.
br flag
In fact it seems that after a while in 22.04 and always in 22.10 the opposite command `echo s2idle | sudo tee -a /sys/power/mem_sleep` is the one that is needed! - Very odd and very hard to track. Updated [here](https://askubuntu.com/a/1434727/925128).
br flag
[This](https://unix.stackexchange.com/q/719830/341192) question contains the pertinent info I was trying to get about what those commands do: `deep` *was* supposed to trigger a longer wake-up time in the first place and lower battery use, `s2idle` is supposed to give short wake-up time and use more energy. Something was wrong in 22.04 and then was fixed. At some point a new problem appeared where `s2idle` was not remembered across reboots (I have to run that command at startup now.)
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.