Talk:Power management

From ArchWiki
Latest comment: 12 December 2023 by YHNdnzj in topic On-demand swap for hibernation only

Sleep hooks

Where is the exact difference between Suspend/resume service files approach and Hooks in /usr/lib/systemd/system-sleep?

Is the latter obsolete?

-- Orschiro 07:33, 17 January 2014

From systemd-sleep(8):
"Note that scripts or binaries dropped in /usr/lib/systemd/system-sleep/ are intended for local use only and should be considered hacks."
It's always preferred to use service files, they are much more flexible in handling the dependencies etc.
-- Lahwaacz (talk) 23:52, 31 January 2014 (UTC)Reply[reply]

Resume file does not work after resuming from hibernation

The systemd unit User resume actions presented on this page only worked for me after resuming from sleep, not from hibernate. After adding to the After and WantedBy lines it works both ways. However this is the first time I've done anything with such service files so I ain't sure if this is the optimal way. Can anyone confirm?

—This unsigned comment is by PhilippD (talk) 18:30, 12 October 2015‎. Please sign your posts with ~~~~!

Actually, the suspend@.service in Power_management#Suspend.2Fresume_service_files binds to, but resume@.service binds to They are not synonyms, systemd triggers and when the system is suspended to RAM, and and when it is suspended to disk. This way you can bind your service to either one or both suspend methods using just a single target. -- Lahwaacz (talk) 19:17, 12 October 2015 (UTC)Reply[reply]

Bluetooth rfkill

Systemd now provides systemd-rfkill.service. If you use rfkill block to disable bluetooth, systemd-rfkill.service will remember this and restore this state on next boot -- robtaylor (talk) Wed 18 May 16:10:05 BST 2016

A "sensible value" for the laptop mode

The vast amount of specific information carried in this part, I find it a bit surprising. It seems "A sensible value for the laptop mode 'knob' is 5 seconds." could be heard in the mouth of a politician kicking the ball into touch.

From Documentation/laptops/laptop-mode.txt:

> The value of the laptop_mode knob determines the time between the occurrence of disk I/O and when the flush is triggered. A sensible value for the knob is 5 seconds. Setting the knob to 0 disables laptop mode.

So "5 (seconds)" is related to the virtual memory subsystem (in direct relation to vm.dirty_writeback_centisecs). Then "0" turns laptop mode off, aha. It'd be cool to know *what* is laptop_mode is in the first place: Is it the whole vm configuration settings that are described in the docs? I believe not, as e.g. the conf files are not to be seen in present Arch (nor in other distros I know of).

A few things changed a bit since the Documentation/laptops/laptop-mode.txt was last edited, in 2004. I've searched extensively which part of it might still be up to date, without success so far. TLP has many if not most of the settings the doc explains. And so looks as an evolution of laptop_mode. Would a guru or someone with knowledge about that be kind enough to specify the effect of vm.laptop_mode? kozaki (talk) 23:33, 1 September 2016 (UTC)Reply[reply]

The effect of the vm.laptop_mode is described in the kernel docs in "The Details" section. The scripts that the docs talk about are probably Laptop Mode Tools nowadays. They are needed only to switch settings based on the current power source (and as a "bonus" they integrate most of the things in the Power_management#Power_saving section), but I bet the kernel settings are mostly the same as in 2004. -- Lahwaacz (talk) 08:41, 2 September 2016 (UTC)Reply[reply]
I now see that, thank you Lahwaacz. Now as we may increase flush time to disk (to, say, ten minutes) via vm.dirty_writeback_centisecs, delaying the flush up to five seconds via the vm.laptop_mode knob doesn't make much sense regarding the disk power-savings... But it may help the cpu staying idle longer. Hence, whether set via laptop-mode-tools, tlp or proper self-made udev rules. I.e. vm.laptop_mode and vm.dirty_* together help delaying and grouping system's activity as a whole, allowing for longer power-saving efficient idle times. Please correct me if I'm wrong. kozaki (talk) 19:37, 4 September 2016 (UTC)Reply[reply]
True, but the delay via vm.laptop_mode makes sense also for other reasons. Let's say vm.dirty_writeback_centisecs is set to something like 10 minutes and the disk is spun down due to inactivity and stays like that for e.g. 8 minutes, when it spins up due to user activity. Flushing all the cummulated dirty pages to the disk immediately might delay the request which caused the disk to spin up, so it's better to wait couple of seconds until there is chance that small high-priority requests have been serviced. Also, it might take couple of seconds to spin up the disk. -- Lahwaacz (talk) 20:14, 4 September 2016 (UTC)Reply[reply]

suspend to hibernate require fix

Rather than overriding the, I think we should just add in the [Install] section of the service. It works for me, and I think this is cleaner. Can anyone else confirm that this works? --Svvac (talk) 14:16, 28 May 2017 (UTC)Reply[reply]

network interfaces: udev rule does not work

At least a few other wiki pages point to this rule for how an example of how to turn off power management, because power mananagement breaks some current cards using the iwlwifi driver. Unfortunately the given udev rule does not work due to persistent device names. There is a note here about persistent device names, but it is really confusing. It stresses the importance of the number in the file name, but then states that it actually wont work anyway and to use the persistent name instead of the wildcard?? However even that won't work because the udev rule above has ACTION="add". At least in my case, that ACTION clause causes the rule to only trigger for the original device name (wlan0), and not the persistent name (wlp5s0). So if I use wlan0 everywhere, it triggers but has no effect. If I use wlp5s0 everywhere it never triggers. One solution is to remove the ACTION="add" clause and use the persistent name everywhere. Another solution is to continue using a wildcard in KERNEL, such as KERNEL="wl*", and then use the persistent name instead of %k in the RUN command. I chose the second solution and my full udev rule was this:

ACTION=="add", SUBSYSTEM=="net", KERNEL=="wl*", RUN+="/usr/bin/iw dev wlp5s0 set power_save off"

Note that I also tried using 99 instead of 70 for the filename with the original udev rule, but that did not work. Lllars (talk) 23:10, 5 August 2017 (UTC)Reply[reply]

What the note tries to say is that you can't "use wlan0" everywhere as you did. In any case, the command is run after the interface gets a persistent name, so you need to run iw dev wlp5s0 set power_save off (or, as the note says, iw dev $name set power_save off to make it generic). As for the matching, KERNEL is the "old name" and NAME is the "new name", which is assigned in 80-net-setup-link.rules. -- Lahwaacz (talk) 14:57, 6 August 2017 (UTC)Reply[reply]
Ok. In a way it's nice to have so much detail about how udev manages the initial and persistent names. But the way this is currently written is still very confusing. Thanks to $name, it sounds like we could just change the given udev rule to:
ACTION=="add", SUBSYSTEM=="net", KERNEL=="wl*", RUN+="/usr/bin/iw dev $name set power_save on"
with a note about how some people will need to use "eth*" instead of "wl*", or off instead of on. Then the whole section about persistent names is unnecessary extra info, and could either be ommitted or clarified and kept as an informational side note.Lllars (talk) 02:22, 7 August 2017 (UTC)Reply[reply]
Note that there are people who don't use the persistent names at all. -- Lahwaacz (talk) 06:17, 7 August 2017 (UTC)Reply[reply]

RTC drift bug in suspend-to-hibernate script

For some time now I have been trying to figure out an issue with my laptop that seems to happen when I use the suspend-to-hibernate script: the laptop would immediately wake up after hibernating.

I took some more time to investigate today, and I think (unfortunately not confirmed 100% yet - the issue was fairly rare) that there is a race in the script that causes the RTC to immediately wake up the computer after it gets suspended. Specifically, the RTC is reset after the hibernate has started, so it is possible that the reset does not happen before the computer hibernates.

Further, the source for the current time is the command date, whereas the RTC's idea of time might be a little different. I confirmed this by outputting /sys/class/rtc/rtc0/since_epoch at the same time as date +%s and saw delays as large as 4 seconds, but I suppose it could also get larger.

Combining the RTC drift and the fact that the RTC wakealarm reset happens after the hibernate has started, it is possible for the computer to immediately wake up from hibernation right after it hibernates if that happens quickly enough. This was especially noticeable in my case as it would then wait for me to enter my encryption password and drain my battery, overheating the CPU and the insides of my backpack.

I have two proposed changes to the script to make it better, but I suppose either one would fix the issue:

  1. Use /sys/class/rtc/rtc0/since_epoch as a base for the wakeup time, rather than date;
  2. Reset the RTC wakealarm before hibernating (right after reading it would be ideal).

I will keep investigating to see if I don't get the issue anymore (as I said, it was fairly rare and thus hard to confirm that it has definitely stopped happening), but if I don't see it in the next week, I'll submit an edit to the wiki.

--Cynary (talk) 09:16, 20 February 2018 (UTC)Reply[reply]

Userspace tools

Power management#Userspace tools now provides a list of graphical power managers and statistics tools as well as laptop power managers for the commandline. The recommendation to use only one of the listed tools because they conflict doesn't really fit anymore, how should that be changed? -- Progandy (talk) 12:42, 20 June 2018‎ (UTC)Reply[reply]

It could be changed to something like this: Be aware that using some of these tools in combination can result in unexpected behavior, such as double suspends. Please consult the documentation of the tool in question to see if there are any possible conflicts.
-- Chazza (talk) 16:12, 20 June 2018 (UTC)Reply[reply]
That sounds good. I looked a bit closer and most (all?) of the GUI tools do not have anything to do with power saving, they only monitor and sometimes react to low battery charge states. Maybe it would be better to split the list between power saving and power monitoring instead of GUI/Console? acpid and powertop do both, though.
Progandy (talk) 18:37, 22 June 2018 (UTC)Reply[reply]
Most GUI tools are not just monitors, e.g. MATE Power Manager can be used to turn off the screen and suspend the system after specified time, which definitely saves the power. On the other hand, most console tools are more advanced solutions, allowing more detailed power tweaks.
--City-busz (talk) 22:02, 22 June 2018 (UTC)Reply[reply]
Oh right, I somehow missed backlight and sleep management.
Progandy (talk) 08:43, 23 June 2018 (UTC)Reply[reply]

Add tool to userspace tools

Add auto-cpufreq to Power_management#Console RaZorr (talk) 13:01, 16 December 2021 (UTC)Reply[reply]

auto-cpufreqAUR may be more suitable under CPU frequency scaling#Userspace tools. -- Flyingpig (talk) 05:18, 17 December 2021 (UTC)Reply[reply]

Audio device power management

In Power_management#Audio it is stated that "audio power saving is turned off by most drivers". This is no longer true at least for snd_hda_intel, as of kernel 5.19.12-arch1-1. On my Dell Precision for example, this causes noise on headphones when no sound is playing. Indeed,

cat /sys/module/snd_hda_intel/parameters/power_save

shows 1 (enabled). Disabling it solves the issue. The following command can be used to test without rebooting:

sudo tee /sys/module/snd_hda_intel/parameters/power_save<<<0

I would like to update this section accordingly. Also, I wonder what is the best place to document this troubleshooting tip, if not already done. Thank you.--Topcat01 (talk) 00:10, 2 October 2022 (UTC)Reply[reply]

Did you test this with "most drivers"? Otherwise your hardware may be just one of the few having such issues. — Lahwaacz (talk) 08:11, 2 October 2022 (UTC)Reply[reply]
That's a good point and I thought of it too, but unfortunately I don't have access to other types of sound cards. In that case I'd just like to add a troubleshooting tip. Since this issue is caused by power management, I thought this page might be a good place. Advice welcome, thanks! -- Topcat01 (talk) 18:23, 2 October 2022 (UTC)Reply[reply]
Also, I noticed the idle noise only after the following updates, and on both regular and lts kernels:
linux-lts (5.15.69-1 -> 5.15.71-1)
linux (5.19.10.arch1-1 -> 5.19.12.arch1-1)
-- Topcat01 (talk) 20:04, 2 October 2022 (UTC)Reply[reply]
So it seems your problems are related to some regression in the kernel and not to the note in the wiki. Did you search for a bug report? — Lahwaacz (talk) 08:13, 3 October 2022 (UTC)Reply[reply]
Yes, it seems to be a kernel regression. The default power management setting did not change recently for snd_hda_intel in Arch's config. Also I tried other machines and they did not have this issue with snd_hda_intel when power saving is enabled (the default). In light of this the change I proposed is not necessary. It would still be useful to add a tip on how to toggle power saving on the fly for testing, which the sudo tee above does. -- Topcat01 (talk) 18:38, 4 October 2022 (UTC)Reply[reply]

On-demand swap for hibernation only

Special:Diff/791319 asked "If the swap space exists, why not just keep it activated?". The reason is simple—some people do not want to use any disk based swap outside of hibernation purposes regardless of any claimed benefits it may bring. Personally I dislike the whole idea that swap space and the hibernation image reside in the same file or volume. IMO Windows does it better with pagefile.sys and hiberfil.sys being separate. -- nl6720 (talk) 13:19, 28 October 2023 (UTC)Reply[reply]

You can always use a swap backed by e.g. a zram device alongside another that's backed by physical storage. By raising the priority of the former, you actually get the benefits from both - most of the time you're using the fast zram, and hibernation works without all these workarounds (systemd-sleep would skip zram devices when trying to find swap to hibernate into.) This should make everyone happy? -- YHNdnzj (talk) 13:34, 28 October 2023 (UTC)Reply[reply]
That's not a solution for those who don't use and don't want to use swap on zram. -- nl6720 (talk) 13:36, 28 October 2023 (UTC)Reply[reply]
They should really read then IMHO... -- YHNdnzj (talk) 15:54, 28 October 2023 (UTC)Reply[reply]
In summary, you think an appropriate solution would be using zram (maybe zswap) and keep the backed swap memory enable for hibernation, yet there's still no relatable solution for allocating the memory reclamation properly on swap, since nothing can head off completely the hibernation space, even along explicitly set high priority on zram's mount point e.g, or tweaking vm.swappiness won't prevent using swap space at all. So what could be a good workaround to rewriting this section? Sure on the referred article "In defence of swap", by Chris Down, is noted a tunable way to work with cgroups v2 then align reclaim memory for certain applications, but then again, besides that your hibernation's space could be used overall (at least a small amount). If it's not a issue to worry about, I'd like to understand, at least in your POV, why it's not a problem and what could be an accurate way to rewrite this section. Mxzcabel (talk) 15:37, 11 December 2023 (UTC)Reply[reply]
... tweaking vm.swappiness won't prevent using swap space at all.
So what I'm trying to say here is that there's really no point in preventing the use of swap completely. You have the space, and the kernel uses it when it thinks reasonable. Instead of disabling swap due to outdated, potentially misleading information, it's better to understand what swap really is and how it works.
To be clear, I fixed a bug for systemd in such setups [1] and I might still do that in the future, but I would definitely not consider it supported, not only in the sense of systemd but for the sane memory management of the whole system - as mentioned in the blog.
-- YHNdnzj (talk) 19:22, 12 December 2023 (UTC)Reply[reply]

power_level parameter in iwlwifi could be relevant

The iwlwifi module provides the power_level parameter, which "sets the default power save level"

I assume this parameter is important for further power saving. I was not able to find more detailed documentation on what it does though

Oneuseaccount (talk) 14:11, 19 November 2023 (UTC)Reply[reply]