linux调优之Set vm.swappiness to 1 or 0

  |   0 评论   |   0 浏览

Set vm.swappiness to 1 or 0

“Swappiness” is a Linux kernel setting that influences the behavior of the Virtual Memory manager. The vm.swappiness setting ranges from 0 to 100: the higher the value, the more strongly it prefers swapping memory pages to disk over dropping pages from RAM.

  • A setting of0 disables swapping entirely [2].
  • A setting of1 permits the kernel to swap only to avoid out-of-memory problems.
  • A setting of60 tells the kernel to swap to disk often, and is the default value on many Linux distributions.
  • A setting of100 tells the kernel to swap aggressively to disk.

MongoDB performs best where swapping can be avoided or kept to a minimum. As such you should set vm.swappiness to either 1 or 0 depending on your application needs and cluster configuration.

| [2] | With Linux kernel versions previous to 3.5, or RHEL / CentOS kernel versions previous to 2.6.32-303, a vm.swappiness setting of 0 would still allow the kernel to swap in certain emergency situations. |
| - | - |
| | |


If your MongoDB instance is hosted on a system that also runs other software, such as a webserver, you should set vm.swappiness to 1. If possible, it is highly recommended that you run MongoDB on its own dedicated system.

  • To check the current swappiness setting on your system, run:


    cat /proc/sys/vm/swappiness
  • To change swappiness on your system:

    1. Edit the /etc/sysctl.conf file and add the following line:


      vm.swappiness = 1
    2. Run the following command to apply the setting:


      sudo sysctl -p


If you are running RHEL / CentOS and using a tuned performance profile, you must also edit your chosen profile to set vm.swappiness to 1 or 0.

标题:linux调优之Set vm.swappiness to 1 or 0