Add memory for your ubuntu (memory swap)

2017-06-03

Recently, the webmaster bought a server on Vultr and wanted to build something, but found that 512mb was not enough due to the budget. Fortunately, Vultr is ssd, so it is not too bad to use swap for memory expansion.

This article was migrated from My Own. The original link is https://wudew.com/posts/67

Swap is a file stored in the hard disk. When the memory is not enough, data will be exchanged in swap. When the budget is not enough, you can first enable swap to increase memory. However, it is still recommended that if the budget is enough, try to use real memory.

This article is tested to be applicable to ubuntu16.04 of Vultr. Since the technology is updated very quickly, please pay attention to the publication time of this article.

 #Switch to the root environment sudo su #Confirm swap status free -m #This command lists the remaining memory and swap
 #Or: sudo swapon -s #This command lists all swap files

 #Check disk space
 df -h #Create swap file sudo fallocate -l 2G /swapfile #This command will create a 2G swap file

 #Change permissions
 chmod 600 /swapfile #Convert files to swap mkswap /swapfile #Enable swap swapon /swapfile #Add self start
 echo  "/swapfile   none    swap    sw    0   0" >> /etc/fstab #Cancel and delete swap (not tested, for reference only)
 #Cancel self start vi /etc/fstab #Disable swap swapoff /swapfile #Delete swap
 rm -rf /swapfile

reference resources:

Maintenance of the website requires a certain amount of expense. If you agree with this article, please close the advertisement blocker and browse the advertisement. Thank you!
Loading

(∀) In other words, welcome to the small station of lookas!

This is the place where lookas records some things. From time to time, there may be some magical brain holes or unreliable ideas of lookas.

Anyway, let's have a look.