Linux performance optimization 2: optimizing swap partitions

Source: Internet
Author: User
About linux performance tuning 2: optimizing swap partitions 1 of linux performance tuning: Disk partitioning policy http://www.2cto.com/os/201307/226371.html First, let's talk about what is a swap partition and its role? Swap partition, that is, Swap zone. The role of swap space can be described in a simple way... about linux performance tuning 2: optimizing Swap partitions 1: linux performance tuning 1: Disk partitioning policy http://www.2cto.com/os/201307/226371.html First, let's talk about what is a swap partition and its role? Swap partition, that is, Swap zone. The role of Swap space can be simply described as: when the physical memory of the system is insufficient, a part of the physical memory needs to be released, for the currently running program. The released space may come from some programs that haven't been operated for a long time. the released space is temporarily saved to the Swap space and will be executed by those programs, then, the stored data is restored from the Swap to the memory. In this way, the system always performs Swap switching when the physical memory is insufficient. In fact, Swap adjustment is crucial to the performance of Linux servers, especially Web servers. By adjusting Swap, the system performance bottleneck is sometimes crossed to save system upgrade costs. If you allocate too much Swap space, the disk space will be wasted, and the Swap space is too small, the system will encounter an error. If the system's physical memory is used up, the system will run slowly but still run. if the Swap space is used up, the system will encounter an error. For example, a Web server can generate multiple service processes (or threads) based on the number of requests. if Swap space is used up, the service process cannot be started, generally, the error "application is out of memory" may occur. in severe cases, the service process may be deadlocked. Therefore, Swap space allocation is very important. Generally, Swap space should be greater than or equal to the size of physical memory, and the minimum should not be less than 64 M. Generally, the size of Swap space should be 2-times that of physical memory. However, different applications should have different configurations: for a small desktop system, only a small Swap space is required, A large server system requires different sizes of Swap space depending on the situation. Especially for database servers and Web servers, as access traffic increases, the requirements for Swap space will also increase. for specific configurations, see the descriptions of server products. In addition, the number of Swap partitions has a great impact on the performance. Because Swap operations are disk IO operations, if there are multiple Swap areas, the Swap space allocation will operate on all Swap in turn, this will greatly balance the IO load and speed up Swap switching. If there is only one swap area, all the swap operations will make the swap area very busy, so that the system is waiting most of the time, the efficiency is very low. The performance monitoring tool will find that the CPU is not very busy at this time, but the system is slow. This shows that the bottleneck lies in I/O, and it cannot be solved by increasing the CPU speed, think about the problems that some people in the forum say they have a large memory and do not need to use swap partitions. if we use swap partitions properly, why can't eight machines solve the problem? Next, let's take a look at the official suggestions of RedHat: Next we will talk about swap partition optimization: 1. first, try to use partitions instead of files. remember to do this unless you have. of course, it may be that the space is too small, so add the swap partition by yourself. 3. note that partitions with smaller partition numbers are used (I have emphasized in 'one of linux performance optimizations: partition policy') 4. round robin can be achieved by distributing data to different devices. if there are multiple swap partitions, you can also specify the priority, that is, use a better-performing partition first. Note that you should write in the configuration file/etc/fstab: (The larger the number, the higher the priority, you can also use swapon-p to specify)/dev/hda1 swap defaults, pri = 10 0 0/dev/hda5 swap defaults, pri = 5 0 0 6. an important parameter: [root @ override top31 ~] # Sysctl-a | grep vm. swa vm. swappiness = 60 there are several special values in the Linux kernel optimization process, including this, which is not a specific percentage, but an expected value. The closer it is to 0, try to use the cache, the closer it is to 100, the more swap is used as much as possible. two unadjusted values: vm. swap_token_timeout = 300 interval vm. page-cluster = 3 Number of pages written to swap at a time 2 ^ 3*4 K = 32 K
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.