Home  »  ArticlesGuidesHow ToTechnologyTools   »   Boosting Performance: Adding Swap Space on Ubuntu 22.04

Boosting Performance: Adding Swap Space on Ubuntu 22.04

Is your Ubuntu 22.04 system running low on memory? Adding swap space can alleviate memory constraints and enhance performance. In this tutorial, we’ll guide you through the process of adding swap space to your Ubuntu 22.04 system, ensuring smoother operation and improved resource management.

Step 1: Check Current Swap Usage

Before adding swap space, it’s essential to check the current usage of swap on your system. You can use the free command to display information about swap space:

$ free -h

This command will show you the total swap space available and how much is currently in use.

Step 2: Create a Swap File

To create a swap file, you can use the dd command to allocate space for the file:

$ sudo fallocate -l 2G /swapfile

This command creates a 2GB swap file. Adjust the size as needed based on your system requirements.

Step 3: Set Permissions and Make the File Usable as Swap

After creating the swap file, you need to set appropriate permissions and make it usable as swap:

$ sudo chmod 600 /swapfile
$ sudo mkswap /swapfile

Step 4: Enable the Swap File

Once the swap file is created and configured, you can enable it using the swapon command:

$ sudo swapon /swapfile

Step 5: Make the Swap File Permanent

To ensure that the swap file is activated automatically at boot time, you need to add an entry for it in the /etc/fstab file:

echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Step 6: Verify Swap Space

Finally, verify that the swap space has been successfully added to your system by checking the output of the free command again:

$ free -h


By following these steps, you can easily add swap space to your Ubuntu 22.04 system, improving performance and ensuring smooth operation even under heavy memory load. Whether you’re dealing with resource-intensive tasks or simply looking to optimize system performance, adding swap space is a valuable technique for enhancing your Ubuntu experience.

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.

Available under:
Articles, Guides, How To, Technology, Tools