简体中文
English
简体中文
日本語

Linux & Edge AI

虚拟内存调整

  1. 创建 swap 文件。
fallocate -l 4G /swapfile
  1. 设置权限并初始化 swap 分区头。
chmod 600 /swapfile
mkswap /swapfile
  1. 启用 swap 并验证状态。
swapon /swapfile
swapon --show
free -h
  1. 创建 systemd 服务实现自动挂载。
tee /etc/systemd/system/enable-swapfile.service >/dev/null <<'EOF'
[Unit]
Description=Enable swapfile via swapon
After=local-fs.target
Requires=local-fs.target

[Service]
Type=oneshot
ExecStart=/sbin/swapon /swapfile
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
EOF
  1. 设置开机自启。
systemctl daemon-reload
systemctl enable enable-swapfile.service
Page Tools
PDF
On This Page