Apply PowerTOP recommendations via a tmpfiles.d configuration file.
This is a bash script to convert a powertop.csv
into the systemd-tmpfiles
format, which can be easily edited and applied on boot.
Archlinux users can also use the .
# The script can run standalone
curl -sSLO https://raw.githubusercontent.com/bbx0/powertop-to-tmpfile/main/powertop-to-tmpfile
bash powertop-to-tmpfile --help
# The makefile takes care of a system-wide installation including the man page
git clone https://github.com/bbx0/powertop-to-tmpfile.git
sudo make -C powertop-to-tmpfile install
powertop-to-tmpfile --help
# Reboot if you have run powertop before to restore the default configuration
sudo reboot
# Collect the PowerTOP recommendations into file ‘powertop.csv‘
sudo powertop --csv=powertop.csv
# Convert the powertop.csv to a tmpfile
powertop-to-tmpfile --csv powertop.csv |sudo tee -a /etc/tmpfiles.d/powertop.conf
# Review the file /etc/tmpfiles.d/powertop.conf and remove entries you don't want.
# e.g. a wireless mouse or keyboard may not work well with the powertop recommendations
# Activate the generated tmpfile (or reboot)
sudo systemd-tmpfiles --create /etc/tmpfiles.d/powertop.conf
The automatic workflow mimics the powertop --auto-tune
option and directly activates all recommendations. These are persisted in file /etc/tmpfiles.d/powertop.conf
and activated on boot.
# Example execution of the `powertop-to-tmpfile --auto-tune` command
$ sudo powertop-to-tmpfile --auto-tune
Running powertop.. (This will take a while.)
+ powertop --csv=/tmp/tmp.SyTyFr3zyS/powertop.csv
Creating tmpfiles.d configuration: /etc/tmpfiles.d/powertop.conf
## Generated by powertop-to-tmpfile at 2024-04-09 14:10:07 CEST
# NMI watchdog should be turned off
w /proc/sys/kernel/nmi_watchdog - - - - 0
# VM writeback timeout
w /proc/sys/vm/dirty_writeback_centisecs - - - - 1500
Activating tmpfiles.d configuration: /etc/tmpfiles.d/powertop.conf
+ systemd-tmpfiles --create /etc/tmpfiles.d/powertop.conf
All done.
A systemd-tmpfile
is not the “correct” way to apply device configuration. This would be to use udev
rules or module configuration. That said, generating a tmpfile from the powertop.csv
is fairly simple and works very well for a static device configuration. If you have changing devices or devices only added after boot, you want to use a different mechanism to apply the PowerTOP recommendations.