Ubuntu 20.04 LTS complete system freeze when watching YouTube videos

Solution 1:

Your /swapfile is way too small, and your vm.swappiness is totally wrong.

Let's increase your /swapfile to 4G, and set vm.swappiness to a more appropriate value.

/swapfile

Note: Incorrect use of the rm and dd commands can cause data loss. Suggest copy/paste.

In the terminal...

sudo swapoff -a           # turn off swap
sudo rm -i /swapfile      # remove old /swapfile

sudo dd if=/dev/zero of=/swapfile bs=1M count=4096

sudo chmod 600 /swapfile  # set proper file protections
sudo mkswap /swapfile     # init /swapfile
sudo swapon /swapfile     # turn on swap
free -h                   # confirm 8G RAM and 4G swap

Edit /etc/fstab, using sudo -H gedit /etc/fstab or sudo pico /etc/fstab.

Confirm this /swapfile line in /etc/fstab... and confirm no other “swap” lines... use SPACES in this line... confirm NO TABS...

/swapfile  none  swap  sw  0  0

reboot                    # reboot and verify operation

vm.swappiness

Edit /etc/sysctl.conf

sudo -H gedit /etc/sysctl.conf

Find the line that has vm.swappiness=10 and set it =60.

Save the file and quit gedit.

sudo sysctl -p

Update #1:

BIOS

You have BIOS version BGCN33WW. A newer BIOS, version BGCN34WW, is available here or here. Although I don't believe that it'll fix your problem, it's always a good idea to keep current with BIOS updates for security fixes.

NVIDIA

You have Nvidia driver 460.91.03. Version 470.57 is available here. This tested driver should also be installable in Software & Updates app. Because the problem is recreatable when using the Intel GPU, I don't suspect that this will fix the problem either, but again, it's always good to stay current.

MEMTEST

Because symptoms improved when we changed the /swapfile and vm.swappiness, we need to check your memory.

Go to https://www.memtest86.com/ and download/run their free memtest to test your memory. Get at least one complete pass of all the 4/4 tests to confirm good memory. This may take many hours to complete.

SWAP

I just looked at the top and free -h outputs again, and your /swapfile appears to not be active. Did you confirm that the swap line in /etc/fstab has no tabs in it?

Curious... examples of free -h before and after the /swapfile change show zero swap usage...

              total        used        free      shared  buff/cache   available
Mem:          7,7Gi       1,2Gi       5,5Gi        29Mi       964Mi       6,2Gi
Swap:         472Mi          0B       472Mi

and

              total        used        free      shared  buff/cache   available
Mem:          7,7Gi       1,2Gi       5,3Gi       157Mi       1,1Gi       6,0Gi
Swap:         4,0Gi          0B       4,0Gi

Also, the top command, when looked at when the computer was frozen, also shows zero swap usage.