For laptops, battery life is one of the most important point to determine it's usability, the longer is better. Bad linux power management profile could dramatically decrease the battery life, really, from 5-6 hours in windows to 2-3 hours in Linux, ultimately newbies will say Linux is very power hungry !
Most modern laptops uses the ACPI for power management, it's much more flexible than old APM and managed by the OS, instead of BIOS. You don't need to worry about ACPI, it's already well integrated with Linux.
Here in this tutorial we are going to focus on normal usage like browsing, video and audio playback, word processing, note taking etc. etc, rather than totally idle state or heavy tasks like gaming.
Contents
Which Linux power management methods are worth to implement ?
In any UNIX like system everything could be tweaked to make it more power efficient, but few of them have noticeable power saving advantage. Bellow a few of them -
- Turn off discrete GPU like NVIDIA Optimus or Radeon Hybrid Graphics
- Disable Intel turbo boost or AMD's precession boost.
- Decrease display backlight
- CPU frequency scaling
- Spin down the hard drive, or better use SSD.
- GPU accelerated video playback
- Disable bluetooth, webcam, card reader
- Audio codec power management
- Optimize various kernel parameters
- Use power efficient network connection
- Use a lightweight desktop environment
This is a comprehensive list, there may be some useful power saving tweaks missing. Let's dig a little deeper with those options above.
Low or weared out Laptop battery ? Here how you can show alerts on low battery automatically.
1. Turn off discrete GPU
If you are using a laptop with switchable discrete graphics card, make sure it's turned off. This could be the biggest cause of power drain, almost tripling the power use than normal.
So how to turn off the discrete GPU ? It depends on your GPU and the Linux distro you are using. It's one of the first thing to do after installing ubuntu or any linux distro.
If you are using a NVIDIA Optimus GPU and running a Debian or Debian derivative, have a look at this guide, Configure NVIDIA Optimus in Debian with bumblebee .
For Ubuntu and Linux Mint, have look here, Ubuntu nVIDIA Optimus setup .
If you are using AMD hybrid/switchable GPU and running Ubuntu or any Ubuntu derivative, look at this guide.
The vgaswitcheroo module could be handy, just run the commands bellow to turn off the discrete graphics.
sudo -i # enter password echo OFF > /sys/kernel/debug/vgaswitcheroo/switch
Note: The vgaswitcheroo may not be always available.
2. Decrease display backlight
Laptop's backlight is another major power consumer, reduce display brightness to a comfortable level, which should match the ambient light.
Most laptops could adjust display brightness with dedicated hot keys. If you are using KDE, Gnome, Cinnamon, Unity and other heavy weight desktops, it should work out of the box.
You may need to add the acpi_backlight=vendor
boot time kernel parameter to the GRUB configuration for proper hotkey function, also don't forget to update GRUB after adding this.
Though in lightweight desktop environments, hotkey functionality may not be available. In such case use the xbacklight app to manage display brightness.
sudo apt-get install xbacklight xbacklight -set 15 # set brightness to 15 %
You could directly change the brightness through the sysfs interface. For intel GPUs, try this command,
root@host:~# echo 100 > /sys/class/backlight/intel_backlight/brightness
3. CPU frequency scaling and tubro boost
Casual tasks like browsing, reading pdf, playing audio doesn't require massive CPU power, so under clocking the CPU saves a lot of power.
Disabling the CPU turboo bost or AMD's precession boost makes a hubge difference in laptop's battery life. It's the second best thing to improve lapop's bettery life, after disabling the discrete GPU, if your laptop have any. You should notice a 1 to 5 hour of extra battery life, ofcourse depending on particular laptop model and it's battery.
Disabling the turbo boost on Intel CPUs could be done in few different ways, also dpending which scaling driver is in use, in intel's case, it's either intel_pstate or intel_cpufreq. Most CPUs support the pstate driver, which is the better of two.
echo '1' | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo # when using intel_pstate
echo '0' | sudo tee /sys/devices/system/cpu/cpufreq/boost # when using acpi cpufreq
Intel Sandy breeze or newer CPU uses the intel_pstate cpu scaling driver after kernel 3.9, it provides two CPU scaling governor, performance and powersave which is somewhat better than acpi_cpufreq driver.
Few words for scaling govornors, Probably need not to change anything here, as Linux kernel loads powersave or ondemand scaling driver by default, they are quite power saving and tries to always keep the CPU frequency lower.
Alternatively, you can use a simple script to set the govorner as powersave for even more battery life. An example below.
for cpu_gov in $(ls /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor); do echo 'powersave' > $cpu_gov; done
If you are using Ubuntu and Unity desktop, there is a nice unity panel applet, indicator cpufreq.
sudo apt-get install indicator-cpufreq
4. Spinning down the hard drive
Laptop hard drives could consume up to 2.5 watt power, depending on task. So spinning down hard drives during low I/O activity period could save a descend amount of power.
Though power saving by hard drive spin down is controversial, as it causes lagging and spinning up the drive requires power surge.
Hard drive spin down could be set with the hdparm
CLI app, install it in Debian or any Debain derivative
sudo apt-get install hdparm sudo hdparm -B /dev/sda # check current APM level
Now you could try to save some power by lowering the APM level, really works when very few apps are open and web browser is closed.
sudo hdparm -B 96 -S 0 /dev/sda
If you are using an external USB hard drive and it's idle, i.e. just plugged in, you could completely spin down it to save a lot of power.
sudo hdparm -B 0 -S 0 /dev/sdb # external drive is /dev/sdb
There's another change you can apply to the system, tweak how often the Linux system's virtual memory written to the disk.
Temporary solution, use sysctl command, run inside a root shell or use su -c. This will wait for 15 seconds before writing the changes to disk. Which in turn decreases number of disk access.
echo 1500 > /proc/sys/vm/dirty_writeback_centisecs
A permanent approach, create a file /etc/sysctl.d/custom_vm_dirty_writeback.conf and paste the line below, so you don't have to type the commands again and again.
vm.dirty_writeback_centisecs = 1500
5. GPU accelerated video playback
If sole purpose is to play movies and watch youtube, you should use hardware accelerated video playback when possible. It off loads the video decoding task to GPU, thus reduces CPU usage and ultimately saves some power.
Media players like VLC, MPV or recent version mplayer support hardware accelerated video decoding. Try Baka-Mplayer, a lightweight mpv based media player with GPU accelerated video decoding support and nice Qt 5 based user interface.
You should also use a browser with GPU acceleration support, most modern browsers like Chromium, Firefox, Opera supports it, here is how to enable hardware acceleration in any chromium based browser.
Avoid playing flash videos in browser, as it doesn't support GPU decoding there.
6. Disable bluetooth, webcam, PCI-E card reader
If you rarely use bluetooth, webcam or the PCI-E card reader, it's better to turn them off. Disable the bluetooth with rfkill
or hard block it with hotkeys if available. How to turn off bluetooth with rfkill
sudo apt-get install rfkill # install rfkill sudo rfkill block bluetooth
To disable bluetooth in Linux by blacklisting related kernel modules, create a text file /etc/modprobe.d/no-bluetooth.conf
and put the blacklist files bellow there.
blacklist btusb blacklist bluetooth
You could block the webcam in the same way, create a text file /etc/modprobe.d/no-webcam.conf
and put the blacklist configuration there.
blacklist uvcvideo
My laptop has a Realtek PCI-E card reader, I never used it, so I'm turning it off. Your card reader could be different, just find out which kernel driver it's using with lspci -k
and blacklist it. Blacklist configuration for Realtek RTS5209 card reader
blacklist rtsx_pci
You should also disable other unused devices too, like inbuilt GSM module or fingerprint scanner, if your laptop have any.
7. Audio codec power management
If you are not playing audio files frequently, put the sound card in idle state. As a temporary test, you could run the command bellow as root.
echo 1 > /sys/module/snd_hda_intel/parameters/power_save # as root
To make it permanent, find the Audio device, usually it's connected through PCI-E interface.
lspci | grep -i audio
Note the PCI Bus ID and identify the kernel driver in use.
lspci -k -s 00:1b.0 # example, your Bus ID could be different
If you are using a Intel HDA sound card, create the /etc/modprobe.d/idle-audio.conf
kernel driver configuration file and put the configuration bellow there.
options snd_hda_intel power_save=1
If you are using AC'97 codec based card, use this configuration
options snd_ac97_codec power_save=1
8. Optimize various kernel parameters
Add some extra kernel parameters to the GRUB configuration to make the system even more power efficient.It could be done in different ways, in Ubuntu or Debian add the extra parameters to the /etc/default/grub
file inside the line GRUB_CMDLINE_LINUX_DEFAULT="quiet" .
- If your laptop's CPU is Intel sandy Breeze or newer, save some power by idling the GPU, add
i915.i915_enable_rc6=1
- To enable intel GPU framebuffer compression, add
i915.i915_enable_fbc=1
Don't orget to run sudo update-grub after adding those kernel parameters.
Now disable some features through the sysctl.conf file, add the configurations listed bellow to the sysctl.conf file, you need root privilege to edit the file.
- Add
kernel.nmi_watchdog=0
to disable NMI watchdog, it's useless for most users. - Add
vm.dirty_writeback_centisecs=1500
to reduce writes to HDD.
Don't forget to run sudo sysctl -p
to apply the new configurations.
Runtime power management for PCI-E devices, helps to save power power on low activity PCI-E devices. An one line script to set auto power management.
sudo -i # become root, then run the script bellow. for pci_dev in /sys/bus/pci/devices/*/power/control; do echo auto > $pci_dev;done
I'm not going to play with the SATA link power management, as it may cause data loss.
9. Use power efficient network connection
Here I mean use a network adapter technology which consumes less power.
- Ethernet is most power efficient, use ethernet cable whenever possible. However Gigabit ethernet is not power efficient, could draw up to 1 Watt of power.
- The second choice is bluetooth, if you are tethering from a phone, for this you have to enable bluetooth. It sips power like nothing, but low speed and inconvenient these days.
- Third choice is Wi-Fi, it consumes significantly more power than ethernet and bluetooth.
- Worst choice is mobile broadbrand, i.e. a GSM/CDMA modem, it could consume 2 to 2.5 watt power.
10. Use a lightweight desktop environment
Bloated desktops like KDE, Cinnamon, Unity draws much more power than lightweight desktops, as there are many background services, file indexing apps running on them.
So It's good to choose a lightweight desktop environment like LXDE, LXQt or XFCE while running on battery power.
How to track power usage and optimize Linux power management ?
Powertop is a great app for this purpose, it provides an easy to understand result and possible hints to optimize power management.
In Debian, Ubuntu or any other derivative install powertop with apt-get.
sudo apt-get install powertop
Now take a measurement and generate a report for 1 minuite in HTML format with the powertop command.
sudo powertop --time=60 --html=power_report.html
Open up the HTML file with your favorite web browser and explore different results, the Tuning section is interesting.
Enough linux power management and power saving tweaks, hope it's simple enough and most readers will find it useful.
If you have any question or suggestion please leave comments, that will make this guide even better. Also share this tutorial with friends if you like it.
chris says
stumbled onto this accidentally when i noticed that my rig was just power hungry with linux mint Rosa. Used to get about an hour and a half now im manging to squeeze 4 hours out of it. I know im really pushing it will need to get a replacement oem battery next week. My Rig and Gpu thank you for more fun times with my pc
Arnab Satapathi says
Thanks for the feedback. Happy to know that you've found this guide useful.
supratim says
xbacklight not working and also the command is not working.Don't know about the grub.Display brightness still same.How do I fix this?
Arnab says
Does the /sys/class/backlight/intel_backlight/ folder exists ?
xbacklight won't work if ACPI backlight is configured properly.
To add acpi_backlight=vendor kernel parameter edit the /etc/default/grub file ar root, find the line GRUB_CMDLINE_LINUX_DEFAULT and add acpi_backlight=vendor line there. See this> https://cdn.pbrd.co/images/7DRfxdpm.png
Try the second command too, if intel_backlight doesn't exists, try /sys/class/backlight/acpi_video0/brightness .
Kon supratim ? Mahata babu ?
bonbonboi says
Good tutorial, I got a good idea how Linux power management works.
Arnab says
Thanks for your valuable feedback, keep visiting.
Koushik says
Great Arnab
Arnab says
Thanks Koushik, comment korar jonnyo.
Mrinmoy says
"Audio codec power management" exactly for this I was looking for, thanks for sharing the info.