7

手动为我的4G内存 lede软路由设置swap(虚拟内存)

 2 years ago
source link: https://hellodk.cn/post/18
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

手动为我的4G内存 lede软路由设置swap(虚拟内存)

手动为我的lede软路由设置swap(虚拟内存)。

1、创建用于交换分区的文件

dd if=/dev/zero of=/mnt/sda1/swapfile bs=block_size count=number_of_block

block_sizenumber_of_block大小可以自定义,如:bs=1M count=1024,那么就会创建1024个bs=1M的区块(文件大小1024M)

比如我设置了一个4GB的swapfile,

dd if=/dev/zero of=/mnt/sda1/swapfile bs=1M count=4096

2、格式化交换分区文件

mkswap /mnt/sda1/swapfile

3、立即启用交换分区文件

swapon /mnt/sda1/swapfile

如果在/etc/rc.local中有swapoff -a,需要修改为swapon -a

4、设置开机时自启用swap分区
需要修改文件/etc/fstab中的swap行,在文件末添

/mnt/sda1/swapfile swap swap defaults 0 0

5、修改vm.swappiness
修改文件/etc/sysctl.confvm.swappiness = 0,我的服务器默认设置为0。 改值0~100,100时,则告诉内核疯狂的将数据移出物理内存在swap缓存中。一般设为60以下。

reboot重启生效。

总结:
虽然开启swap分区会导致硬盘IO性能下降,但对于小内存的服务器还是需要的。


end.

标签: Linux, 路由器

本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK