Set the size setting of swap swap space and the swappiness scale setting in CentOS

Source: Internet
Author: User

First use the FREE-M command to see the memory usage and swap size

Close swap:

To set the swap size:

BS refers to the block size, which is the magnitude of each chunk. The example here is 1M, which means the number of count, which is measured in 1M.

Count is telling the program how many blocks the new swapfile will take. Here is 1024, which means that the new swap file is 5G in size.

Note: It may take some time to complete this step and wait patiently for completion.

Convert the enlarged file into a swap file:

Re-open Swap:

Allow swap to take effect automatically when it is started. Open the/etc/fstab file and add the following command. and then save.

Query swap size again:

Set the scale value of the swappiness:

First of all, the role of the swap partition, in fact, the swap partition under the Linux system and the virtual memory under Windows almost a meaning, the role of the swap space is simple to understand: when the system's physical memory is not enough, it is necessary to the physical memory of a portion of the space released, For use by the currently running program. The freed space may come from programs that have not been manipulated for a long time, and the freed space is temporarily saved in the swap space until those programs run, recovering the saved data from the swap into memory. In this way, the system always does swap swap when physical memory is not enough.

In other words, Linux uses a portion of the hard disk as a swap partition for process scheduling-the process is a running program-standby the currently unused process to ' wait ', or even ' sleep ', once it is used, and then '   Active ', the process of sleeping sleeps in the swap zone, emptying the memory out of the ' activity ' process. If the memory is large enough, then this should allow Linux not to use the swap partition too much, you can modify the value of the swappiness. When the swappiness is 0, the maximum use of physical memory, and then the swap space, when the swappines is 100, it means active use of the swap partition, and the memory of the data in a timely manner into the swap space.
In the CentOS, Red Hat, Ubuntu and other systems, the default value of Swappiness is 60, if the Linux server memory is very small, for example, less than 4G, then you can not change this value, because after all, considering the memory is not enough to borrow swap case. Compared to many servers, it is recommended to set below the value of 25, if more than 8G of memory, and the current memory usage is still remaining, it is recommended to directly change the swappiness to 0, so as to maximize the use of physical memory, reduce the load on the hard disk, and speed up. Also avoid errors such as "memcached timeout error because of slow response" when using memcached. about commands related to swappiness operations:View swappiness Current settings: Modify the value of swappiness: To make the swappiness value modified, the restart does not expire:
Add "Vm.swappiness=0" to the last line

Set the size setting of swap swap space and the swappiness scale setting in CentOS

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.