Browsers are laggy in Ubuntu 20.04 LTS

Solution 1:

After talking with the OP in comments, I suspect this issue is related to swap.

Solutions that I recommend

  • First, increase the swap size to 8 GB or whatever you prefer

  • Decrease the swappiness value to 10

Why should you do this?

Well... I think the issue occurs due to swappiness

The OP's swappiness was way too much which lead to using that small 2 GB swap size. So after increasing the swap size we also decreased the swappiness value so that there should be no error in future, thus the problem was solved.

How to increase swap

What is swap?

Swap can be defined as Virtual memory. Virtual memory means ram only. But In virtual memory, Ram is used in a storage medium like Hard disk or SSD or On which your OS is installed. Whenever the Ram is full It will store the Ram files in the allocated space for swap. It is not as fast as a Normal ram but its speed depend on the speed of your storage medium

How to configure swappiness

What is swappiness?

The Linux kernel provides a tweakable setting that controls how often the swap file is used, called swappiness.

A swappiness setting of zero means that the disk will be avoided unless necessary (you run out of memory), while a swappiness setting of 100 means that programs will be swapped to the disk almost instantly.

The Ubuntu system comes with a default of 60, meaning that the swap file will be used fairly often if the memory usage is around half of my RAM. You can check your own system's swappiness value by running:

$ cat /proc/sys/vm/swappiness
60

Solution 2:

Following the steps in this answer, as suggested by Algnis, I used

sudo swapoff -a
sudo dd if=/dev/zero of=/swapfile bs=1G count=8 

to add 8G of swap space.

After that I did

sudo chmod 600 /swapfile 

so that only root users can read and write to the swap file.

Then I used

sudo mkswap /swapfile

to make the swap file usable.

I added this like to /etc/fstab

/swapfile none swap sw 0 0 

to add the new swap file.

Finally I ran

sudo sysctl vm.swappiness=10

as also suggested by Algnis.

I made sure to reboot my system to get it working and used free -h to make sure my new swap file was there and working.