Вот несколько способов изменить значение подкачки в Linux, а также примеры кода:
Способ 1: использование команды sysctl
# Check the current swappiness value
sysctl vm.swappiness
# Set the swappiness value to 10
sudo sysctl vm.swappiness=10
# To make the change persistent across reboots, edit the /etc/sysctl.conf file and add the following line:
# vm.swappiness=10
Способ 2: использование команды echo
# Check the current swappiness value
cat /proc/sys/vm/swappiness
# Set the swappiness value to 10
sudo echo "10" > /proc/sys/vm/swappiness
# To make the change persistent across reboots, edit the /etc/sysctl.conf file and add the following line:
# vm.swappiness=10
Метод 3. Использование файловой системы sysfs
# Check the current swappiness value
cat /sys/kernel/mm/transparent_hugepage/khugepaged/defrag
# Set the swappiness value to 10
sudo sh -c 'echo 10 > /sys/kernel/mm/transparent_hugepage/khugepaged/defrag'
# To make the change persistent across reboots, edit the /etc/rc.local file and add the following line before the "exit 0" line:
# echo 10 > /sys/kernel/mm/transparent_hugepage/khugepaged/defrag
Метод 4. Использование системного менеджера systemd (дистрибутивы на основе systemd)
# Check the current swappiness value
sudo sysctl vm.swappiness
# Set the swappiness value to 10
sudo systemctl edit --full --force systemd-sysctl.service
# Add the following lines to the file and save it:
# [Service]
# ExecStart=
# ExecStart=/usr/lib/systemd/systemd-sysctl --prefix=/proc/sys/vm --values=vm.swappiness=10
# Reload the systemd daemon
sudo systemctl daemon-reload
sudo systemctl restart systemd-sysctl