Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
  • News
  • Artificial Intelligence
  • Applications
  • Linux
No Result
View All Result
Cloudbooklet
No Result
View All Result
Home Google Cloud

How to Add SWAP Space in Ubuntu 20.04 – Google Cloud

by Cloudbooklet
3 years ago
in Google Cloud, Compute Engine
How To Add Swap Space In Ubuntu 20.04 - Google Cloud
ShareTweetSendShare
Readers like you help support Cloudbooklet. When you make a purchase using links on our site, we may earn an affiliate commission.

How to Add SWAP Space in Ubuntu 20.04 on Google Cloud. Swap space is a virtual memory extension of the system or servers real memory (RAM). If you have swap space configured your server will behave as it has additional memory than it actually have. This guide helps you to configure swap space on Ubuntu […]

ADVERTISEMENT

How to Add SWAP Space in Ubuntu 20.04 on Google Cloud. Swap space is a virtual memory extension of the system or servers real memory (RAM). If you have swap space configured your server will behave as it has additional memory than it actually have.

This guide helps you to configure swap space on Ubuntu 20.04.

This setup is tested on Google Cloud Compute Engine instance running Ubuntu 20.04 with 614 MB RAM. So, this setup will work on any cloud servers or any VPS or any dedicated servers.

ADVERTISEMENT

Prerequisites

  1. A running Compute Engine, see the Setting up Compute Engine Instance with Ubuntu 20.04.

Before Begin

You need to know how much RAM memory you have in your machine.

You might also like

How To Setup Ssh Keys On Ubuntu

How to Setup SSH Keys on Ubuntu 20.04

4 months ago
Draggan Ai Editing Tool Install And Use Draggan Photo Editor

DragGAN AI Editing Tool Install and Use DragGAN Photo Editor

4 months ago

The general rule to allocate how much swap space is necessary is as follows.

  • Systems with less than 2 GB RAM – twice the amount of RAM.
  • Systems with 2 to 8 GB RAM – the same size as the amount of RAM.
  • Systems with more than 8 GB RAM – at least 4 GB of Swap.

Check Swap Space

Check whether your Ubuntu server already has a swap space available. More often virtual machines don’t have a swap space enabled by default. Check swap space using the following command.

ADVERTISEMENT
sudo swapon --show

If you don’t get any output, then your server don’t have any swap space configured. So you can proceed to add swap memory.

01. Create a Swap File

In the current situation with 614 MB RAM we are going to create a swap space of 1GB.

ADVERTISEMENT

Create a swap file to add 1 GB (1G) space. You can also increase the amount of space you need.

sudo fallocate -l 1G /swapfile

02. Adjust Swap File Permissions

Now you have a swap file of correct size and can be enabled as swap space.

ADVERTISEMENT

Proceed by setting up correct permissions.

sudo chmod 600 /swapfile

03. Configure Swap Space

You can now mark the file as swap space with the mkswap command.

ADVERTISEMENT
sudo mkswap /swapfile

You will receive the output similar to this.

Output
Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes)
no label, UUID=f59595fb-754b-47ae-af6b-8dd6e98654d8

04. Enable Swap Space

Enable the swap space and allow the system to utilise the space.

sudo swapon /swapfile

Verify that the swap is available by typing:

sudo swapon --show
Output
NAME TYPE SIZE USED PRIO
/swapfile file 1024M 0B -2

You can check the output of the free utility again.

free -h
Output
total used free shared buff/cache available
Mem: 581M 275M 62M 103M 243M 110M
Swap: 1.0G 0B 1.0G

05. Make Swap as Permanent

Now swap space is only created for the current session. If you reboot the server the current changes will be gone. So you can make this setting permanent by adding the swap file to our /etc/fstab file.

sudo nano /etc/fstab

Add the following at the end of the file.

/swapfile swap swap defaults 0 0

Configure Swappiness Value

The swappiness parameter allow to configure how often your system swaps data out of RAM to the swap space.

This value will be between 0 to 100 in percentage. The values close to zero, the kernel will not swap data to the disk unless absolutely necessary. The higher the value that are closer to 100 will try to put more data into swap in an effort to keep more RAM space free.

So, telling the system not to rely on the swap much will generally make your system faster.

You can see the current swappiness value by typing:

cat /proc/sys/vm/swappiness
Output
60

Now set the value to 10 with the following command.

sudo sysctl vm.swappiness=10
Output
vm.swappiness = 10

You can make this value permanent by adding the line to your /etc/sysctl.conf file.

sudo nano /etc/sysctl.conf

At the bottom, add the following line.

vm.swappiness=10

Hit Ctrl+X followed by Y and Enter to save and close the file.

Removing Swap Space

To remove a swap space you need to swapoff the space, remove the entry from the /etc/fstab file and finally delete the swap file.

sudo swapoff -v /swapfile

Edit the /etc/fstab file and remove the swap file entry /swapfile swap swap defaults 0 0

Finally, delete the swap file.

sudo rm /swapfile

Get your Professional Google Cloud Architect certificate with this easy to learn course now.

Conclusion

Now you have learned how to create swap space and configure it and remove the swap space on your Ubuntu 20.04 server on Google Cloud.

Thanks for your time. If you face any problem or any feedback, please leave a comment below.

Tags: Google Cloud PlatformUbuntu 20.04
Share2Tweet1SendShare
Cloudbooklet

Cloudbooklet

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related Posts

Set Up Deep Learning With Nvidia, Cuda, Cudnn On Ubuntu

How to Set Up Deep Learning with Nvidia, CUDA, cuDNN on Ubuntu 22.04

7 months ago
How To Install Or Upgrade Php 8.2 On Ubuntu 22.04

How to Install or Upgrade PHP 8.2 on Ubuntu 22.04

9 months ago
How To Change Timezone On Ubuntu 22.04

How to Change Timezone on Ubuntu 22.04

1 year ago
How To Install Ansible On Ubuntu 22.04

How to Install Ansible on Ubuntu 22.04

1 year ago

Follow Us

Trending Articles

Ai Annotation Jobs

AI Annotation Jobs: Everything You Need to Know

September 18, 2023

AI Statistics and Trends: What You Need to Know in 2023

5 Best Laptop for Minecraft in 2023: Top Picks for All Budgets

Best 10 AI Comic Generator: Create Comic book in Seconds

Create High Quality AI Cover Song with Covers AI

How to Block YouTube Ads on Android TV in 2023 (6 Easy Methods)

Popular Articles

Install Waifu Diffusion

How to Install Waifu Diffusion – Step-by-Step Guide

August 31, 2023

10 Best AI Summarizer Tools in 2023: A Review and Comparison

18+ Best Free NSFW AI Generators of 2023

5 Free AI Soulmate Maker: Create Your Perfect Match

9 Best Bulk Email Service Providers of 2023

6 Best AI Cover Song Generators for Free Online

Subscribe Now

loader

Subscribe to our mailing list to receives daily updates!

Email Address*

Name

Cloudbooklet Logo

Welcome to our technology blog, where we explore the latest advancements in the field of artificial intelligence (AI) and how they are revolutionizing cloud computing. In this blog, we dive into the powerful capabilities of cloud platforms like Google Cloud Platform (GCP), Amazon Web Services (AWS), and Microsoft Azure, and how they are accelerating the adoption and deployment of AI solutions across various industries. Join us on this exciting journey as we explore the endless possibilities of AI and cloud computing.

  • About
  • Contact
  • Disclaimer
  • Privacy Policy

Cloudbooklet © 2023 All rights reserved.

No Result
View All Result
  • News
  • Artificial Intelligence
  • Applications
  • Linux

Cloudbooklet © 2023 All rights reserved.