Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A simple guide for optimizing linux 🐧 in detail

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
NotificationsYou must be signed in to change notification settings

sn99/Optimizing-linux

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 

Repository files navigation

I am writing this guide to save my progress and let others contribute to increasing linux performance even further;afterall, many are better than one. You can use all of them or just a few of them.Read a topic fully before starting.

I am currently onNobara, so some steps may vary from distro to distro.

NOTE: This guide is not for beginners who are new to Linux but a few of them can be used safely by them.

Index


Compiling your kernel

By now, everyone agrees that compiling your kernel is one of the best options to get the fastest possible speed.You might want to googleHow to make custom kernel in <distro> to get the packages required to compile the kernel.

  1. Download thelatest kernel or whatever you like. Extract it; I am going to assume ageneric name from now onlinux-x.x.x.

  2. The next step is finding theconfig file. Most of the time, you can run:

    cp -v /boot/config-$(uname -r) .config

    From insidelinux-x.x.x, which should give an output like:

    '/boot/config-y.y.y-generic' ->'.config'

    if it fails, you can find config in/proc/config.gz or simple runmake listnewconfig ORmake oldconfig(itusually starts a long process; try finding your config in your distro source code too).

  3. EditMakefile and changeEXTRAVERSION to add something. For example, "EXTRAVERSION = <yourname>".

  4. (You might want to see the next subtopic before doing this) Now runmake xconfig. Now a lot of optimizations arepossibleHere, many dead codes and modules can be removed and enabled. Let's go the safe road for now.

    • Now, one of the best things you can do is no longer build for a generic kernel. Select
      - Processor type and features- Processor family        -[x] Core2/newer Xeon
      It should have beenGeneric-x86-64 by default.
    • There is a lot of other stuff you can do too, but you will have to read them and see which suitsyou best. A simple way might be to just copyclear linux config, butit might disable certain features (see nextApplying patches).
  5. Now, you might want to run:

    dmesg --level=errdmesg --level=warn

    To see if you can enable some extra flags for extra features. Forexample,psmouse serio1: elantech: The touchpad can support a better bus than the old PS/2 protocol. Make sure MOUSE_PS2_ELANTECH_SMBUS and MOUSE_ELAN_I2C_SMBUS are enabled to get a better touchpad experience.can be solved by enabling both of them.

  6. Finally, compiling the kernel:

    # sed -ri '/CONFIG_SYSTEM_TRUSTED_KEYS/s/=.+/=""/g' .configmake -j N CFLAGS='-march=native -O3 -flto -pipe' CXXFLAGS='-march=native -O3 -flto -pipe'make -j N CFLAGS='-march=native -O3 -flto -pipe' CXXFLAGS='-march=native -O3 -flto -pipe' modulessudo make modules_installsudo make install

    WhereN is the number ofcores you have, alternatively use$(getconf _NPROCESSORS_ONLN).

    If any steps fail, runmake clean and start again.

  7. Making it default in grub (I am using grub2, your process might vary):

    sudo grub2-mkconfig -o /boot/grub2/grub.cfgsudo grubby --set-default /boot/vmlinuz-x.x.x-x

    You can find yoursvmlinuz-x.x.x-x in/boot/

Now restart and rununame -r to see your kernel.

Applying patches

There are several patches that you can use to increase performance or to make life simpler.

There are a lot of patches available, and you will have to find those that suit you best. I will beusinggraysky2 kernel patch here. Download thewholerepo or just the file you need. In my case, I have GCC 10 andthe latest kernel, so I will beusingthis.

  1. Copy the desired patch file into the root of the extracted linux dictionary; same place as.config.

  2. patch -p1 < enable_additional_cpu_optimizations_for_gcc_v10.1+_kernel_v5.8+.patch

    You should see an output like this:

    patching file arch/x86/Kconfig.cpupatching file arch/x86/Makefilepatching file arch/x86/Makefile_32.cpupatching file arch/x86/include/asm/vermagic.h
  3. Now, you can start from step 4 in the previous setup and will see:

    -  Processor type and features- Processor family-[x] Native optimizations autodetected by GCC

There are other patches such asscheduling related that you can apply to. Again, tryfinding your patches that suits your system.

Removing your own compiled kernel

Try to keep the last working kernel, i.e., have a minimum of two kernels (the one you are using and the previous one).NOTE: Removing the currently running kernel (determined byuname -r) will render your systemnon-bootable.

  1. These entries need to be removed:

    /boot/vmlinuz-x.x.x-x/boot/initrd-x.x.x-x/boot/System-map-x.x.x-x/boot/config-x.x.x-x/lib/modules/x.x.x-x//var/lib/initramfs/x.x.x-x//boot/loader/entries/*x.x.x-x
  2. sudo grub2-mkconfig -o /boot/grub2/grub.cfg orsudo update-grub2

Btrfs filesystem optimizations

  1. sudo gedit /etc/fstab, change it to look something like this (this is on fedora, yours might vary):

    UUID=<do-not-change> /                       btrfs   subvol=root,x-systemd.device-timeout=0,ssd,noatime,space_cache,commit=120,compress=zstd,discard=async,lazytime 0 0UUID=<do-not-change> /boot                   ext4    defaults        1 2UUID=<do-not-change>          /boot/efi               vfat    umask=0077,shortname=winnt 0 2UUID=<do-not-change> /home                   btrfs   subvol=home,x-systemd.device-timeout=0,ssd,noatime,space_cache,commit=120,compress=zstd,discard=async,lazytime 0 0

    Optional :nobarrier

    nobarrier option is safe as long you didn't expect sudden powerloss happens or has battery-backed.

    On a device with a volatile battery-backed write-back cache, the nobarrier option will not lead to filesystem corruption as the pending blocks are supposed to make it to the permanent storage.man 5 btrfs

  2. sudo systemctl daemon-reload

  3. sudo systemctl enable fstrim.timer

Changing boot parameters

Important: I usually like disablingmitigations, but then again, I am onAMD based CPU and do nothaveMeltdownonlySpectre, I do not run an unknown script, and even if I have to, I use containers and firefox withnoscript andafew other security add-ons. Nonetheless, if you understand the security concerns, you can disable it and see asubstantialboost in performance.

  1. sudo grubby --args "mitigations=off nowatchdog processor.ignore_ppc=1 amdgpu.ppfeaturemask=0xffffffff ec_sys.write_support=1 split_lock_detect=off" --update-kernel=ALL

OR

  1. sudo gedit /etc/default/grub

  2. You will find a lineGRUB_CMDLINE_LINUX=" ... rhgb quiet change it to (... signifies other parameters):

    GRUB_CMDLINE_LINUX="... rhgb quiet mitigations=off nowatchdog processor.ignore_ppc=1 split_lock_detect=off"
  3. Also, editGRUB_TIMEOUT=5 toGRUB_TIMEOUT=1.

  4. sudo grub2-mkconfig -o /etc/grub2-efi.cfg

    OR

    sudo grub2-mkconfig -o /etc/grub2.cfg

After rebooting, you can runcat /proc/cmdline to see your boot options.

Improving boot time

Our last tweak kinda improved it, but let's try something more.

  1. Remove startup applications; I usegnome-tweaks for a GUI-like experience.

  2. Run the following to find what service is taking the longest:

    systemd-analyzesystemd-analyze blamesystemd-analyze critical-chain

    These might vary from system to system and distro to distro; in my case(fedora), I disableddnf-makecache.service.which took around32s. To do so:

    sudo systemctl disable NetworkManager-wait-online.servicesudo systemctl disable dnf-makecache.service sudo systemctl disable dnf-makecache.timersudo gsettingsset org.gnome.software download-updatesfalse

    You might want to google every service that you think about disabling and what it does; in my case, it just updatesdnfcache, which I usually like to do manually.

Changing swappiness

If you have 8GB or more ram, you might benefit from it; otherwise, leave it as it is.

  1. To see current swappiness, entercat /proc/sys/vm/swappiness; it should print60; we want to make it 10.

  2. sudo gedit /etc/sysctl.conf

  3. Entervm.swappiness=10 and reboot; now step 1 should print 10.

Changingscaling_governor toperformance

Do not change it toperformance on Ryzen based CPUs as itmight(I seem to get better performance on AC, but thenagain,performance does not seem to allow turbo boost in some cases) hurt their performance, usingondemand.orschedutil is better (more leaning towardsschedutil as soon as itgetsfixed).

  1. Runcat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor to see your current governor.

  2. echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

    This setting most likely will not persist during the next boot; I like to change it manually rather than making asystemd service (I am a laptop, and it gets hot). You might want to google how to make it persistent for your distroifyou like OR:

    echo'GOVERNOR="performance"'| sudo tee /etc/default/cpufrequtilssudo systemctl disable schedutil

    The default isschedutil; you can seeothershere.

Note: You can also change the default during the kernel compilation.

Improving graphic card performance

You can find overclocking tools specific to your GPU(s), but to make sure your graphics card isn’t being suppressed bythe OS (especially AMD):

  1. Checking whether it isauto:

    cat /sys/class/drm/card0/device/power_dpm_force_performance_levelcat /sys/class/drm/card1/device/power_dpm_force_performance_level
  2. Check the parameters of GPU by:

    sudo cat /sys/kernel/debug/dri/0/amdgpu_pm_infosudo cat /sys/kernel/debug/dri/1/amdgpu_pm_info
  3. Now set everything to high:

    sudo suecho high> /sys/class/drm/card0/device/power_dpm_force_performance_levelecho high> /sys/class/drm/card1/device/power_dpm_force_performance_level

    You can change them back toauto if your system overheats.

Some other tweaks

  • ArchWiki/Improving performance

  • DisablingCool'n'Quiet orspeedstep orPowerNow! from bios (will cause heat up on laptops, only enable it duringgaming)

  • Check other bios features, too; they vary from system to system but should have a significant boost in performance

  • UsingX instead ofWayland (may vary game to game)

  • UsingOpengl backend in games instead ofVulkun (may vary game to game)


Contributing

Feel free to open anissueorediting the README yourself.


License

Licensed under either of these:


[8]ページ先頭

©2009-2025 Movatter.jp