Improving Ubuntu Memory Management: Slow Computer (Weeks After Installation)
If you have installed Ubuntu a few weeks back and have been facing issues with your computer freezing or slowing down, it might be due to poor memory management. This article discusses some ways to improve your Ubuntu memory management, which will help you run Android Studio, Chrome tabs, and other applications smoothly.
Identifying Memory Management Issues in Ubuntu
Before we dive into the solutions, it is essential to identify the root cause of the issue. You can check the memory usage on your Ubuntu system by running the command free -h on the terminal.
free -h
Mem: 1.9Gi 1.7Gi 73Mi 1.6Gi 48Mi
Swap: 1.9Gi 316Mi 1.6Gi
The above output displays the total amount of memory (both physical and swap), the amount of memory in use, and the amount of free memory. If the amount of free memory is significantly low, it might be the cause of your computer freezing and slowing down.
Increasing Swap Memory
Swap memory is the memory used by the Linux kernel as virtual memory. It is helpful when the system does not have enough physical memory for the programs running on it. You can increase the swap memory by following the steps below:
- Find out the current swap memory by running the command
sudo swapon --showon the terminal. - Create a new swap file by running the command
sudo fallocate -l 4G /swapfile. Replace 4G with the amount of swap memory you want to allocate. - Set up the swap memory by running the command
sudo mkswap /swapfile. - Enable the swap memory by running the command
sudo swapon /swapfile. - Make the swap file permanent by editing the
/etc/fstabfile by adding the following line:/swapfile swap swap defaults 0 0
Lowering the Swappiness Value
The swappiness value determines when the Linux kernel should start using the swap memory. By default, the swappiness value is set to 60, which means that the kernel will start using the swap memory when 40% of the physical memory is in use. You can lower this value to prevent the kernel from swapping too early.
To lower the swappiness value, run the following command on the terminal:
sudo sysctl vm.swappiness=10
To make this change permanent, edit the /etc/sysctl.conf file and add the following line:
vm.swappiness=10
Closing Unused Applications
Leaving unused applications running in the background can take up a significant amount of memory. Make it a habit to close the applications you no longer need to prevent the system from slowing down.
Using a Lightweight Desktop Environment
The Ubuntu standard installation comes with the GNOME desktop environment, which can be resource-intensive. You can switch to a lightweight desktop environment such as XFCE, LXDE, or LXQt to save some memory.
These were some methods to improve the memory management on your Ubuntu system. You can try these out and see which one works best for you. If you are still facing issues, you can refer to the following resources for more information: