How does MySQL avoid using swap?

Source: Internet
Author: User

How does MySQL avoid using swap Linux? There are many good memory and IO Scheduling Mechanisms, but they are not applicable to all scenarios. One of the headaches for DBA Linux is that it does not avoid ing the address space allocated to MySQL to swap because MySQL is very important. For systems that frequently perform read/write operations, the data seems to be in the memory but is actually very bad on the disk, and the growth in response time is likely to drag down the entire system. This blog mainly talks about how we, as a DBA, try to avoid MySQL from being attacked by swap. First, we need to understand some basic things, such as why swap is generated. Assume that the physical memory is 16 GB, And the swap is 4 GB. If MySQL occupies 12 GB of physical memory and other programs or system modules require 6 GB of memory, the operating system may map some of the address space of MySQL to swap. When cp is a large file or mysqldump is used to export a large database, the file system will usually apply for a large amount of memory from Linux as the cache. If you are not careful, L will use swap. This scenario is common. The following are the simplest three adjustment methods: 1. Change the content of/proc/sys/vm/swappiness to 0 (temporary) and/etc/sysctl. add vm on conf. swappiness = 0 (permanent) determines whether Linux prefers to use swap or release the file system cache. When the memory is tight, the lower the value, the more inclined it is to release the file system cache. Of course, this parameter can only reduce the probability of using swap, and does not prevent Linux from using swap. 2. Modify the MySQL Configuration Parameter innodb_flush_method to enable the O_DIRECT mode. In this case, the buffer pool of InnoDB directly bypasses the file system cache to access the disk, but the redo log still uses the file system cache. It is worth noting that the Redo log is in the overwriting mode, and will not occupy too much even if the file system cache is used. 3. Adding the MySQL Configuration Parameter memlock will force the address space of the mysqld process to be locked in the physical memory. This is a very overbearing requirement for the OS. You must use the root account to start MySQL to take effect. Another complicated method is to specify that MySQL uses the Large Page memory (Large Page ). On Linux, the large page memory will not be swapped out of the physical memory, which is similar to memlock.

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.