Swap交换内存

swap 有两种主要形式,swap文件 和 swap分区 使用 swapon -s 或者 swapon -show 查看当前已启用 swap swapoff xxxx 关闭swap 启用swap分区 提前创建好sda2为swap分区 1 2 3 4 5 6 mkswap /dev/sda2 swapon /dev/sda2 # 编辑fstab /dev/sda2 none swap defaults 0 0 创建swap文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 # 用三种方法创建都可以 dd if=/dev/zero of=/swapfile bs=1M count=2048 fallocate -l 2G /swapfile mkswap -U clear --size 2G --file /swapfile # 修改文件权限,避免其他用户误触 chmod 600 /swapfile # 格式化为swap文件 mkswap /swapfile # 启动swap文件 swapon /swapfile # 添加到fstab /swapfile none swap defaults 0 0 配置swappiness swappiness 数字越大表示越积极的把较少使用的匿名内存交换到swap ...

August 6, 2026 · 2 min · 224 words · Me