Are you dealing with low RAM on your Ubuntu system? This is a common issue on systems required more memory to running applications smoothly. This can be resolved by adding more memory, but that involves additional costs. If you don’t want to spend extra money, you can easily create a swap file and add it to your system to avoid low memory problems. If you are facing issue first time you can also try clearing the cached memory.
A swap file in Linux is the space allocated on disk utilized by system on low RAM. When RAM fills up, inactive data gets moved to this file on your disk, freeing up RAM for important processes. It’s like using extra space on your desk when your main workspace gets cluttered.
The Swap space helps your system for:
Before adding a new swap file, it’s good practice to check whether your system already has some swap configured. Linux offers a few tools to see the swap details. Try swapon command for active swap details, or free to see total and used swap space
sudo swapon --show
The command will return nothing in case of no swap added to system.
sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon --show
This command should now show your newly created swap file.
You have already enabled swap memory on your system. However, you also need to make sure that the swap file turns on automatically when your system starts. To do this, add it to the system’s /etc/fstab file.
sudo nano /etc/fstab
/swapfile none swap sw 0 0
The swappiness parameter controls how often your system uses swap space. You can adjust it to tune your system’s performance with respect to RAM and swap usage.
cat /proc/sys/vm/swappiness
sudo sysctl vm.swappiness=20
vm.swappiness=20
to /etc/sysctl.conf
.You’ve successfully added and configured a swap file on your Ubuntu 24.04 system. This addition should help in managing your system’s resources more effectively, especially under heavy load. Remember, while swap can help in managing memory pressure, it’s not a substitute for adding more physical RAM when consistently facing performance issues.
The post Adding a Swap File to Ubuntu 24.04: A Complete Tutorial appeared first on TecAdmin.
Canonical’s Kubernetes LTS (Long Term Support) will support FedRAMP compliance and receive at least 12…
Welcome to the Ubuntu Weekly Newsletter, Issue 878 for the week of February 2 –…
At Canonical, we firmly believe that delivering an outstanding, customer-centric support experience is impossible without…
I want to share how to install osTicket v1.14 for Ubuntu 20.04 server. osTicket written…
Now I want to share how to install WordPress on ubuntu 20.04 server. WordPress is…
Now I want to share the DNS server installation process on your Ubuntu 20.04 server.…