How does MySQL use swap?

Source: Internet
Author: User
How does MySQL avoid using swap Original article: www.taobaodba.comhtml552_mysql_avoid_swap.html? Linux has many good memory and IO Scheduling Mechanisms, but they are not suitable for all scenarios. One of the headaches for DBA Linux is that it does not avoid null IP addresses allocated to MySQL because MySQL is very important.

How does MySQL avoid using swap Original: http://www.taobaodba.com/html/552_mysql_avoid_swap.html? Linux has many good memory and IO Scheduling Mechanisms, but they are not suitable for all scenarios. One of the headaches for DBA Linux is that it does not avoid null IP addresses allocated to MySQL because MySQL is very important.

How does MySQL avoid using swap?

Original article:

Http://www.taobaodba.com/html/552_mysql_avoid_swap.html

?

Linux has many good memory and IO Scheduling Mechanisms, but they are not suitable for 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 in fact it is very bad on the disk. The increase in response time is likely to drag the entire system down. 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 three simplest adjustment methods:
1. Change the/proc/sys/vm/swappiness content to 0 (temporary), and add vm. swappiness = 0 (permanent) to/etc/sysctl. conf)
This parameter 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. Add the MySQL Configuration Parameter memlock.
This parameter forces the IP address space of the mysqld process to be locked in the physical memory, which is an 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. The specific configuration method can take the test: http://harrison-fisk.blogspot.com/2009/01/enabling-innodb-large-pages-on-linux.html

?

Http://robbin.iteye.com/blog/461382 for more information

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.