Ubuntu – Ubuntu 18.04 freezes randomly after RAM and SSD upgrade

18.04freezeramssd

I previously had an 8GB of RAM and 1TB of hard disk on my ASUS VivoBook R542UQ-DM153. I've added a 250GB WD Blue SSD and an 8GB of RAM. Total RAM now is 16GB. I've also made a fresh installation of Ubuntu on SSD. Now every time there is somewhat like heavy use the system freezes and I am left with no other option but to hard shutdown. Please help how can I fix that.

$ sudo dmidecode --type memory
# dmidecode 3.1
Getting SMBIOS data from sysfs.
SMBIOS 3.0.0 present.

Handle 0x0008, DMI type 16, 23 bytes
Physical Memory Array
    Location: System Board Or Motherboard
    Use: System Memory
    Error Correction Type: None
    Maximum Capacity: 64 GB
    Error Information Handle: Not Provided
    Number Of Devices: 4

Handle 0x0009, DMI type 17, 40 bytes
Memory Device
    Array Handle: 0x0008
    Error Information Handle: Not Provided
    Total Width: 64 bits
    Data Width: 64 bits
    Size: 8192 MB
    Form Factor: SODIMM
    Set: None
    Locator: ChannelA-DIMM0
    Bank Locator: BANK 0
    Type: DDR4
    Type Detail: Synchronous Unbuffered (Unregistered)
    Speed: 2400 MT/s
    Manufacturer: 859B
    Serial Number: E0F2D27D
    Asset Tag: 9876543210
    Part Number: CB8GS2400.C8D       
    Rank: 1
    Configured Clock Speed: 2133 MT/s
    Minimum Voltage: 1.2 V
    Maximum Voltage: 1.2 V
    Configured Voltage: 1.2 V

Handle 0x000A, DMI type 17, 40 bytes
Memory Device
    Array Handle: 0x0008
    Error Information Handle: Not Provided
    Total Width: Unknown
    Data Width: Unknown
    Size: No Module Installed
    Form Factor: Unknown
    Set: None
    Locator: ChannelA-DIMM1
    Bank Locator: BANK 1
    Type: Unknown
    Type Detail: None
    Speed: Unknown
    Manufacturer: Not Specified
    Serial Number: Not Specified
    Asset Tag: Not Specified
    Part Number: Not Specified
    Rank: Unknown
    Configured Clock Speed: Unknown
    Minimum Voltage: Unknown
    Maximum Voltage: Unknown
    Configured Voltage: Unknown

Handle 0x000B, DMI type 17, 40 bytes
Memory Device
    Array Handle: 0x0008
    Error Information Handle: Not Provided
    Total Width: 64 bits
    Data Width: 64 bits
    Size: 8192 MB
    Form Factor: SODIMM
    Set: None
    Locator: ChannelB-DIMM0
    Bank Locator: BANK 2
    Type: DDR4
    Type Detail: Synchronous Unbuffered (Unregistered)
    Speed: 2400 MT/s
    Manufacturer: 04CB
    Serial Number: 01210200
    Asset Tag: 9876543210
    Part Number: AO1P24HC8T1-BSFS    
    Rank: 1
    Configured Clock Speed: 2133 MT/s
    Minimum Voltage: 1.2 V
    Maximum Voltage: 1.2 V
    Configured Voltage: 1.2 V

Handle 0x000C, DMI type 17, 40 bytes
Memory Device
    Array Handle: 0x0008
    Error Information Handle: Not Provided
    Total Width: Unknown
    Data Width: Unknown
    Size: No Module Installed
    Form Factor: Unknown
    Set: None
    Locator: ChannelB-DIMM1
    Bank Locator: BANK 3
    Type: Unknown
    Type Detail: None
    Speed: Unknown
    Manufacturer: Not Specified
    Serial Number: Not Specified
    Asset Tag: Not Specified
    Part Number: Not Specified
    Rank: Unknown
    Configured Clock Speed: Unknown
    Minimum Voltage: Unknown
    Maximum Voltage: Unknown
    Configured Voltage: Unknown

Best Answer

There is a good chance that your system is looking for free swap space that does not exist.

When this happens, the system will grind to a halt as the system constantly pages your storage device for swap space that is not there.

There are two things causing this to happen.

1 - Your swappiness is set too high. For a solid state drive with 16 GB of RAM, you don't need to set your swappiness to 60.

Run the following command to set your swappiness to 10:

echo 'vm.swappiness = 10' | sudo tee -a /etc/sysctl.conf

To change your swappiness in the future you can edit the file /etc/sysctl.conf or you can use sed. The following example will change swappiness from 10 to 20:

sudo sed -i 's/swappiness = 10/swappiness = 20/g' /etc/sysctl.conf

Run the following command to apply the changes:

sudo sysctl -p

You can play around with this setting. You may do better with setting swappiness to 20 or higher using a solid state drive as the system will be able to take advantage of cached RAM. Personally, I have about 5GB of RAM with a solid state drive and 10 works fine.

2 - You can also increase your swap space to free up more RAM. Right now, you have 16 GB of RAM which is a lot. However, you don't have much swap space. This can cause the system to slow down when RAM usage is too high.

Use the following commands to increase the size of your swapfile:

sudo swapoff -a
sudo dd if=/dev/zero of=/swapfile bs=1M count=8192
sudo mkswap /swapfile
sudo swapon /swapfile

this will set your swapfile to 8 GB. To set your swapfile to 16 GB you can increase count=8192 to count=16384. Use count=4096 reset the size back to 4 GB.

You will not need 16 GB of swap space for RAM unless you use hibernation. If you use hibernation, it is recommended you set your swap space the same size as your RAM. The recommended minimum for 16 GB of RAM on a system that does not use hibernation is 4 GB.

Also, when your swappiness is set to a lower number, the size of your swap file becomes less important.


EDIT

I just checked your laptop model and it says that you have Nvidia graphics. Run the following commands to install the Nvidia drivers:

sudo apt update
sudo ubuntu-drivers autoinstall 

Reboot to apply the changes.

Related Question