Linux

如何在 Linux 記憶體管理中配置 swappiness?

  • February 9, 2019

swappiness 參數控制核心將程序移出物理記憶體並移至交換磁碟的趨勢。什麼是預設設置以及如何配置它以提高整體性能

Linux 核心提供了一個可調整的設置來控制交換性

$ cat /proc/sys/vm/swappiness
60  

/etc/sysctl.conf以root身份打開。然後,將此行更改或添加到文件中:

vm.swappiness = 10

要臨時更改 swappiness 值,請嘗試以下命令:

$ echo 50 > /proc/sys/vm/swappiness

來自Swappiness,維基百科

您可以在虛擬文件中設置此值/proc/sys/vm/swappiness 提到的值將決定應如何使用交換空間,以下是其意圖的值。

vm.swappiness = 0   # Swap is disabled. In earlier versions, this meant that the kernel would swap only to avoid an out of memory condition, but in later versions this is achieved by setting to 1.
vm.swappiness = 1   # Kernel version 3.5 and over, as well as kernel version 2.6.32-303 and over: Minimum amount of swapping without disabling it entirely.
vm.swappiness = 10  # This value is sometimes recommended to improve performance when sufficient memory exists in a system, this value *10* could be considered for the performance being expected. 
vm.swappiness = 60  # The default value.
vm.swappiness = 100 # The kernel will swap aggressively.

雖然它實際上也取決於需要,但如果可用的物理記憶體足夠,則可能不需要很大的交換空間,用外行的話來說,不需要更改60.

引用自:https://unix.stackexchange.com/questions/265713