Ubuntu system expands swap space

In the Linux system, dividing a part of the hard disk space as the swap space can greatly improve the operating efficiency of the system. The total capacity of physical memory and swap is the size of virtual memory in the kernel, that is, when the physical memory is not enough, the swap space on the hard disk can be used as memory.

Generally speaking, the size of the swap space is usually set to twice the size of the physical memory, such as 4G of physical memory. If the hard disk capacity allows, set the size of the swap space to 8G. Generally, the swap space will be set when the Ubuntu system is installed . , but it can also be set after the system is installed, and the related methods are introduced below.

# 先关闭swap
cd /var
sudo swapoff /var/swap

# 重设swap大小 (1Mb * 4096 = 4GB),这一步会花较长的时间,耐心等待。
sudo dd if=/dev/zero of=swap bs=1M count=4096

# 格式化
sudo nkswap /var/swap

# 开启swap
sudo swapon /var/swap

# 设置开机启动,在/etc/fstab文件中添加如下的代码
/var/swap swap swap defaults 0 0

# 查看当前生效的swap
swapon -s

# 查看swap的使用情况 
free -m

Guess you like

Origin blog.csdn.net/m0_46259216/article/details/124108457
Recommended