Optimizing Power Consumption on My Home Server: Part 2 – Applying Power-Saving Settings Permanently

Making PowerTOP Optimizations Persistent

In Part 1, we explored how PowerTOP works and how to analyze power consumption on a Linux system. Now, in Part 2, we’ll focus on applying PowerTOP’s recommendations permanently, ensuring that our power optimizations persist after reboots.

Applying Power-Saving Settings Automatically

PowerTOP provides temporary tuning recommendations that reset upon reboot. To make these changes permanent, we need to apply them automatically at system startup.

1. Enable Runtime Power Management for PCI Devices

To enable runtime power management for all PCI devices, run:

for d in /sys/bus/pci/devices/*/power/control; do echo auto | sudo tee $d; done

To apply this automatically at boot, create a systemd service:

sudo nano /etc/systemd/system/pci_pm.service

Add the following:

[Unit]
Description=Enable PCI Runtime Power Management
After=multi-user.target

[Service]
Type=oneshot
ExecStart=/bin/sh -c 'for d in /sys/bus/pci/devices/*/power/control; do echo auto > $d; done'
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Enable it:

sudo systemctl daemon-reload
sudo systemctl enable pci_pm
sudo systemctl start pci_pm

2. Enable SATA Link Power Management

To enable SATA link power management:

for d in /sys/class/scsi_host/host*/link_power_management_policy; do echo med_power_with_dipm | sudo tee $d; done

For persistence:

sudo nano /etc/systemd/system/sata_pm.service

Paste:

[Unit]
Description=Enable SATA Link Power Management
After=multi-user.target

[Service]
Type=oneshot
ExecStart=/bin/sh -c 'for d in /sys/class/scsi_host/host*/link_power_management_policy; do echo med_power_with_dipm > $d; done'
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Then enable it:

sudo systemctl daemon-reload
sudo systemctl enable sata_pm
sudo systemctl start sata_pm

3. Enable Disk Power Management

Enable runtime power management for disks:

for d in /sys/block/sd*/device/power/control; do echo auto | sudo tee $d; done

For persistence:

sudo nano /etc/systemd/system/disk_pm.service

Paste:

[Unit]
Description=Enable SATA Link Power Management
After=multi-user.target

[Service]
Type=oneshot
ExecStart=/bin/sh -c 'for d in /sys/class/scsi_host/host*/link_power_management_policy; do echo med_power_with_dipm > $d; done'
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Then enable it:

sudo systemctl daemon-reload
sudo systemctl enable sata_pm
sudo systemctl start sata_pm

4. Disable NMI Watchdog

To disable the NMI watchdog (which can prevent deep CPU sleep states):

echo 0 | sudo tee /proc/sys/kernel/nmi_watchdog

For persistence:

sudo nano /etc/sysctl.d/disable_nmi_watchdog.conf

Add:

kernel.nmi_watchdog = 0

Apply:

sudo sysctl --system

5. Automate PowerTOP’s Auto-Tuning Feature

To let PowerTOP apply its optimizations automatically at boot:

sudo nano /etc/systemd/system/powertop.service

Add:

[Unit]
Description=Powertop tunings
After=multi-user.target

[Service]
ExecStart=/usr/sbin/powertop --auto-tune
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Then enable it:

sudo systemctl daemon-reload
sudo systemctl enable powertop
sudo systemctl start powertop

Final Thoughts

By applying these changes, your home server (or any Linux system) will now retain PowerTOP’s optimizations after every reboot. You should notice lower power consumption and possibly reduced heat and noise levels.

Have you tried optimizing your server’s power usage? Let me know your experience in the comments!

Leave a Reply

Your email address will not be published. Required fields are marked *