Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
is "echo mem > /sys/power/state" good practice?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
fpemud
Guru
Guru


Joined: 15 Feb 2012
Posts: 349

PostPosted: Fri Aug 10, 2018 2:59 pm    Post subject: is "echo mem > /sys/power/state" good practice? Reply with quote

I know that all userspace processes just freeze/thaw in "echo mem > /sys/power/state" scenario, they even don't know what happened.
But in for example "systemctl suspend" scenario, process can get notification, can inhibit the suspend process. It is more complex or more "graceful". Many system service or application is using these features, like NetworkManager.

I want to know are all these "graceful" behaviors really necessary? Not because linux programs are not "robust" enough?
If they are, then "echo mem > /sys/power/state" would definitely break the system and should not be used.
Back to top
View user's profile Send private message
eccerr0r
Watchman
Watchman


Joined: 01 Jul 2004
Posts: 9679
Location: almost Mile High in the USA

PostPosted: Fri Aug 10, 2018 3:46 pm    Post subject: Reply with quote

Depends.

If the "graceful" suspend occurs, there's a higher chance of recovery IF something happens between when the suspend takes place and the resume.

If you guarantee that nothing bad happens like a piece of hardware gets pulled like a disk or a power supply, or if the hardware gets placed into some unscrupulous person's hands (hint: do you want your security keys suspended in memory?), then the quick memory suspend is fine...it was designed to be minimal safe suspend.
_________________
Intel Core i7 2700K/Radeon R7 250/24GB DDR3/256GB SSD
What am I supposed watching?
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 6920

PostPosted: Fri Aug 10, 2018 5:42 pm    Post subject: Reply with quote

I accidentally suspended using that one-liner while mpv was streaming a video and it came back fine, that's a pretty good indication of how unnecessary all the other layers are.

Paranoid security and syncing removable devices are valid use cases for doing anything fancier, but anything else is just broken software.
Back to top
View user's profile Send private message
eccerr0r
Watchman
Watchman


Joined: 01 Jul 2004
Posts: 9679
Location: almost Mile High in the USA

PostPosted: Sat Aug 11, 2018 1:57 am    Post subject: Reply with quote

I'm not entirely sure it's simply security paranoia, if you have to leave your laptop somewhere or forget it's suspended, someone can instantly unsuspend it and see exactly what you were doing at the time of suspend, no password needed. At least with the infrastructure it will blank the screen and ask for a password before allowing access once more.

Or if you forget about your computer while it's suspended and your battery runs out... if everything was synced and cleaned up before you suspend with the infrastructure, you could be back and running with less data loss.

It's totally up to you on the risk you want to take.
_________________
Intel Core i7 2700K/Radeon R7 250/24GB DDR3/256GB SSD
What am I supposed watching?
Back to top
View user's profile Send private message
fpemud
Guru
Guru


Joined: 15 Feb 2012
Posts: 349

PostPosted: Sat Aug 11, 2018 9:58 am    Post subject: Reply with quote

Quote:
I'm not entirely sure it's simply security paranoia


It is a good point I didn't know about.
So at least there's a chance for the system admin to choose between simplicity and security.



Quote:
For some platforms, it is possible that the hardware state changes during suspend/hibernation, in which case it will be necessary to update the rfkill core with the current state is at resume time.


The above is from rfkill.txt in linux kernel documentation I read today.
This behavior is what I think is "not robust", and is one of the reasons why NetworkManager needs to interact with systemd to receive the suspend/resume event.
Kernel drivers know suspend/resume happened, why doesn't the kernel update the rfkill state and notify userspace the state change as if the hardware state changes when resume happens?



Quote:
syncing removable devices


This action should also be taken by the kernel and be transparent to userspace.
Back to top
View user's profile Send private message
eccerr0r
Watchman
Watchman


Joined: 01 Jul 2004
Posts: 9679
Location: almost Mile High in the USA

PostPosted: Sat Aug 11, 2018 2:19 pm    Post subject: Reply with quote

Technically running sync is not necessary as before and after suspend, the state of memory and disk theoretically should match - so even if you don't sync, it should be fine (as long as you don't lose power or otherwise disturb state.)

However there's also the notion of what's in userspace versus what's on disk, and kernel does not necessarily know what's consistent or not. So for those sensitive (or stupid?) applications, getting an alert could let it flush state to disk as well.

However once again, there's no need for this unless you have inadvertent state loss during suspend.
_________________
Intel Core i7 2700K/Radeon R7 250/24GB DDR3/256GB SSD
What am I supposed watching?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum