How to deal with the lack of swap space

Source: Internet
Author: User

In the process of daily operations, we often encounter the lack of swap space, and even nagios to swap monitoring as a basic system monitoring items, enough to see the importance of this performance indicators.


In general, MySQL database machine is more prone to swap space is not enough, also has the application server high load situation also can produce this phenomenon.


Why is swap used? Suppose our physical memory is 32g,swap is 4G. If MySQL itself already occupies 24G of physical memory while other programs or system modules require 8G of memory, then the operating system may map a portion of the address space owned by MySQL to swap.

such as copying or compressing a large file, or using mysqldump to export a large database, the file system will often apply to Linux a large amount of memory as a cache, accidentally will cause L to use swap. This scenario is more common, and the following are the simplest three adjustment methods:

①/proc/sys/vm/swappiness content changed to 0 (temporary),/etc/sysctl.conf add vm.swappiness=0 (permanent)
This parameter determines whether Linux is inclined to use swap or is disposed to release the filesystem cache. In the case of tight memory, the lower the value the more inclined to release the file system cache.

Of course, this parameter only reduces the probability of using swap, and does not prevent Linux from using swap.


② Modify the configuration parameters of MySQL Innodb_flush_method, turn on O_direct mode.

In this case, the InnoDB buffer pool will directly bypass the file system cache to access the disk, but redo log will still use the file system cache. It is important to note that Redo log is overwrite mode and does not take up too much even if the file system cache is used.


③ add MySQL configuration parameters Memlock
This parameter forces the address space of the mysqld process to remain locked in physical memory, which is a very overbearing requirement for the OS. You must start MySQL with the root account to take effect.

There is also a more sophisticated way to specify that MySQL uses large page memory (Large page). Large pages of memory on Linux will not be swapped out of physical memory, and Memlock have the same wonderful.


A necessary condition for a program to run is sufficient memory, which is often a source of tension within the system. To meet the requirements of more programs, the operating system virtual a portion of the memory address and maps it to swap. For a program, it knows only that the operating system allocates memory addresses to itself, but it is unclear whether the memory addresses are mapped to physical memory or swap.


Physical memory and swap are functionally identical, except for the difference in performance between physical storage components (memory and disk). The operating system will swap in and out according to the characteristics of the program using memory, leaving the physical memory as much as possible to the program that needs it most. However, this scheduling is based on a predetermined set of rules, and does not fully meet the needs of the program.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

How to deal with the lack of swap space

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.