Vm. swappiness = 0. OOM may occur in the latest kernel. MySQL is accidentally killed.

Source: Internet
Author: User
Tags andrew morton
Vm. swappiness0 may cause OOM in the latest kernel, and MySQL may be killed unexpectedly. please use RHEL/CentOS 6.4 and the MySQL Kernel updated. Note that vm. the default behavior of swappiness = 0 has been modified. if you continue to set vm. swappiness = 0, which may cause system memory overflow and cause MySQL to be killed unexpectedly.

In the previous MYSQL optimization three axes on LINUX, we recommend that you set vm. swappiness = 0. To avoid swap out MySQL server memory. In this way, Linux prefers to swap out cache pages rather than inactive pages when switching out the memory. For more information, see: http://www.woqutech.com /? P = 1200.

It is often asked whether vm. swappiness = 0 will cause Linux to not swap out swap space, resulting in memory overflow (OOM ). Referring to the introduction of MYSQL optimization on LINUX, we know that this value is only a "tends" reference value for a Linux system to determine whether to swap memory (swap), not to say, after it is set to 0, Linux will not use the memory swap space at all.

However, in the newer kernel (2.6.32-303. el6 and later), the default vm. swappiness = 0 behavior is modified, which is no longer true. If vm. swappiess is set to 0, memory overflow may occur in the system where the MySQL database is located. In general, the MySQL database occupies the largest memory on the server. according to the Linux policy, it will first Kill MySQL (adjust/proc/(pidof-s mysqld) /oom_adj can change the kill priority of OOM), resulting in application faults.

This modification was submitted in kernel 3.5-rc1 and merged into 2.6.32-303. el6 and later versions. Let's take a look at this patch:

Http://gitorious.ti.com/ti-linux-kernel/ti-linux-kernel/commit/fe35004fbf9eaf67482b074a2e032abb9c89b1dd? Format = patch

From fe35004fbf9eaf67482b074a2e032abb9c89b1dd Mon Sep 17 00:00:00 2001

From: Satoru Moriya

Date: Tue, 29 May 2012 15:06:47-0700

Subject: [PATCH] mm: avoid swapping out with swappiness = 0

Sometimes we 'd like to avoid swapping out anonymous memory. In

Particle, avoid swapping out pages of important process or process

Groups while there is a reasonable amount of pagecache on RAM so that we

Can satisfy our MERS 'requirements.

OTOH, we can control how aggressive the kernel will swap memory pages

/Proc/sys/vm/swappiness for global and

/Sys/fs/cgroup/memory. swappiness for each memcg.

But with current reclaim implementation, the kernel may swap out even if

We set swappiness = 0 and there is pagecache in RAM.

This patch changes the behavior with swappiness = 0. If we set

Swappiness = 0, the kernel does not swap out completely (for global reclaim

Until the amount of free pages and filebacked pages in a zone has been

Forced CED to something very small (nr_free + nr_filebacked

Watermark )).

Signed-off-by: Satoru Moriya

Acked-by: Minchan Kim

Reviewed-by: Rik van Riel

Acked-by: Jerome Marchand

Signed-off-by: Andrew Morton

Signed-off-by: Linus Torvalds

---

Mm/vmscan. c | 6 ++ ---

1 files changed, 3 insertions (+), 3 deletions (-)

Diff -- git a/mm/vmscan. c B/mm/vmscan. c

Index 67a4fd4 .. ee97530 100644

--- A/mm/vmscan. c

++ B/mm/vmscan. c

@-1761,10 + 1761,10 @ static void get_scan_count (struct mem_cgroup_zone * mz, struct scan_control * SC,

* Proportional to the fraction of recently scanned pages on

* Each list that were recently referenced and in active use.

*/

-Ap = (anon_prio + 1) * (reclaim_stat-> recent_scanned [0] + 1 );

+ Ap = anon_prio * (reclaim_stat-> recent_scanned [0] + 1 );

Ap/= reclaim_stat-> recent_rotated [0] + 1;

-Fp = (file_prio + 1) * (reclaim_stat-> recent_scanned [1] + 1 );

+ Fp = file_prio * (reclaim_stat-> recent_scanned [1] + 1 );

Fp/= reclaim_stat-> recent_rotated [1] + 1;

Spin_unlock_irq (& mz-> zone-> lru_lock );

@-1777,7 + 1777,7 @ out:

Unsigned long scan;

Scan = zone_nr_lru_pages (mz, lru );

-If (priority | noswap ){

+ If (priority | noswap |! Vmscan_swappiness (mz, SC )){

Scan >>= priority;

If (! Scan & force_scan)

Scan = SWAP_CLUSTER_MAX;

--

1.7.5

As Satoru Moriya said, in earlier versions, even if we set swappiness = 0 and RAM has pagecache, the kernel may swap out some anonymous memory pages. In order to "meet user needs", this patch modifies the swappiness = 0 behavior. if you set swappiness = 0, only in (nr_free + nr_filebacked

In kernel 2.6.32-303. el6 RHEL/CentOS and later versions, the patch has been merged:

* Mon Aug 27 2012 Jarod Wilson [2.6.32-303. el6]

...

-[Mm] avoid swapping out with swappiness = 0 (Satoru Moriya) [787885]

For other distribution versions of Linux (such as Debian and Ubuntu), check the patch.

The kernel version of RHEL/CentOS 6.3 is 2.6.32-279, and the kernel of RHEL/CentOS 6.4 is 2.6.32-358. from this version, swappiness has been modified, comrades who use this and later versions should pay special attention to it.

The solution is actually very simple,

1. try to ensure that the Linux operating system has enough memory

2. for the latest kernel, we recommend that you set vm. swappiness to 1.

3. set/proc/(pidof-s mysqld)/oom_adj to a smaller value to avoid MySQL being shut down due to insufficient memory.

Refer:

Https://github.com/torvalds/linux/blob/master/mm/vmscan.c

Http://gitorious.ti.com/ti-linux-kernel/ti-linux-kernel/commit/fe35004fbf9eaf67482b074a2e032abb9c89b1dd? Format = patch

Http://www.mysqlperformanceblog.com/2014/04/28/oom-relation-vm-swappiness0-new-kernel/

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.