How to speed up your Linux laptop
Some of us are not willing to get a new machine every a couple of years, I personally think that getting new hardware should be done when is a real need. That is when our machine starts failing and is not reliable or because is too slow for the task. As software engineers, we need to spread the word in order to avoid good working laptops been thrown away, as electronic waste is a global problem that we all should try to mitigate.
Hardware Flaws
Meltdown and Spectre vulnerabilities in modern computers can leak passwords and sensitive data. Current Linux kernels have mitigations for these vulnerabilities that keep us more secure, but they come with a performance overhead.
We can disable processor bugs mitigations to gain some performance, and also minimize console output when booting in order to improve booting speed.
This will not give you a big gain, expect about 2% of performance gains, so if concerned about security don’t do it.
Edit /etc/default/grub file and change default settings for your kernel.
GRUB_CMDLINE_LINUX_DEFAULT=”quiet loglevel=3 noibrs noibpb nopti nospectre_v2 nospectre_v1 l1tf=off nospec_store_bypass_disable no_stf_barrier mds=off tsx=on tsx_async_abort=off mitigations=off”
Scaling Governor
Scaling governor is a software that controls the CPU frequency and we have a few algorithms to optimize scaling for battery time, for instance. By tweaking its configuration we can achieve greater performance, this will reduce battery time and probably will make your laptop hotter.
$ echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
Note that the above command won’t make a permanent change. After a reboot, it will be reset. There is a great article on how to make scaling governor configuration permanent.
Another thing one could do is execute the above command at /etc/rc.local but in my opinion, is a bit hacky.
Since with performance governor your machine will be hotter, it may trigger thermal throttling under heavy loads, especially for thinner laptops. A simple way to improve temperatures is undervolting.
Software Undervolting
Undervolting is a process through which voltage to computer processors and components is decreased to reduce energy consumption and heat produced by computing components.
There are many undervolting utilities out there. I personally use undervolt which is written in python and is very easy to use.
As advised on its GitHub repo, the following technique could potentially damage your machine, so do your research and proceed at your own risk.
Warning! This program is untested (apart from by myself) and it may damage your hardware! Use at your own risk.
After installing it with pip install; we can create a Systemd unit to run it on each boot. So we create the following file:
/etc/systemd/system/undervolt.service
With this content:
[Service]
Type=oneshot
ExecStart=/usr/local/bin/undervolt -v — core -60 — cache -60 — gpu -60 -t 85
My thermal trigger was 70°C originally, and this config bumps it up to 85°C which provides a lot of extra performance without raising the temperature too much.
For many low voltage intel mobile processors decreasing 70mV is perfectly normal and results in a stable configuration. I noticed that it wasn’t so stable on my i7–4600U so I used a 60mV decrease instead and now works rock solid while being cooler.
I use Vitals Gnome extension to measure and monitor all relevant system metrics, like CPU usage, load average, temperatures, fan speed, and more.
Comparing results
Benchmarking can be done with a simple benchmark tool such as glxgears. Make sure you disable VSync so you can see how many frames per second your machine is capable to render with your current configuration. To run this benchmarking just copy and paste the following command line in your terminal.
$ vblank_mode=0 glxgears
Feel free to choose another synthetic CPU benchmark that you see fit. Sysbench and Stress-ng are great examples, but there are much more available.
Boot times
We can improve our boot times significantly. I wrote an entire article some time ago that tackles that topic, so check it out if interested.
Conclusion
With these techniques and very little time, we can get the most of our laptop, achieving performance that newer models provide without spending a dime and learn something new in the process!