mirror of
https://gitea.com/mcereda/oam.git
synced 2026-02-09 05:44:23 +00:00
1.5 KiB
1.5 KiB
Swap
TL;DR
# show the swap usage
swapon --show
free -h
# enable or disable a swap partition or file
sudo swapon /root/swapfile
sudo swapoff LABEL=swap
sudo swapoff /dev/sda2
# enable or disable *all* swap partition or file
sudo swapon -a
sudo swapoff --all
# chech what processes are swapping
# see the "si" (swap in) and "so" (swap out) columns
vmstat
vmstat --wide 1
Swappiness
# change the current value
sudo sysctl vm.swappiness=10
sudo sysctl -w vm/swappiness=5
# persistent configuration
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf
echo 'vm.swappiness = 5' | sudo tee -a /etc/sysctl.d/99-swappiness.conf
Swapfile
# add a swapfile
sudo fallocate -l 1G /swapfile # or sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile swap swap defaults 0 0' | sudo tee -a /etc/fstab
# remove a swapfile
sudo swapoff -v /swapfile
sudo sed -i.bak '/\/swapfile/d' /etc/fstab
sudo rm /swapfile