{"id":104,"date":"2013-04-17T15:49:18","date_gmt":"2013-04-17T13:49:18","guid":{"rendered":"http:\/\/www.olivierdoucet.info\/blog\/?p=104"},"modified":"2013-04-18T18:50:52","modified_gmt":"2013-04-18T16:50:52","slug":"story-mysql-crash-memory-issue","status":"publish","type":"post","link":"https:\/\/www.olivierdoucet.info\/blog\/2013\/04\/17\/story-mysql-crash-memory-issue\/","title":{"rendered":"Story of a MySQL crash (memory issue)"},"content":{"rendered":"<p>Today we faced an important issue with MySQL 5.5<br \/>\nServer stalled after aborting a TRUNCATE on a big table. Yes, this is bad to abort a TRUNCATE \ud83d\ude09 But this is not the issue I want to speak about. Server crashed, that&rsquo;s a point. mysqld process restarted automatically, and started loading data into memory (massive use of InnoDB tables). This server has 128GB of memory, so buffer pool was set to 100GB (yes, that&rsquo;s quite huge). Data set is ~ 100GB. After a few minutes, server crashed again, but this time complaining about memory.<\/p>\n<p><!--more--><\/p>\n<p>Error log gave this :<br \/>\n<code>*** glibc detected *** \/usr\/sbin\/mysqld-5.5: malloc(): memory corruption: 0x00007f5ffc9affa0 ***<br \/>\n======= Backtrace: =========<br \/>\n\/lib64\/libc.so.6[0x7f7a46163e96]<br \/>\n\/lib64\/libc.so.6[0x7f7a46166b4e]<br \/>\n[...]<br \/>\n08:45:24 UTC - mysqld got signal 6 ;<\/code><\/p>\n<p>The biggest problem is that this behaviour happened three times in a row. As it needs ~ 30 minutes to warm buffer pool, this was quite a downtime.<\/p>\n<p>Memory usage looked like this (pink is pagecache) :<br \/>\n<a href=\"https:\/\/www.olivierdoucet.info\/blog\/wp-content\/uploads\/2013\/04\/memory.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.olivierdoucet.info\/blog\/wp-content\/uploads\/2013\/04\/memory.png\" alt=\"Memory usage\" width=\"349\" height=\"191\" class=\"aligncenter size-full wp-image-105\" srcset=\"https:\/\/www.olivierdoucet.info\/blog\/wp-content\/uploads\/2013\/04\/memory.png 349w, https:\/\/www.olivierdoucet.info\/blog\/wp-content\/uploads\/2013\/04\/memory-300x164.png 300w\" sizes=\"auto, (max-width: 349px) 100vw, 349px\" \/><\/a><\/p>\n<p>And dmesg reported this : <\/p>\n<p><code>[28524726.820222] INFO: rcu_bh detected stall on CPU 32 (t=0 jiffies)<br \/>\n[28524726.820230] Pid: 53878, comm: mysqld-5.5 Not tainted 3.2.0-oxeva #8<br \/>\n[28524726.820237] Call Trace:<br \/>\n[28524726.820244]  <IRQ>  [<ffffffff81092a4e>] __rcu_pending+0x89\/0x35b<br \/>\n[28524726.820285]  [<ffffffff81092e0f>] rcu_check_callbacks+0xef\/0x110<br \/>\n[28524726.820301]  [<ffffffff81059c02>] update_process_times+0x41\/0x77<br \/>\n[28524726.820314]  [<ffffffff81075e8f>] tick_sched_timer+0x6f\/0x98<br \/>\n[28524726.820329]  [<ffffffff8106b2e1>] __run_hrtimer+0x95\/0x120<br \/>\n[28524726.820337]  [<ffffffff81075e20>] ? tick_nohz_handler+0xd8\/0xd8<br \/>\n[28524726.820341]  [<ffffffff8106b5a0>] hrtimer_interrupt+0xda\/0x1a4<br \/>\n[28524726.820350]  [<ffffffff817382c2>] smp_apic_timer_interrupt+0x7e\/0x91<br \/>\n[28524726.820365]  [<ffffffff8173678b>] apic_timer_interrupt+0x6b\/0x70<br \/>\n[28524726.820367]  <EOI><\/code><\/p>\n<p>So RCU seems the one responsible for killing mysqld.<\/p>\n<p><strong>What is RCU ? <\/strong><br \/>\nLet&rsquo;s explain this in a few words : when you deallocate memory, the memory is not released immediately but marked as \u00ab\u00a0can be deallocated\u00a0\u00bb. The deallocation itself is asynchronous and handled by RCU.<br \/>\n(Well, this is a big shortcut, but if you&rsquo;re interested, you can have full explanation here : <a href=\"http:\/\/www.rdrop.com\/users\/paulmck\/RCU\/whatisRCU.html\" title=\"http:\/\/www.rdrop.com\/users\/paulmck\/RCU\/whatisRCU.html\" target=\"_blank\">http:\/\/www.rdrop.com\/users\/paulmck\/RCU\/whatisRCU.html<\/a>)<\/p>\n<p>So, what is happening here ?<br \/>\nWhen we have allocated all the memory (user space + page cache), and Mysql makes a malloc() to ask for more, kernel is faced to a dilemma : he has allocated 100%, but he knows some memory can be reclaimed. This is RCU job, but deallocation takes time, and malloc() needs to have an answer fast. This is a zone of undefined behaviour, and in our case, this results to a corruption with malloc() call (and mysqld crashed).<\/p>\n<p><strong>How can we fix this ? <\/strong><br \/>\nAs we have a majority of InnoDB tables, page cache is not very useful (innodb handles cache itself). So we can disable it by opening files with flag O_DIRECT.<br \/>\nThis is handled with mysql variable <a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.5\/en\/innodb-parameters.html#sysvar_innodb_flush_method\" title=\"innodb_flush_method\" target=\"_blank\">innodb_flush_method<\/a><\/p>\n<p>We launch mysql again with this variable set to O_DIRECT, and result is OK :<br \/>\n<a href=\"https:\/\/www.olivierdoucet.info\/blog\/wp-content\/uploads\/2013\/04\/after.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.olivierdoucet.info\/blog\/wp-content\/uploads\/2013\/04\/after.png\" alt=\"Memory usage after\" width=\"353\" height=\"178\" class=\"aligncenter size-full wp-image-106\" srcset=\"https:\/\/www.olivierdoucet.info\/blog\/wp-content\/uploads\/2013\/04\/after.png 353w, https:\/\/www.olivierdoucet.info\/blog\/wp-content\/uploads\/2013\/04\/after-300x151.png 300w\" sizes=\"auto, (max-width: 353px) 100vw, 353px\" \/><\/a><br \/>\nSee ? No more pagecache used, and plenty of memory available.<\/p>\n<p>We did not use O_DIRECT before because of incompatibilities with NFS, but this has been fixed since.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today we faced an important issue with MySQL 5.5 Server stalled after aborting a TRUNCATE on a big table. Yes, this is bad to abort a TRUNCATE \ud83d\ude09 But this is not the issue I want to speak about. Server crashed, that&rsquo;s a point. mysqld process restarted automatically, and started loading data into memory (massive &hellip; <a href=\"https:\/\/www.olivierdoucet.info\/blog\/2013\/04\/17\/story-mysql-crash-memory-issue\/\" class=\"more-link\">Continuer la lecture de <span class=\"screen-reader-text\">Story of a MySQL crash (memory issue)<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[57,36],"class_list":["post-104","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-innodb_flush_method","tag-mysql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Story of a MySQL crash (memory issue) - My thoughts<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.olivierdoucet.info\/blog\/2013\/04\/17\/story-mysql-crash-memory-issue\/\" \/>\n<meta property=\"og:locale\" content=\"fr_FR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Story of a MySQL crash (memory issue) - My thoughts\" \/>\n<meta property=\"og:description\" content=\"Today we faced an important issue with MySQL 5.5 Server stalled after aborting a TRUNCATE on a big table. Yes, this is bad to abort a TRUNCATE \ud83d\ude09 But this is not the issue I want to speak about. Server crashed, that&rsquo;s a point. mysqld process restarted automatically, and started loading data into memory (massive &hellip; Continuer la lecture de Story of a MySQL crash (memory issue) &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.olivierdoucet.info\/blog\/2013\/04\/17\/story-mysql-crash-memory-issue\/\" \/>\n<meta property=\"og:site_name\" content=\"My thoughts\" \/>\n<meta property=\"article:published_time\" content=\"2013-04-17T13:49:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-04-18T16:50:52+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.olivierdoucet.info\/blog\/wp-content\/uploads\/2013\/04\/memory.png\" \/>\n<meta name=\"author\" content=\"Olivier\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@odoucet\" \/>\n<meta name=\"twitter:site\" content=\"@odoucet\" \/>\n<meta name=\"twitter:label1\" content=\"\u00c9crit par\" \/>\n\t<meta name=\"twitter:data1\" content=\"Olivier\" \/>\n\t<meta name=\"twitter:label2\" content=\"Dur\u00e9e de lecture estim\u00e9e\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.olivierdoucet.info\/blog\/2013\/04\/17\/story-mysql-crash-memory-issue\/\",\"url\":\"https:\/\/www.olivierdoucet.info\/blog\/2013\/04\/17\/story-mysql-crash-memory-issue\/\",\"name\":\"Story of a MySQL crash (memory issue) - My thoughts\",\"isPartOf\":{\"@id\":\"https:\/\/www.olivierdoucet.info\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.olivierdoucet.info\/blog\/2013\/04\/17\/story-mysql-crash-memory-issue\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.olivierdoucet.info\/blog\/2013\/04\/17\/story-mysql-crash-memory-issue\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/www.olivierdoucet.info\/blog\/wp-content\/uploads\/2013\/04\/memory.png\",\"datePublished\":\"2013-04-17T13:49:18+00:00\",\"dateModified\":\"2013-04-18T16:50:52+00:00\",\"author\":{\"@id\":\"https:\/\/www.olivierdoucet.info\/blog\/#\/schema\/person\/d093cada9eddc4839cbae3de5c823a39\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.olivierdoucet.info\/blog\/2013\/04\/17\/story-mysql-crash-memory-issue\/#breadcrumb\"},\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.olivierdoucet.info\/blog\/2013\/04\/17\/story-mysql-crash-memory-issue\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\/\/www.olivierdoucet.info\/blog\/2013\/04\/17\/story-mysql-crash-memory-issue\/#primaryimage\",\"url\":\"http:\/\/www.olivierdoucet.info\/blog\/wp-content\/uploads\/2013\/04\/memory.png\",\"contentUrl\":\"http:\/\/www.olivierdoucet.info\/blog\/wp-content\/uploads\/2013\/04\/memory.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.olivierdoucet.info\/blog\/2013\/04\/17\/story-mysql-crash-memory-issue\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.olivierdoucet.info\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Story of a MySQL crash (memory issue)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.olivierdoucet.info\/blog\/#website\",\"url\":\"https:\/\/www.olivierdoucet.info\/blog\/\",\"name\":\"My thoughts\",\"description\":\"En fran\u00e7ais and in english :)\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.olivierdoucet.info\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"fr-FR\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.olivierdoucet.info\/blog\/#\/schema\/person\/d093cada9eddc4839cbae3de5c823a39\",\"name\":\"Olivier\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\/\/www.olivierdoucet.info\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e75f77ace92ccb2dfab09f226ce3d329?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e75f77ace92ccb2dfab09f226ce3d329?s=96&d=mm&r=g\",\"caption\":\"Olivier\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Story of a MySQL crash (memory issue) - My thoughts","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.olivierdoucet.info\/blog\/2013\/04\/17\/story-mysql-crash-memory-issue\/","og_locale":"fr_FR","og_type":"article","og_title":"Story of a MySQL crash (memory issue) - My thoughts","og_description":"Today we faced an important issue with MySQL 5.5 Server stalled after aborting a TRUNCATE on a big table. Yes, this is bad to abort a TRUNCATE \ud83d\ude09 But this is not the issue I want to speak about. Server crashed, that&rsquo;s a point. mysqld process restarted automatically, and started loading data into memory (massive &hellip; Continuer la lecture de Story of a MySQL crash (memory issue) &rarr;","og_url":"https:\/\/www.olivierdoucet.info\/blog\/2013\/04\/17\/story-mysql-crash-memory-issue\/","og_site_name":"My thoughts","article_published_time":"2013-04-17T13:49:18+00:00","article_modified_time":"2013-04-18T16:50:52+00:00","og_image":[{"url":"http:\/\/www.olivierdoucet.info\/blog\/wp-content\/uploads\/2013\/04\/memory.png","type":"","width":"","height":""}],"author":"Olivier","twitter_card":"summary_large_image","twitter_creator":"@odoucet","twitter_site":"@odoucet","twitter_misc":{"\u00c9crit par":"Olivier","Dur\u00e9e de lecture estim\u00e9e":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.olivierdoucet.info\/blog\/2013\/04\/17\/story-mysql-crash-memory-issue\/","url":"https:\/\/www.olivierdoucet.info\/blog\/2013\/04\/17\/story-mysql-crash-memory-issue\/","name":"Story of a MySQL crash (memory issue) - My thoughts","isPartOf":{"@id":"https:\/\/www.olivierdoucet.info\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.olivierdoucet.info\/blog\/2013\/04\/17\/story-mysql-crash-memory-issue\/#primaryimage"},"image":{"@id":"https:\/\/www.olivierdoucet.info\/blog\/2013\/04\/17\/story-mysql-crash-memory-issue\/#primaryimage"},"thumbnailUrl":"http:\/\/www.olivierdoucet.info\/blog\/wp-content\/uploads\/2013\/04\/memory.png","datePublished":"2013-04-17T13:49:18+00:00","dateModified":"2013-04-18T16:50:52+00:00","author":{"@id":"https:\/\/www.olivierdoucet.info\/blog\/#\/schema\/person\/d093cada9eddc4839cbae3de5c823a39"},"breadcrumb":{"@id":"https:\/\/www.olivierdoucet.info\/blog\/2013\/04\/17\/story-mysql-crash-memory-issue\/#breadcrumb"},"inLanguage":"fr-FR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.olivierdoucet.info\/blog\/2013\/04\/17\/story-mysql-crash-memory-issue\/"]}]},{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/www.olivierdoucet.info\/blog\/2013\/04\/17\/story-mysql-crash-memory-issue\/#primaryimage","url":"http:\/\/www.olivierdoucet.info\/blog\/wp-content\/uploads\/2013\/04\/memory.png","contentUrl":"http:\/\/www.olivierdoucet.info\/blog\/wp-content\/uploads\/2013\/04\/memory.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.olivierdoucet.info\/blog\/2013\/04\/17\/story-mysql-crash-memory-issue\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.olivierdoucet.info\/blog\/"},{"@type":"ListItem","position":2,"name":"Story of a MySQL crash (memory issue)"}]},{"@type":"WebSite","@id":"https:\/\/www.olivierdoucet.info\/blog\/#website","url":"https:\/\/www.olivierdoucet.info\/blog\/","name":"My thoughts","description":"En fran\u00e7ais and in english :)","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.olivierdoucet.info\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"fr-FR"},{"@type":"Person","@id":"https:\/\/www.olivierdoucet.info\/blog\/#\/schema\/person\/d093cada9eddc4839cbae3de5c823a39","name":"Olivier","image":{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/www.olivierdoucet.info\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e75f77ace92ccb2dfab09f226ce3d329?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e75f77ace92ccb2dfab09f226ce3d329?s=96&d=mm&r=g","caption":"Olivier"}}]}},"_links":{"self":[{"href":"https:\/\/www.olivierdoucet.info\/blog\/wp-json\/wp\/v2\/posts\/104","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.olivierdoucet.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.olivierdoucet.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.olivierdoucet.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.olivierdoucet.info\/blog\/wp-json\/wp\/v2\/comments?post=104"}],"version-history":[{"count":8,"href":"https:\/\/www.olivierdoucet.info\/blog\/wp-json\/wp\/v2\/posts\/104\/revisions"}],"predecessor-version":[{"id":108,"href":"https:\/\/www.olivierdoucet.info\/blog\/wp-json\/wp\/v2\/posts\/104\/revisions\/108"}],"wp:attachment":[{"href":"https:\/\/www.olivierdoucet.info\/blog\/wp-json\/wp\/v2\/media?parent=104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.olivierdoucet.info\/blog\/wp-json\/wp\/v2\/categories?post=104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.olivierdoucet.info\/blog\/wp-json\/wp\/v2\/tags?post=104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}