Arch Linux Laptop Optimization Guide For Practical Use : archlinux
2022-2-28 22:26:37 Author: www.reddit.com(查看原文) 阅读量:1985 收藏

Everything I mention in this post will be taken from the Arch Wiki this guide is geared towards new Arch Linux users who want a practical laptop like they did on Windows or Mac OS. This guide can be applied to other distros not just Arch.

Everything I'll show is biased towards my personal laptop with an Intel CPU and GPU, I'll be leaving guides for AMD and NVIDIA devices where it's needed so people with that hardware aren't left out.

For laptops with dual GPU's if you want the most battery life and best thermals you'll want to switch to your iGPU for normal tasks, I left Arch Wiki guides for how to do that at the bottom of this post.

I won't be using any power saving packages in this guide, because I don't like them and feel I can achieve better results without them even though they do a lot of similar things you'll see here. (If you do have any power saving packages installed uninstall all of them if you plan on following this guide as they may cause conflicts)

I'll continue updating this guide if I find anything new or if new technologies come out to improve efficiency.

Also small rant at the bottom of my post and basically my hope for Linux laptop support in the future.

Step 1. Kernel and Drivers

When picking what kernel to use (Latest or LTS) the latest will mostly likely have better performance and battery especially on newer hardware, the LTS will have better stability and reliability.

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

Here is the Arch Wiki page to the Linux kernel.

Here is the Arch Wiki Guide for NVIDIA drivers.

Here is the Arch Wiki Guide for AMD drivers.

Here is the Arch Wiki Guide for Intel drivers.

Step 2. Enable Wayland

Wayland has been shown have slight power saving compared to X.org for KDE you'll want to run sudo pacman -S plasma-wayland-session (For NVIDIA it's different check the wiki) then select the session from your login screen, on Gnome it should be enabled by default. For other desktop environments I'll leave the Arch Wiki page.

Wayland is not a requirement for this guide I personally just found it much better to use.

For KDE Wayland on NVIDIA.

Proof Wayland can save power.

Here is the Arch Wiki guide to Wayland.

Step 3. Enable Early KMS

I'll show you how to enable early KMS for Intel GPU's I'll leave the wiki page for other GPU's below, you'll need early KMS for step 9, it can also fix hibernation issues for Intel GPU's.

From Arch Wiki > "KMS also enables newer technologies (such as DRI2) which will help reduce artifacts and increase 3D performance,even kernel space power-saving."

run sudo nano /etc/mkinitcpio.conf

MODULES=( ) >> MODULES=(i915) - then exit and save

run sudo mkinitcpio -P

run lsmod | grep intel_agp - if the module is not loaded reboot and continue to step 4, but if the module is loaded continue step 3 below.

run sudo nano /etc/mkinitcpio.conf

MODULES=(i915) >> MODULES=(intel_agp i915) - exit and save. This is 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 ay lead to troubles when resuming from hibernation (monitor gets no signal."

run sudo mkinitcpio -P

Now reboot the system.

Here is the Arch Wiki guide to early KMS for NVIDIA or AMD users, or if you just want to look into it further.

Step 4. Enabling Hardware Acceleration

Enabling hardware acceleration is important it'll use your laptops GPU for stuff like video decoding or encoding instead of your CPU, your laptop run cooler and faster while saving power this can resolve issues like videos stuttering and your laptop being hot while watching videos, I recommend looking into the Arch Wiki guide hardware acceleration for applications below after you've set this up. The guide shown below is for Intel GPU's I left the wiki guide for other brands below it should be similar to what is done here.

run lspci | grep VGA to see your GPU

For Intel GPU's 2014 and newer install sudo pacman -S intel-media-driver - From Arch Wiki. > "HD Graphics series starting from Broadwell (2014) and newer are supported by intel-media-driver."

For Intel GPU's 2013 and older install sudo pacman -S libva-intel-driver - From Arch Wiki > "GMA 4500 (2008) and newer GPUs, including HD Graphics up to Coffee Lake (2017) are supported by libva-intel-driver."

You'll also want to sudo pacman -S libvdpau-va-gl libva-utils vdpauinfo

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

run export LIBVA_DRIVER_NAME=i965 - If you install 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 which driver you installed.) Then add VDPAU_DRIVER=va_gl below save and exit.

Here is the Arch Wiki guide to hardware acceleration for NVIDIA and AMD users.

I recommend looking at this to enable hardware acceleration in applications.

Check if your GPU and hardware acceleration driver can decode VP9 if it can't install the h264ify browser extension otherwise you wont be able to watch stuff like YouTube videos with hardware video decoding keep in mind h264ify will disable resolutions above 1080p.

Step 5. Undervolting

(WARNING UNDERVOLTING CAN BRICK A DEVICE PERMANENTLY MAKING THE DEVICE COMPLETELY UNUSABLE I WONT BE RESPONSIBLE IF YOU DO BRICK YOUR DEVICE DO THIS AT YOUR OWN RISK)

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."

I'll be covering the Intel method to undervolt, I know there is a method to undervolt K10 and newer AMD CPUs which I'll leave a link to the wiki guide below. Do not use this guide to undervolt your AMD CPU.

run sudo pacman -S intel-undervolt

For kernel 5.9+ you need to add msr.allow_writes=on as a kernel parameter to your boot loader I'll leave the Arch Wiki guide on how to do that for your specific boot loader. After you added the parameter reboot your device.

After that you want to run sudo nano /etc/intel-undervolt.conf

Decrease your CPU mV by -10 like this.

undervolt 0 'CPU' -10

Save and exit then run sudo intel-undervolt apply && sudo intel-undervolt read

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

run mprime

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

Here is the Arch Wiki guide for undervolting.

Here is the Arch Wiki guide for undervolting on AMD.

Step 6. Hibernation Suspend and Swap

I recommend having a swapfile or swap partition having swap makes ram management for the kernel easier, if you're worried about SSD writes I'll show you how to reduce swappiness or turn it off completely so you can have swap for just hibernation.

For hibernation to work you will need a swapfile or swap partition I'll be showing you how to enable hibernation for a swap partition and leave the swapfile wiki guide below.

For people using LVM2 I left a separate guide below as it is slightly different.

Swapfiles on btrfs are also different I'll leave a wiki guide below.

Suspend should work out of the box, I'll be showing you how to fix it if it doesn't work like it should.

To enable hibernation you want to run cat /etc/fstab | grep swap and grab the "UUID=xxxxxxx-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 guide to find how to add kernel parameters to yours.

For LVM2 users you'll want to run 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 guide to find how to add 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 it than I can.

run sudo nano /etc/mkinitcpio.conf

From 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.

I'll show you how to decrease swappiness

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

add vm.swappiness = "Your number" - From 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." (I use 10, set between 0-60, 0 will disable swapping)

add vm.vfs_cache_pressure = "Your number" - From 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" (I use 50, set between 50-100)

Here are links to fix suspend or hibernate not working consistently or if your device wakes up from suspend instantly.

For me echo XHC > /proc/acpi/wakeup fixed my suspend issues and I'll show how to make that a permanent solution later in this tutorial. (See in step 12)

Here is an Arch Wiki guide for hibernation.

Here is an Arch Wiki guide for swapfile hibernation.

Here is an Arch Wiki guide to hibernating on a swapfile with btrfs.

Here is an Arch Wiki guide to hibernation into a thinly-provisioned LVM volume.

Here is an Arch Wiki guide to Hybrid-Sleep.

Step 7. Install Thermald

I said I won't use power saving packages but I recommend installing Thermald to prevent throttling, if you feel your device 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 CPUs. 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 HW 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

Boom pretty simple personally I haven't noticed a difference with Thermald on or off since what I do on my laptop usually keeps my CPU under 40C.

Here is an Arch Wiki guide to Thermald.

Step 8. 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 also reduce performance.

If you want to just disable your CPU's turbo boost feature see step 12.

For Gnome power management should automatically be enabled, the top right menu should have the options for it, but if it doesn't run sudo systemctl enable --now power-profiles-daemon and it should appear if it doesn't reboot the device.

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."

I am unsure of how KDE handles power management for the CPU I heard they are planning to add something similar to what Gnome has I'll leave an Arch Wiki guide to KDE power management.

I'm unsure how other desktop environments handle CPU power management so I'll leave an Arch Wiki guide to desktop environments for you to figure it out.

For desktop environments that don't support CPU power management or if you don't use a desktop environment I'll add a tutorial on how to set your CPU's power profile to the one you want in step 12.

Step 9. GPU Power saving

For this whole step you would've needed to enable early KMS from step 3.

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

add options i915 enable_guc=2 - From Arch Wiki > "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 Arch Wiki > "Making use of Framebuffer compression (FBC) can reduce power consumption while reducing memory bandwidth needed for screen refreshes | Framebuffer compression may be unreliable or unavailable on Intel GPU generations before Sandy Bridge."

Here is the Arch Wiki guide for Intel GPU's.

Here is the Arch Wiki page for NVIDIA GPU's.

Here is the Arch Wiki Page for AMD GPU's.

Step 10. 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

Here is the Arch Wiki guide for audio power saving.

Step 11. Wireless Cards Power saving

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

run lsmod | grep '^iwl.vm' and make a mental 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

Here is the Arch Wiki guide for wireless card power saving.

Step 12. Power Management Script or PowerTop

For this part you can have an easier time by running sudo pacman -S powertop and calling it a day I won't type out a guide on how to use it I'll just leave the Arch Wiki guide here.

What I did instead is make my own script to apply basically the same optimizations PowerTop does but I added more to it like "echo XHC > /proc/acpi/wakeup" from step 6.

DO NOT BLINDLY COPY AND PASTE THIS READ THE INSTRUCTIONS.

run sudo nano /usr/bin/Power_Management then see what you need from the lines (yes you do need the "#!/bin/sh" part) below and please keep in mind the lines below are for my laptop specifically so you'll need to edit it yourself to make it specific for your device which shouldn't be to hard, and if you don't need to enable some stuff in this script like "echo XHC > /proc/acpi/wakeup" or "echo enabled | tee /sys/bus/usb/devices/{1-7,1-8,usb1,usb2}/power/wakeup" Don't. Not all devices are the same and you should check what you need to and don't need to enable.

#!/bin/sh
echo XHC > /proc/acpi/wakeup - (for laptops suspend to work properly on some models)

echo enabled | tee /sys/bus/usb/devices/{1-7,1-8,usb1,usb2}/power/wakeup - (For laptops that are having USB wake up problems)

echo auto > /sys/block/sda/device/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 - (This enables PCI power management some PCI devices wont wake up after they slept so remove the ones that give you issues also leave this at the bottom of the script it caused me WiFi card issues when it was at the top of the script)

Exit and save.

If your desktop environment supports CPU power management you can skip this part and move on to the chmod command below this, only do this part if your desktop environment doesn't support CPU power management or if you don't use a desktop environment, otherwise skip past this part. Keep in mind this can also reduce performance. This part is going to be for the intel_pstate driver only and my CPU specifically, I'll link the Arch Wiki guide 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 and make note of the results.

run cat /sys/devices/system/cpu/cpufreq/{policy0,policy1,policy2,policy3}/energy_performance_available_preferences and make note of the results.

Add the lines you need into the #!/bin/sh script above, keep in mind again this is for my CPU and driver specifically find which CPU driver you have in the Arch Wiki link above and edit this for your CPU and driver specifically. If you notice your device 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/Power_Management

Next we'll make a systemd service that executes the script you made to run on boot so its permanent, run sudo nano /etc/systemd/system/Power_Management.service then copy and paste this in.

[Unit]
Description=Enables Laptop Optimizations

[Service]
Type=oneshot
ExecStart=/usr/bin/Power_Management

[Install]
WantedBy=sysinit.target

run sudo systemctl enable --now Power_Management.service && sudo systemctl status Power_Management.service

(For SATA drives only.) run cat /sys/class/scsi_host/host*/link_power_management_policy if the option is not "med_power_with_dipm" here is the Arch Wiki guide to changing it. (You can probably edit it into the script.)

Step 13. Arch Wiki improving performance

You'll want to follow these guides I won't include any tutorials since this is device specific.

https://wiki.archlinux.org/title/improving_performance

If you have an SSD follow this Arch Wiki guide.

Step 14. CPU microcode

From 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."

All users with an AMD or Intel CPU should install microcode for their CPU.

Here is an Arch Wiki guide on how to do it.

Step 15. Reboot the device and make sure everything works if it does you're finished with the guide enjoy an actual good Linux laptop experience.

If you fully followed this guide and had tools like TLP or PowerTop or whatever else installed I recommend uninstalling them since they might cause conflicts, you shouldn't need any power saving tools after this guide if you did everything correctly.

SOME HELPFUL LINKS FOR DEVICE SPECIFIC ISSUES PLEASE SEE WHAT YOU NEED I GUARANTEE YOU WILL NEED SOMETHING HERE.

https://wiki.archlinux.org/title/Solid_state_drive/NVMe (If you have NVMe storage)

https://wiki.archlinux.org/title/NVIDIA_Optimus (For laptops with dual GPU's)

https://wiki.archlinux.org/title/PRIME (For laptops with dual GPU's)

https://wiki.archlinux.org/title/Bumblebee (For laptops with dual GPU's)

https://wiki.archlinux.org/title/Nvidia-xrun (For laptops with dual GPU's)

https://wiki.archlinux.org/title/External_GPU (If your use an external GPU for gaming check this out)

https://wiki.archlinux.org/title/Power_management (This page has a lot of the stuff this guide already did, but I excluded some things like the watchdog timer and turning off Bluetooth permanently)

https://wiki.archlinux.org/title/laptop (Can include fixes for specific laptop models or stuff like finger print scanners)

https://wiki.archlinux.org/title/Power_management#Laptop_Mode (Mostly for HDD Laptops)

https://wiki.archlinux.org/title/firefox#Wayland

https://wiki.archlinux.org/title/chromium#Native_Wayland_support

https://wiki.archlinux.org/title/wayland

https://wiki.archlinux.org/title/xorg (X.org does have specific options you can configure for your device, if you use X.org make sure to check this out)

https://wiki.archlinux.org/title/FFmpeg#Intel_QuickSync_(QSV) (Hardware Accelerated Encoding for Intel GPU's)

https://wiki.archlinux.org/title/OpenGL (Make sure you're using iris drivers on gen 8+ Intel GPU's)

https://wiki.archlinux.org/title/Vulkan (You should probably install this if you haven't already)

https://wiki.archlinux.org/title/GPGPU (caused my system to be unstable try if you want to)

https://wiki.archlinux.org/title/fstab#atime_options (mount options that 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)

https://wiki.archlinux.org/title/Tablet_PC (This is for tablet laptops like mine there is some useful features this can enable like sensors for device rotation)

https://wiki.archlinux.org/title/HiDPI (This will help laptops with HiDPI screens especially on X.org)

https://wiki.archlinux.org/title/touchscreen (This might help you if you're having touch screen issues)

https://wiki.archlinux.org/title/Touchpad_Synaptics (Might help if you have touchpad issues)

https://wiki.archlinux.org/title/Security (It's a laptop so duh)

The goal of this guide is to help people actually have a usable laptop on Linux like they did on Windows or Mac OS, most guides or YouTube videos tell you to install some packages and it "fixes the problem" in reality it doesn't, so new Linux users end up combing a bunch of confusing power saving programs from different guides and videos into one big mess that bloats their system and it still doesn't fix their issue or makes their device slow or unusable with features like Bluetooth permanently disabled, obviously after that anyone will switch back to Windows or Mac OS thinking Linux sucks, what I hope this guide does is promote actual good Linux laptop tutorials with the proper information for them, instead of someone saying "install that tool and you'll be good" then average users looking through pages of google trying to find an answer to their issues when they just want to use their damn device normally.

If anyone needs proof of stability or reliability my laptop went in and out of hibernation and suspend during this period.


文章来源: https://www.reddit.com/r/archlinux/comments/rz6294/arch_linux_laptop_optimization_guide_for/
如有侵权请联系:admin#unsafe.sh