Reference: https://askubuntu.com/questions/1075505/how-do-i-increase-swapfile-in-ubuntu-18-04
sudo swapon --show
sudo swapoff -a
sudo rm /swapfile
# There're a lot of guides use `sudo fallocate -l 1G /swapfile` command, but there's an issue with it:
# The problem with fallocate(1) is that it uses filesystem ioctls to make the allocation fast and effective,
# the disadvantage is that it does not physically allocate the space but swapon(2) syscall requires a real space.
# Reference : https://bugzilla.redhat.com/show_bug.cgi?id=1129205
# We'll use dd command instead
# if = input file
# of = output file
# bs = block size
# count = multiplier of blocks
sudo dd if=/dev/zero of=/swapfile bs=4M count=4096
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon --show
# Backup the /etc/fstab file first
sudo cp /etc/fstab /etc/fstab.bak
# Add new swap information to /etc/fstab
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab