Skip to content

Instantly share code, notes, and snippets.

@LarryIsBetter
Last active April 24, 2024 23:58
Show Gist options
  • Star 50 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save LarryIsBetter/218fda4358565c431ba0e831665af3d1 to your computer and use it in GitHub Desktop.
Save LarryIsBetter/218fda4358565c431ba0e831665af3d1 to your computer and use it in GitHub Desktop.
Linux Laptop Optimizations

I have a website now that includes a more dumbed down but straight forward version of this guide that isnt basied towards Arch Linux but considers most distros. https://linuxguidance.net/improve-battery-and-optimize-your-linux-laptop/

Everything I do in this guide is mostly taken from the Arch Wiki, and is for Arch Linux, obviously this can probably be applied to other Linux distributions especially Arch based ones, this guide is for people who want a laptop with similar effciency they had on Windows or MacOS. I hate the excuse of having to compromise on Linux to have good battery or thermals on laptops.

Please think of this guide as more of a starting point, if you're serious about fully optimizing your laptop research your laptop and the hardware inside of it as that can get you even further down the rabbit hole.

This guide assumes you have a relatively modern laptop with at least an SSD from the factory, if you don't, don't worry you can still probably follow this guide perfectly, if you have a 32-bit laptop I'm using 64-bit packages only, but there should be 32-bit packges in the Arch multilib repo, just don't assume everything will work or not break your laptop, please read carefully, and don't copy and paste commands or edit config files blindly and research everything before you do it, I won't be responsible for a broken OS or even broken hardware. This warning applies to modern laptops too.

This guide is not for people who want to get the most out of their battery by disabling stuff like Bluetooth, or by limiting their hardware or OS. (Except CPU power profiles).

Everything in this guide is biased to my laptop with an Intel CPU and GPU, I'll leave the Arch Wiki pages for AMD and NVIDIA laptops where it's needed so people with that hardware aren't left out, for dual GPU laptops I've left Arch Wiki pages on how to enable GPU switching at the bottom of this guide please consider enabling it as thermals and battery life will improve significantly.

Please uninstall all your power saving packages if you plan on following this guide because they'll cause conflicts. (Unless its Thermald or power-profiles-daemon)

I'll keep updating this guide if I find anything new to improve efficiency. Please point out any errors, mistakes or inconsistencies.


Step 1. Kernel and Drivers

  • When picking what kernel to use (Latest or LTS) the latest kernel will most likely have better performance and battery life, especially on newer hardware, and the LTS kernel will have better stability and reliability, depending on your devices age you might be better off with the LTS kernel for stability reasons. (For AMD CPU devices you'll want kernel 5.17+ for the AMD p-state driver, it improves performance and power saving).

  • Install the microcode for your CPU if you haven't already.

  • From the Arch Wiki "Processor manufacturers release stability and security updates to the processor microcode. These updates provide bug fixes that can be critical to the stability of your system. Without them, you may experience spurious crashes or unexpected system halts that can be difficult to track down."

  • If you are using PulseAudio I recommend switching to Pipewire.

run sudo pacman -S linux-firmware if you haven't installed it.

As of 01/21/2022 the linux-firmware package was split into multiple packages to reduce disk space usage, research your hardware and see what you might need to additionally install. [1]


Step 2. Wayland

For KDE run sudo pacman -S plasma-wayland-session (if you are an NVIDIA user, also install egl-wayland, and if the session does not start with the proprietary NVIDIA driver, also enable the DRM kernel mode setting),[1] then select the session from your login screen.

On Gnome, Wayland should be enabled by default.

For other desktop environments I'll leave the Arch Wiki page for desktop environments.


Step 3. Early KMS

  • From the Arch Wiki "KMS is typically initialized after the initramfs stage. However, it is possible to enable KMS already during the initramfs stage."
  • From the Arch Wiki "KMS also enables newer technologies (such as DRI2) which will help reduce artifacts and increase 3D performance, even kernel space power-saving."
  • Early KMS can fix hibernation issues on Intel GPU's. [1]
  • I'm not sure how early KMS works with dual GPU's laptops with mixed brands please look into that before doing this.
  • This step is for Intel GPU's, I've left the Arch Wiki page for other GPU brands below, it should be similar to what is done here.
  • You'll need early KMS for step 11.

run sudo nano /etc/mkinitcpio.conf and change the "MODULES=" to how it's shown below.

# vim:set ft=sh
# MODULES
# The following modules are loaded before any boot hooks are
# run.  Advanced users may wish to specify all system modules
# in this array.  For instance:
#     MODULES=(piix ide_disk reiserfs)
MODULES=(i915)

Save and exit.

run lsmod | grep intel_agp If the module is not loaded run sudo mkinitcpio -P then reboot the laptop, and continue to step 4. If the module is loaded continue this step down below.

run sudo nano /etc/mkinitcpio.conf and change the "MODULES=" to how it's shown below.

# vim:set ft=sh
# MODULES
# The following modules are loaded before any boot hooks are
# run.  Advanced users may wish to specify all system modules
# in this array.  For instance:
#     MODULES=(piix ide_disk reiserfs)
MODULES=(intel_agp i915)

Save and exit.

  • From the Arch Wiki "Intel users may need to add intel_agp before i915 to suppress the ACPI errors (check the output of lsmod on your running system to see if intel_agp is loaded). This may be required for resuming from hibernation to work with a changed display configuration. If you use PRIME GPU with Intel IGP being your primary GPU and AMD as the discrete one, adding intel_agp may lead to troubles when resuming from hibernation (monitor gets no signal). See [2] for details."

run sudo mkinitcpio -P

Reboot your laptop.


Step 4. Hardware Acceleration

  • From the Arch Wiki "Hardware video acceleration makes it possible for the video card to decode/encode video, thus offloading the CPU and saving power."
  • This step is for Intel GPU's, I left Arch Wiki pages for other GPU brands below, it should be similar to what is done here.
  • For dual GPU laptops enabling GPU switching will use your iGPU for light work and dGPU for heavy work, the power savings can be significant, I left Arch Wiki pages for GPU switching at the bottom on this post.
  • After you've set everything up I recommend seeing this Arch Wiki page to enable hardware acceleration in applications.
  • If you are on an older AMD GPU that cannot decode VP9 be aware that Fedora Linux will disable H.264, H.265 and VC1 hardware accelerated decoding and encoding other distros might disable these soon, please research your distro to see if they have. (IMO the best workaround is using flatpak and following this guide).

run lspci | grep VGA to see your GPU

For Intel GPU's 2014 and newer run sudo pacman -S intel-media-driver libvdpau-va-gl libva-utils vdpauinfo intel-media-sdk | From the Arch Wiki "HD Graphics series starting from Broadwell (2014) and newer are supported by intel-media-driver."

For Intel GPU's 2013 and older run sudo pacman -S libva-intel-driver libvdpau-va-gl libva-utils vdpauinfo intel-media-sdk | From the Arch Wiki "GMA 4500 (2008) and newer GPUs, including HD Graphics up to Coffee Lake (2017) are supported by libva-intel-driver."

run export LIBVA_DRIVER_NAME=iHD | If you installed intel-media-driver.

run export LIBVA_DRIVER_NAME=i965 | If you installed libva-intel-driver.

run export VDPAU_DRIVER=va_gl

run vainfo to confirm everything is working.

run vdpauinfo to confirm everything is working.

If everything is working run sudo nano /etc/environment and add "LIBVA_DRIVER_NAME=iHD" or "LIBVA_DRIVER_NAME=i965" (Depending on the hardware acceleration driver you've installed). Then add "VDPAU_DRIVER=va_gl", how it is shown below.

#
# This file is parsed by pam_env module
#
# Syntax: simple "KEY=VAL" pairs on separate lines
#
# 
# Hardware Acceleration / GPU 
LIBVA_DRIVER_NAME=iHD or LIBVA_DRIVER_NAME=i965
VDPAU_DRIVER=va_gl
MESA_LOADER_DRIVER_OVERRIDE=iris  |  If your Intel GPU is gen 8+

(This is for Firefox not Chromium based web browsers). From the Arch Wiki "VA-API will be enabled by default on systems using Mesa for OpenGL, starting with Firefox 103. This means that force enabling the feature via media.ffmpeg.vaapi.enabled will no longer be required for these systems." (Note you'll still need to disable VP9 if your GPU or your hardware acceleration driver doesn't support VP9 video decoding).

Check if your GPU and hardware acceleration driver can decode VP9 if it can't install the h264ify browser extension, [1] [2] or for Firefox and Firefox derivatives go it into about:config and set media.mediasource.vp9.enabled to false otherwise you won't be able to watch videos with hardware video decoding, keep in mind h264ify or changing media.mediasource.vp9.enabled to false will disable resolutions above 1080p.


Step 5. Undervolting

  • WARNING UNDERVOLTING CAN BRICK YOUR LAPTOP PERMANENTLY IF YOU ACCIDENTALLY OVERVOLT IT MAKING IT COMPLETELY UNUSABLE I WONT BE RESPONSIBLE IF YOU DO BRICK YOUR LAPTOP.
  • From Arch Wiki "Undervolting is a process where voltage to CPU is reduced in order to reduce its energy consumption and heat without affecting performance. Note that most desktop motherboards allow tweaking CPU voltage settings in BIOS as well."
  • From Arch Wiki "It is no longer possible to undervolt Intel processors with modern BIOSes and microcode, due to the changes needed to patch the Plundervolt vulnerability."
  • There is a method to undervolt K10 and newer AMD CPUs, I'll leave a link to the Arch Wiki page.
  • Do not use this guide to undervolt your AMD CPU.

run sudo pacman -S intel-undervolt

For kernels 5.9+ you need to add "msr.allow_writes=on" as a kernel parameter to your boot loader I'll leave the Arch Wiki page for adding kernel parameters to your boot loader. After you added the kernel parameter reboot your laptop.

run sudo nano /etc/intel-undervolt.conf

Decrease the CPU mV by -10 how it's shown below.

undervolt 0 'CPU' -10
undervolt 1 'GPU' 0
undervolt 2 'CPU Cache' 0
undervolt 3 'System Agent' 0
undervolt 4 'Analog I/O' 0

Save and exit, then run sudo intel-undervolt apply && sudo intel-undervolt read and make sure it applied properly.

Next stress you'll test for system stability as undervolting can cause a system to crash or hang or even become unbootable, run yay -S mprime-bin

run mprime

Stress test for 30 minutes, then decrease the mV by -10 for every successful run until your laptop crashes or hangs, once you find the sweet spot you can enable the undervolt service run sudo systemctl enable intel-undervolt.service and please make sure your system runs stable before enabling this service as it can result in an unbootable or unstable system.


Step 6. Swap

  • Most distributions have swap configured in some way I don't recommend touching it if it is enabled, for stability reasons they know what they are doing and how to setup their system and how their OS works.

  • Swap makes memory management for your laptop easier,[1] [2] [3] if you're worried about SSD writes I recommend using ZRAM, I'll also show you how to reduce swappiness or turn off swapping.

  • For most people I recommend using ZRAM Fedora and ChromeOS use it, it wont tax your SSD/HDD and makes swapping faster as your system is swapping to RAM (I know that sounds confusing I've left links explaining how it works) so slow downs to the system aren't as noticable when doing memory intensive work loads since your RAM is most likely faster than your SSD/HDD, older or less powerful laptops with an HDD and or 4 to 8 GBs of RAM will benefit the most from ZRAM but I still recommend enabling ZRAM on powerful modern laptops even if you think you don't need it, if you do want to use ZRAM and want to use hibernation then it won't work but I don't recommend using hibernation anyways my reasons will be listed in step 7.[1] [2] (If you plan on using ZRAM and a regular swap file or partition don't use ZRAM then or just don't use a regular swap file or partition).

  • If you plan on swapping with your partition or swap file enable zswap, from the Arch Wiki "Zswap is a kernel feature that provides a compressed RAM cache for swap pages. Pages which would otherwise be swapped out to disk are instead compressed and stored into a memory pool in RAM. Once the pool is full or the RAM is exhausted, the least recently used (LRU) page is decompressed and written to disk, as if it had not been intercepted. After the page has been decompressed into the swap cache, the compressed version in the pool can be freed."

  • I'll show you how to decrease or turn off swapping here, if you're doing this to reduce SSD writes and not for a specific reason please read. [1] [2] [3] IMO it's better to have better system performance at the sacrifice of an unnoticeable amount of SSD longevity. Personally I wouldn't touch swappiness or vfs cache pressure as the defaults work fine for most set up and touching them can actually slow your laptop down.

run sudo nano /etc/sysctl.d/99-sysctl.conf

add vm.swappiness = "Number"

  • From the Arch Wiki "The swappiness sysctl parameter represents the kernel's preference (or avoidance) of swap space. Swappiness can have a value between 0 and 200 (max 100 if Linux < 5.8), the default value is 60. A low value causes the kernel to avoid swapping, a high value causes the kernel to try to use swap space, and a value of 100 means IO cost is assumed to be equal. Using a low value on sufficient memory is known to improve responsiveness on many systems."

add vm.vfs_cache_pressure = "Number"

  • From the Arch Wiki "Another sysctl parameter that affects swap performance is vm.vfs_cache_pressure, which controls the tendency of the kernel to reclaim the memory which is used for caching of VFS caches,versus pagecache and swap. Increasing this value increases the rate at which VFS caches are reclaimed. [1] For more information, see the Linux kernel documentation."

After you finished this step the config file should look something to what is shown below.

vm.swappiness = Number
vm.vfs_cache_pressure = Number

Step 7. Suspend and Hibernation

  • Suspend is complicated to say the least but if you get it working correctly it will be worth it. For the most part suspend will work out of the box and you'll most likely be fine with it but if you want to go in depth most laptops will use 2 types or both suspend modes (not at the same time). Most older laptops will use something called "S3 sleep" this will suspend everything you are doing on your laptop to RAM and deactivates everything but the RAM. Most newer laptops will use "s2idle" or "S0ix" or you probably know it as "Modern Standby" which is a more modern way of putting a laptop to sleep and works more like how when you turn off your phone, all the components go into a low power mode, the benifit of s2idle over S3 sleep is faster wake up times and usually less issues with suspend not working properly or wake up issues like the screen not turning on. Now in an ideal world s2idle will work perfectly and have the same or better battery drain than S3 sleep but some laptop manufactors don't implment it correctly into the BIOS the same goes for S3 sleep so here is what I recommend. Microsofts Explaination of S3 and Modern Standby

Update your laptop BIOS to the latest version.

If your laptop is having issues with sleep I've left troubleshooting links below.

If you don't like s2idle or have issues with it and just want S3 sleep use the "mem_sleep_default=deep" kernel parameter keep in mind most older laptops have this by default anyways you can check by typing "cat /sys/power/mem_sleep" in terminal, some modern laptops that support s2idle don't support S3 sleep or you have to enable it in BIOS like I explain below but if s2idle is working for you I recommend leaving it as is.

Go to your BIOS and look around for setting to enable S3 sleep or s2idle mode if it's not there google your laptop model and see if you have S3 sleep or s2idle if you don't find any information, (I don't know if this is offical use at your own risk). You can test if your laptop is capable of s2idle on AMD here or if you are on Intel they have an offical guide here.

  • I don't recommend hibernation on modern systems it's basically turning on your laptop all over again except your work is saved, suspend will drain less battery than turning it on again and for slow HDD laptops that is the worst it has to write to the HDD when entering hibernate then spin up the HDD when turning it back on, the battery drain is massive, but if you do leave your laptop off for long periods of time and want your work to be the way you left it then hibernation makes sense. For hibernation to work you need a swap (If you use ZRAM for your swap then hibernation will not work), I'll show you how to enable hibernation for a swap partition and leave the swap file Arch Wiki page, swap files on btrfs are also different I'll leave the Arch Wiki page.

  • People using LVM2 I added instructions for you below as it's slightly different.

To enable hibernation run sudo blkid and grab the swap partitions "UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

Next add "resume=UUID=xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" as a kernel parameter to your boot loader here is the Arch Wiki page for adding kernel parameters to yours.

For LVM2 users run sudo lsblk and check where the swap partition is located. Next add "resume=/dev/YourVolumeGroup/yourLogicalVolume" as a kernel parameter to your boot loader here is the Arch Wiki page for adding kernel parameters to yours.

Next configure the initramfs I'll copy and paste how to configure it from the Arch Wiki since it does a better job at explaining than I can.

run sudo nano /etc/mkinitcpio.conf

  • From the Arch Wiki "When an initramfs with the base hook is used, which is the default, the resume hook is required in /etc/mkinitcpio.conf. Whether by label or by UUID, the swap partition is referred to with a udev device node, so the resume hook must go after the udev hook. This example was made starting from the default hook configuration: HOOKS=(base udev autodetect keyboard modconf block filesystems resume fsck)"
  • When an initramfs with the systemd hook is used, a resume mechanism is already provided, and no further hooks need to be added.
  • Note: LVM users should add the resume hook after lvm2.

run sudo mkinitcpio -P and reboot.

  • If you do want suspend and hibernation there is hybrid-sleep but it is confusing because of the whole S3 sleep and s2idle situation and I'm not sure how to do it but if you are determined it is something that exists and you'll have to research yourself.

Here are the Arch Wiki pages to fix suspend or hibernate not working consistently or if your laptop wakes up from suspend instantly. Running echo XHC > /proc/acpi/wakeup fixed my suspend issues and I'll show how to make that a permanent solution later in this tutorial. In step 14


Step 8. SSD TRIM and HDD defragmentation

  • If you have an HDD ignore this HDD's don't need TRIM and if you are looking for defragmentation your file system should handle this automatically don't worry about it.

  • Most Linux distributions have fstrim enabled out of the box but if you encrypted your system you might still find this useful.

Check if fstrim is enabled by opening terminal and typing "systemctl status fstrim.timer" if it is enabled, great you are done if it's not enabled then type "systemctl enable --now fstrim.timer" if that doesn't work you probably have to install fstrim look up how to install it for your specific distribution.

If your system is encrypted then fstrim probably isn't working for you and you have to do a few more steps but keep in mind there is a security risk if you are super serious about that. [1]

Run "lsblk" in terminal and grab the "luks-000000-0000-0000-0000-0000000000" and the partition name right above it for example mine is "nvme0n1p3".

Type "sudo cryptsetup --allow-discards --persistent refresh luks-000000-0000-0000-0000-0000000000" and check if the "allow-discards" flag is enabled by typing "sudo cryptsetup luksDump /dev/nvme0n1p3 | grep Flags" don't forget to change the "/dev/nvme0n1p3" to your partition name.

Reboot and TRIM should be working now.


Step 9. Thermald (Intel Only)

  • Thermald prevents throttling, if you feel your laptop won't throttle you don't have to install this, I still recommend it as a "just in case".
  • From Arch Wiki "thermald is a Linux daemon used to prevent the overheating of Intel CPU's. This daemon monitors temperature and applies compensation using available cooling methods."
  • From Arch Wiki "By default, it monitors CPU temperature using available CPU digital temperature sensors and maintains CPU temperature under control, before hardware takes aggressive correction action. If there is a skin temperature sensor in thermal sysfs, then it tries to keep skin temperature under 45C."

run sudo pacman -S thermald

run sudo systemctl enable --now thermald


Step 10. CPU Power Management

  • The purpose of this CPU power saving guide isn't to just to reduce thermals it's to make the fans spin up less in turn saving battery and having a more comfortable experience. Keep in mind this can reduce performance.
  • If you want to just disable your CPU's turbo boost feature see step 14.

For Gnome and KDE run sudo pacman -S power-profiles-daemon then enable it by running sudo systemctl enable --now power-profiles-daemon if no settings appear for setting the CPU's power profile reboot your laptop.

From the Arch Wiki "power-profiles-daemon conflicts with other power management services such as TLP, tuned and system76-power. To use one of the aforementioned services instead without uninstalling power-profiles-daemon (due to its potential status as a dependency), disable the power-profiles-daemon service by masking it (see also [1], [2])."

I'm unsure how other desktop environments handle CPU power management so I'll leave an Arch Wiki page for desktop environments.

For desktop environments that don't support CPU power management I'll add how to set your CPU's power profile in step 14.


Step 11. GPU Power saving

  • For this whole step you would've needed to enable early KMS from step 3.
  • If you don't have an Intel GPU don't follow the steps I give here, instead use the Arch Wiki pages below for your brand of GPU.
  • All of these options might cause serious stability issues on many laptops especially older ones please enable and test the options one by one to see what works and what might not, if you're using X.org tuning some settings might fix these issues I'll leave the Arch Wiki page. There is also possible stability fixes in the Arch Wiki Intel page below

run sudo nano /etc/modprobe.d/i915.conf

add options i915 enable_guc=2

  • This option is automatically turned on for 12th gen+, for older GPUs please look Here and see which option you need to enable.

  • From the Arch Wiki "On supported Skylake and newer processors, some video features (e.g. CBR rate control on SKL low-power encoding mode) may require the use of an updated GPU firmware, [3] which is loaded by default only on Gen 11+ hardware since Linux 5.4. [4] Enabling GuC/HuC firmware loading can cause issues on some systems; disable it if you experience freezing (for example, after resuming from hibernation)."

add options i915 enable_fbc=1

  • From the Arch Wiki "Making use of Framebuffer compression (FBC) can reduce power consumption while reducing memory bandwidth needed for screen refreshes."

add options i915 enable_psr=1

  • "allows the display to go to lower standby states when system is idle but display is on as it eliminates display refresh request to DDR memory completely" [1]

add options i915 enable_rc6=1

  • This kernel parameter was disabled in kernel 4.16 if you have a decently updated system you shouldn't have to worry about this and ignore the rc6 step completely. You can check your kernel version by typing "uname -r" into your terminal. "RC6 is a technology which allows the GPU to go into a very low power consumption state when the GPU is idle (down to 0V)." [1]

After you finished these steps the config file should look something to what is shown below.

options i915 enable_rc6=1 (Only if on kernel 4.15 and lower.)
options i915 enable_psr=1
options i915 enable_guc=2
options i915 enable_fbc=1

Step 12. Audio Power saving

  • This can cause your audio to make crackling noises or your microphone to make popping noises.

run lspci -k and make a note of the audio kernel driver.

run sudo nano /etc/modprobe.d/audio_powersave.conf

add options snd_hda_intel power_save=1 or options snd_ac97_codec power_save=1 | Depending on the audio kernel driver.

  • From the Arch Wiki "By default, audio power saving is turned off by most drivers. It can be enabled by setting the power_save parameter; a time (in seconds) to go into idle mode. To idle the audio card after one second."

  • Arch Wiki page for audio power saving.


Step 13. Wireless Card Power saving

  • From the Arch Wiki "these power saving options are experimental and can cause an unstable system."

run lsmod | grep '^iwl.vm' and make a note of the result.

run sudo nano /etc/modprobe.d/iwlwifi.conf

add options iwlwifi power_save=1 add options iwlmvm power_scheme=3 or options iwldvm force_cam=0 | Depending on the lsmod result.

After you finished this step the config file should look something to what is shown below.

options iwlwifi power_save=1
options iwlmvm power_scheme=3 or options iwldvm force_cam=0

Step 14. Power Management Script

  • You can have an easier time by running sudo pacman -S powertop. I'll leave the Arch Wiki page.
  • What I did is make a script to apply the same optimizations PowerTop does but I added more that PowerTop doesn't.
  • DO NOT BLINDLY COPY AND PASTE THIS, READ THE INSTRUCTIONS.

run sudo nano /usr/bin/Laptop-Optimizations then see what you need from the lines below (yes you do need the "#!/bin/sh" part) below and please keep in mind these lines below are for my laptop specifically so you'll need to edit it to make it specific for your laptop, which shouldn't hard and if you don't need to enable some stuff in this script like "echo XHC > /proc/acpi/wakeup" don't. Not all laptops are the same and you should check what you need to and don't need to enable.

#!/bin/sh
echo XHC > /proc/acpi/wakeup

echo enabled | tee /sys/bus/usb/devices/{1-7,1-8,usb1,usb2}/power/wakeup (I've been having issues with suspend and this was the culprit use at your own risk).

echo auto > /sys/block/sda/device/power/control 

echo auto > /sys/bus/usb/devices/1-8/power/control

echo powersave > /sys/module/pcie_aspm/parameters/policy

echo auto | tee /sys/bus/i2c/devices/{i2c-0,i2c-1,i2c-2}/device/power/control

echo auto | tee /sys/bus/pci/devices/{0000:00:00.0,0000:00:1f.0,0000:01:00.0,0000:00:13.0,0000:02:00.0,0000:00:17.0}/power/control (Leave this at the bottom if the script, it caused me PCIe wakeup issues when it was at the top).

Save and exit.

  • If your desktop environment supports CPU power management you can skip this part and move on to the chmod command below, only do this part if your desktop environment doesn't support CPU power management, keep in mind this can reduce performance. This part is going to be for the intel_pstate driver only and my CPU specifically, I'll link the Arch Wiki page for other drivers and CPU's so you can edit this script for your CPU and driver.

run cat /sys/devices/system/cpu/cpufreq/{policy0,policy1,policy2,policy3}/scaling_available_governors && cat /sys/devices/system/cpu/cpufreq/{policy0,policy1,policy2,policy3}/energy_performance_available_preferences and make a note of the results. (Policy numbers will be relevant to how many threads your CPU has).

Add the lines you need into the #!/bin/sh script above, If you notice your laptop is slow or stuttering after this put the power profile up till it's not.

echo "your choice here" | tee /sys/devices/system/cpu/cpufreq/{policy0,policy1,policy2,policy3}/scaling_governor

echo "your choice here" | tee /sys/devices/system/cpu/cpufreq/{policy0,policy1,policy2,policy3}/energy_performance_preference

echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo | (This disables the turbo boost feature)

After you finished making your script run sudo chmod +x /usr/bin/Laptop-Optimizations

Next make a systemd service that runs the script on boot so it's permanent, run sudo nano /etc/systemd/system/Laptop-Optimizations.service then copy and paste this in.

[Unit]
Description=Enables Laptop Optimizations

[Service]
Type=oneshot
ExecStart=/usr/bin/Laptop-Optimizations

[Install]
WantedBy=sysinit.target

run sudo systemctl enable --now Laptop-Optimizations.service && sudo systemctl status Laptop-Optimizations.service

(For SATA drives only). run cat /sys/class/scsi_host/host/link_power_management_policy* if the result isn't "med_power_with_dipm" here is the Arch Wiki page to changing it. (You probably can edit it into the script how its shown below).

From the Arch Wiki "It will become a default setting for Intel based laptops in Linux 4.16 [8]."

echo med_power_with_dipm > /sys/class/scsi_host/host*/link_power_management_policy*


Step 16. Improving performance

  • See the Arch Wiki pages below, I won't write any guide since this is device specific.

Improving Performance

If you have an SSD the Arch Wiki page.


Step 17. Reboot your laptop, look below for anything you might need, it can improve your laptop even further, I tried to include just about everything someone might need.

If you have NVMe storage.

Dynamic GPU Switching. | For laptops with dual GPU's.

NVIDIA Optimus | For laptops with dual GPU's.

PRIME | For laptops with dual GPU's.

Bumblebee | For laptops with dual GPU's. Arch Wiki "Bumblebee has significant performance issues."

Nvidia-xrun | For laptops with dual GPU's.

If you use an External GPU.

Power Management | This page has a lot this guide did, but I excluded some things.

Laptop | For specific laptop models or stuff like finger print scanners.

Laptop Mode | For HDD Laptops.

X.org | X.org does have options you can configure for your laptop, if you use X.org check this out.

OpenGL | Make sure you're using iris drivers on gen 8+ Intel GPU's.

Vulkan | Install this.

GPGPU/OpenCL | Caused instability try if you want to.

Fstab atime Options | Can reduce SSD writes and improve performance, google "your filesystem Arch Wiki" and an article should appear for your filesystem from there you can optimize it.

Tablet PC | For tablet laptops there is some useful features this can enable like sensors for device rotation.

iio-sensor-proxy | If your laptop has sensors like ambient light ones for auto brightness you'll want to install this package.

HiDPI | For HiDPI screens especially on X.org.

Touchscreen | If you have touch screen issues.

Touchpad Synaptics | If you have touch pad issues.

Security | It's a laptop so?

Variable Refresh Rate | Can improve battery life.

Hard Disk Shock Protection | From the Arch Wiki "There are several laptops from different vendors featuring shock protection capabilities. As manufacturers have refused to support open source development of the required software components so far, Linux support for shock protection varies considerably between different hardware implementations."

Audio Mute LED | If you have a mute LED and wish to enable it. (options snd-hda-intel model=mute-led-gpio fixed it for me on the 13-4103dx).

NTP | This can be useful for a laptop especially if you travel a lot with it.

Mobile broadband modem | If your device has a SIM card slot and you wish to use mobile data on the go.

GPS | Some laptops support GPS if you wish to enable it.

Device Geo Location Tracking | Once you enable GPS you can use GPS tracking, if you don't have GPS prey let's you track your device using other methods.

DSDT | Make sure your DSDT table is actually working as it can cause ACPI event issues. (MESSING WITH THIS CAN CAUSE PERMANENT DAMAGE TO YOUR DEVICE. This might possibly solve issues like your fans not working or your screen brightness not working and other power management issues).

Linux On Mac Github page | Apple laptop users will find this very useful.

If your MacBook has issues waking from sleep have a look at this

@macvenez
Copy link

macvenez commented Sep 8, 2023

Thanks for this guide, helped me a lot!

I read that enable_rc6=1 option has been disabled on newer kernels as it was creating issues.
I checked with dmesg and in fact it was spitting out i915: unknown parameter 'enable_rc6' ignored . Maybe consider removing this from the guide (it should not make any difference btw as it will just skip the option).

@LarryIsBetter
Copy link
Author

Thanks for this guide, helped me a lot!

I read that enable_rc6=1 option has been disabled on newer kernels as it was creating issues. I checked with dmesg and in fact it was spitting out i915: unknown parameter 'enable_rc6' ignored . Maybe consider removing this from the guide (it should not make any difference btw as it will just skip the option).

Hello thank you for noticing this I've change the guide accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment