set setting reset

脂肪と糖にはたらくやつ

CentOS7 で再起動後に vm.swappiness の設定が元に戻ってしまう

環境

AWS EC2 の CentOS 公式 AMI です。

CentOS 7 (x86_64) - with Updates HVM on AWS Marketplace

事象

  • デフォルトは vm.swappiness = 30
  • sysctl -w vm.swappiness=任意の値 すると任意の値に変更可能
  • sysctl -p するも reboot 後に元に戻ってしまう

原因

こちらで言及されていました。

CentOs7 vm.swappiness cannot be set on boot - CentOS

tuned によって上書きされるようです。

対応

tuned の設定ファイルは /usr/lib/tuned 配下にあるそうですので grep してみます。

#  find /usr/lib/tuned -name '*.conf' -type f -exec grep "vm.swappiness" {} \+
/usr/lib/tuned/latency-performance/tuned.conf:vm.swappiness=10
/usr/lib/tuned/throughput-performance/tuned.conf:vm.swappiness=10
/usr/lib/tuned/virtual-guest/tuned.conf:vm.swappiness = 30

デフォルトでは 30 に設定されていましたので、 /usr/lib/tuned/virtual-guest/tuned.conf の値を変更したところ、意図した通りに設定されました。 一応、編集したファイルを下記に記載します。

#
# tuned configuration
#

[main]
include=throughput-performance

[sysctl]
# If a workload mostly uses anonymous memory and it hits this limit, the entire
# working set is buffered for I/O, and any more write buffering would require
# swapping, so it's time to throttle writes until I/O can catch up.  Workloads
# that mostly use file mappings may be able to use even higher values.
#
# The generator of dirty data starts writeback at this percentage (system default
# is 20%)
vm.dirty_ratio = 30

# Filesystem I/O is usually much more efficient than swapping, so try to keep
# swapping low.  It's usually safe to go even lower than this on systems with
# server-grade storage.
- vm.swappiness = 30
+ vm.swappiness = 5