Brief : Ubuntu running slow? You can improve the running speed by changing the CPU performance mode.

I was running Ubuntu 18.04 on a ASUS Vivobook 8th Gen Core i5 processor coupled with 8 GB of RAM. Everything went well for a year but recently I started noticing slowness. I had upgraded to Ubuntu 20.04.1 LTS and tried the usual apt update, upgrade and autoremove but nothing helped. I first believed the slowness was due to the upgrade, however it went so bad that I had to rule it out!

Here’s my system configuration.

Asus Specification - Ubuntu running slow

Ever clicked on Chrome and waited for more than a minute for it to launch? If yes, that is what I was going through.

Read : Lightweight Linux Distribution

In Ubuntu, there is a ondemand service running, which was setting my CPU to powersave option, thus limiting the CPU performance. The only way I could find was to change it to performance mode and then disable the ondemand service.

ambarish@thelinuxuser:/sys/devices/system/cpu/cpufreq/policy7$ systemctl list-units --all --type=service | grep ondemand 

ondemand.service loaded inactive dead Set the CPU Frequency Scaling governor

Here’s the CPU frequency policy set to powersave.

ambarish@thelinuxuser:/sys/devices/system/cpu/cpufreq/policy0$ cat /sys/devices/system/cpu/cpufreq/policy*/scaling_governor
powersave
powersave
powersave
powersave
powersave
powersave
powersave
powersave
ambarish@thelinuxuser:/sys/devices/system/cpu/cpufreq/policy0$ cd /sys/devices/system/cpu/cpufreq
ambarish@thelinuxuser:/sys/devices/system/cpu/cpufreq$ ls -lrt
total 0
drwxr-xr-x 2 root root 0 Nov 16 22:17 policy7
drwxr-xr-x 2 root root 0 Nov 16 22:17 policy6
drwxr-xr-x 2 root root 0 Nov 16 22:17 policy5
drwxr-xr-x 2 root root 0 Nov 16 22:17 policy4
drwxr-xr-x 2 root root 0 Nov 16 22:17 policy3
drwxr-xr-x 2 root root 0 Nov 16 22:17 policy2
drwxr-xr-x 2 root root 0 Nov 16 22:17 policy1
drwxr-xr-x 2 root root 0 Nov 16 22:17 policy0

Once you have the no. of policies, you will have to change the scaling_governor from powersave to performance.

ambarish@thelinuxuser:/sys/devices/system/cpu/cpufreq/policy7$ ls -lrt
total 0
-rw-r--r-- 1 root root 4096 Nov 16 22:24 scaling_governor
-rw-r--r-- 1 root root 4096 Nov 16 22:24 scaling_setspeed
-rw-r--r-- 1 root root 4096 Nov 16 22:24 scaling_min_freq
-rw-r--r-- 1 root root 4096 Nov 16 22:24 scaling_max_freq
-r--r--r-- 1 root root 4096 Nov 16 22:24 scaling_driver
-r--r--r-- 1 root root 4096 Nov 16 22:24 scaling_cur_freq
-r--r--r-- 1 root root 4096 Nov 16 22:24 scaling_available_governors
-r--r--r-- 1 root root 4096 Nov 16 22:24 related_cpus
-rw-r--r-- 1 root root 4096 Nov 16 22:24 energy_performance_preference
-r--r--r-- 1 root root 4096 Nov 16 22:24 energy_performance_available_preferences
-r--r--r-- 1 root root 4096 Nov 16 22:24 cpuinfo_transition_latency
-r--r--r-- 1 root root 4096 Nov 16 22:24 cpuinfo_min_freq
-r--r--r-- 1 root root 4096 Nov 16 22:24 cpuinfo_max_freq
-r--r--r-- 1 root root 4096 Nov 16 22:24 base_frequency
-r--r--r-- 1 root root 4096 Nov 16 22:24 affected_cpus

Lets change it back to performance mode for each CPU.

echo performance | sudo tee /sys/devices/system/cpu/cpufreq/policy0/scaling_governor
echo performance | sudo tee /sys/devices/system/cpu/cpufreq/policy1/scaling_governor
echo performance | sudo tee /sys/devices/system/cpu/cpufreq/policy2/scaling_governor
echo performance | sudo tee /sys/devices/system/cpu/cpufreq/policy3/scaling_governor
echo performance | sudo tee /sys/devices/system/cpu/cpufreq/policy4/scaling_governor
echo performance | sudo tee /sys/devices/system/cpu/cpufreq/policy5/scaling_governor
echo performance | sudo tee /sys/devices/system/cpu/cpufreq/policy6/scaling_governor
echo performance | sudo tee /sys/devices/system/cpu/cpufreq/policy7/scaling_governor

These settings revert back once you restart your system. Only option was to disable it completely so that my system runs on performance mode and does not slow down! You can use below terminal commands to disable it completely.

ambarish@thelinuxuser:/sys/devices/system/cpu/cpufreq/policy7$ sudo systemctl disable ondemand
[sudo] password for ambarish:
Removed /etc/systemd/system/multi-user.target.wants/ondemand.service.

Wrapping up

There’s could be tens of reasons for your Ubuntu system slowness. A faulty hardware, a misbehaving application eating up your RAM, or a heavy desktop environment can be some of them. I didn’t know Ubuntu limiting the system performance on it’s own.

I could see considerable changes once the CPU performance was updated to Performance mode. If your Ubuntu is running slow, fire up a terminal and rule out this.