{"id":3373,"date":"2018-11-15T18:18:20","date_gmt":"2018-11-15T10:18:20","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=3373"},"modified":"2018-11-15T18:18:20","modified_gmt":"2018-11-15T10:18:20","slug":"out-of-memorykill-process-or-sacrifice-child","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=3373","title":{"rendered":"Out of memory:Kill process or sacrifice child"},"content":{"rendered":"<p>\n\t\u8fd9\u4e2a\u9519\u8bef\u540c\u6837\u4e0d\u5e38\u89c1\uff0c\u5f88\u5c11\u6709\u4eba\u9047\u5230\uff0c\u4f46\u5e76\u4e0d\u4ee3\u8868\u5b83\u4e0d\u5b58\u5728\uff01\u4eca\u5929\u5c31\u6765\u8bf4\u8bf4&nbsp;Out of memory: Kill process or sacrifice child\u3002\n<\/p>\n<p>\n\t\u6211\u4eec\u77e5\u9053\uff0c\u64cd\u4f5c\u7cfb\u7edf(operating system)\u6784\u5efa\u5728\u8fdb\u7a0b(process)\u7684\u57fa\u7840\u4e0a\u3002\u8fdb\u7a0b\u7531\u5185\u6838\u4f5c\u4e1a(kernel jobs)\u8fdb\u884c\u8c03\u5ea6\u548c\u7ef4\u62a4\uff0c\u5176\u4e2d\u6709\u4e00\u4e2a\u5185\u6838\u4f5c\u4e1a\u79f0\u4e3a &ldquo;Out of memory killer(OOM\u7ec8\u7ed3\u8005)&rdquo;\u3002\n<\/p>\n<p>\n\tOut of memory killer \u5728\u53ef\u7528\u5185\u5b58\u6781\u4f4e\u7684\u60c5\u51b5\u4e0b\u4f1a\u6740\u6b7b\u67d0\u4e9b\u8fdb\u7a0b\u3002\u53ea\u8981\u8fbe\u5230\u89e6\u53d1\u6761\u4ef6\u5c31\u4f1a\u6fc0\u6d3b\uff0c\u9009\u4e2d\u67d0\u4e2a\u8fdb\u7a0b\u5e76\u6740\u6389\u3002\u901a\u5e38\u91c7\u7528\u542f\u53d1\u5f0f\u7b97\u6cd5\uff0c\u5bf9\u6240\u6709\u8fdb\u7a0b\u8ba1\u7b97\u8bc4\u5206(heuristics scoring)\uff0c\u5f97\u5206\u6700\u4f4e\u7684\u8fdb\u7a0b\u5c06\u88ab kill \u6389\u3002\u56e0\u6b64 Out of memory: Kill process or sacrifice child \u548c\u524d\u9762\u6240\u8bb2\u7684 OutOfMemoryError \u90fd\u4e0d\u540c\uff0c\u56e0\u4e3a\u5b83\u65e2\u4e0d\u7531JVM\u89e6\u53d1\uff0c\u4e5f\u4e0d\u7531JVM\u4ee3\u7406, \u800c\u662f\u7cfb\u7edf\u5185\u6838\u5185\u7f6e\u7684\u4e00\u79cd\u5b89\u5168\u4fdd\u62a4\u63aa\u65bd\u3002\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"Out of memory: Kill process or sacrifice child\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/kill-process-or-sacrifice.png\" style=\"width: 704px;height: 247px\" \/>\n<\/p>\n<p>\n\t\u5982\u679c\u53ef\u7528\u5185\u5b58(\u542bswap)\u4e0d\u8db3\uff0c\u5c31\u6709\u53ef\u80fd\u4f1a\u5f71\u54cd\u7cfb\u7edf\u7a33\u5b9a\uff0c\u8fd9\u65f6\u5019 Out of memory killer \u5c31\u4f1a\u8bbe\u6cd5\u627e\u51fa\u6d41\u6c13\u8fdb\u7a0b\u5e76\u6740\u6b7b\u4ed6\uff0c\u4ece\u800c\u5f15\u8d77 Out of memory: kill process or sacrifice child \u9519\u8bef\u3002\n<\/p>\n<p>\n\t\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cLinux kernels(\u5185\u6838)\u5141\u8bb8\u8fdb\u7a0b\u7533\u8bf7\u7684\u91cf\u8d85\u8fc7\u7cfb\u7edf\u53ef\u7528\u5185\u5b58\u3002\u8fd9\u662f\u56e0\u4e3a\uff0c\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u5f88\u591a\u8fdb\u7a0b\u7533\u8bf7\u4e86\u5f88\u591a\u5185\u5b58\uff0c\u4f46\u5b9e\u9645\u4f7f\u7528\u7684\u91cf\u5e76\u6ca1\u6709\u90a3\u4e48\u591a\u3002\n<\/p>\n<p>\n\t\u6253\u4e2a\u7b80\u5355\u7684\u6bd4\u55bb\uff1a\u5bbd\u5e26\u79df\u8d41\u7684\u670d\u52a1\u5546\uff0c\u53ef\u80fd\u4ed6\u7684\u603b\u5e26\u5bbd\u53ea\u6709 10Gbps\uff0c\u4f46\u5374\u5356\u51fa\u8fdc\u8fdc\u8d85\u8fc7 100 \u4efd\u4ee5\u4e0a\u7684 100Mbps \u5e26\u5bbd\uff0c\u539f\u56e0\u662f\u591a\u6570\u65f6\u5019\uff0c\u5bbd\u5e26\u7528\u6237\u4e4b\u95f4\u662f\u9519\u5cf0\u7684\uff0c \u800c\u4e14\u4e0d\u53ef\u80fd\u6bcf\u4e2a\u7528\u6237\u90fd\u7528\u6ee1\u670d\u52a1\u5546\u6240\u627f\u8bfa\u7684\u5e26\u5bbd\u3002\n<\/p>\n<p>\n\t\u8fd9\u6837\u7684\u8bdd\uff0c\u53ef\u80fd\u4f1a\u6709\u4e00\u4e2a\u95ee\u9898\uff0c\u5047\u82e5\u67d0\u4e9b\u7a0b\u5e8f\u5360\u7528\u4e86\u5927\u91cf\u7684\u7cfb\u7edf\u5185\u5b58\uff0c\u90a3\u4e48\u53ef\u7528\u5185\u5b58\u91cf\u5c31\u4f1a\u6781\u5c0f\uff0c\u5bfc\u81f4\u6ca1\u6709\u5185\u5b58\u9875\u9762(pages)\u53ef\u4ee5\u5206\u914d\u7ed9\u9700\u8981\u7684\u8fdb\u7a0b\u3002\u53ef\u80fd\u8fd9\u65f6\u5019\u4f1a\u51fa\u73b0\u6781\u7aef\u60c5\u51b5\uff0c\u5c31\u662f root \u7528\u6237\u4e5f\u4e0d\u80fd\u901a\u8fc7 kill \u6765\u6740\u6389\u6d41\u6c13\u8fdb\u7a0b\u3002\u4e3a\u4e86\u9632\u6b62\u53d1\u751f\u8fd9\u79cd\u60c5\u51b5\uff0c\u7cfb\u7edf\u4f1a\u81ea\u52a8\u6fc0\u6d3b killer\uff0c\u67e5\u627e\u6d41\u6c13\u8fdb\u7a0b\u5e76\u5c06\u5176\u6740\u6b7b\u3002\n<\/p>\n<p>\n\t\u73b0\u5728\u6211\u4eec\u77e5\u9053\u4e86\u4e3a\u4ec0\u4e48\u4f1a\u53d1\u751f\u8fd9\u79cd\u95ee\u9898\uff0c\u90a3\u4e3a\u4ec0\u4e48\u662f\u534a\u591c5\u70b9\u949f\u89e6\u53d1 &ldquo;killer&rdquo; \u53d1\u62a5\u8b66\u4fe1\u606f\u7ed9\u4f60\u5462\uff1f\u901a\u5e38\u89e6\u53d1\u7684\u539f\u56e0\u5728\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u914d\u7f6e\u3002\u4f8b\u5982\uff1a\/proc\/sys\/vm\/overcommit_memory \u914d\u7f6e\u6587\u4ef6\u7684\u503c\uff0c \u6307\u5b9a\u4e86\u662f\u5426\u5141\u8bb8\u6240\u6709\u7684 malloc() \u8c03\u7528\u6210\u529f\u3002\u8bf7\u6ce8\u610f\uff0c\u5728\u5404\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u8fd9\u4e2a\u914d\u7f6e\u5bf9\u5e94\u7684 proc \u6587\u4ef6\u8def\u5f84\u53ef\u80fd\u4e0d\u540c\u3002\n<\/p>\n<p>\n\t\u8fc7\u91cf\u4f7f\u7528(overcommitting)\u914d\u7f6e\uff0c\u5141\u8bb8\u6d41\u6c13\u8fdb\u7a0b\u7533\u8bf7\u8d8a\u6765\u8d8a\u591a\u7684\u5185\u5b58\uff0c\u6700\u7ec8\u60f9\u5f97 &rdquo;Out of memory killer&ldquo; \u51fa\u6765\u641e\u4e8b\u60c5\u3002\n<\/p>\n<p>\n\t\u4e0b\u9762\u6211\u4eec\u770b\u4e00\u4e2a\u793a\u4f8b\uff0c\u4ea7\u751f&nbsp;Out of memory: kill process or sacrifice child \u9519\u8bef\u3002\n<\/p>\n<pre class=\"brush:java;\">\r\npublic class OOM {\r\n\/\/ \u4e1a\u4f59\u8349\uff1awww.xttblog.com\r\npublic static void main(String[] args){\r\n  java.util.List&lt;int[]&gt; l = new java.util.ArrayList();\r\n  for (int i = 10000; i &lt; 100000; i++) {\r\n      try {\r\n        l.add(new int[100000000]);\r\n      } catch (Throwable t) {\r\n        t.printStackTrace();\r\n      }\r\n    }\r\n  }\r\n}<\/pre>\n<p>\n\t\u5728 Linux \u4e0a(\u5982\u6700\u65b0\u7a33\u5b9a\u7248\u7684 Ubuntu)\u7f16\u8bd1\u5e76\u6267\u884c\u4e0a\u9762\u7684\u4ee3\u7801\uff0c\u6700\u7ec8\u5728\u7cfb\u7edf\u65e5\u5fd7\u4e2d(\u5982 \/var\/log\/kern.log \u6587\u4ef6)\u53ef\u80fd\u4f1a\u770b\u5230\u7c7b\u4f3c\u4e0b\u9762\u7684\u4fe1\u606f\uff1a\n<\/p>\n<pre class=\"brush:plain;\">\r\nJun  4 07:41:59 plumbr kernel: \r\n    [70667120.897649]\r\n    Out of memory: Kill process 29957 (java) score 366 or sacrifice child\r\nJun  4 07:41:59 plumbr kernel: \r\n    [70667120.897701]\r\n    Killed process 29957 (java) total-vm:2532680kB, anon-rss:1416508kB, file-rss:0kB<\/pre>\n<p>\n\t\u5982\u679c\u9700\u8981\u8c03\u6574 swap \u7684\u5927\u5c0f\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u7684\u547d\u4ee4\uff1a\n<\/p>\n<pre class=\"brush:bash;\">\r\nswapoff -a \r\ndd if=\/dev\/zero of=swapfile bs=1024 count=655360\r\nmkswap swapfile\r\nswapon swapfile<\/pre>\n<p>\n\t\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u7684\u529e\u6cd5\u6709\u591a\u79cd\u3002\u6700\u7b80\u5355\u7684\u529e\u6cd5\u5c31\u662f\u5c06\u7cfb\u7edf\u8fc1\u79fb\u5230\u5185\u5b58\u66f4\u5927\u7684\u5b9e\u4f8b\u4e2d\u3002\u53e6\u5916\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7 OOM killer \u8c03\u4f18\uff0c\u6216\u8005\u505a\u8d1f\u8f7d\u5747\u8861(\u6c34\u5e73\u6269\u5c55,\u96c6\u7fa4)\uff0c\u6216\u8005\u964d\u4f4e\u5e94\u7528\u5bf9\u5185\u5b58\u7684\u9700\u6c42\u3002\n<\/p>\n<h2>\n\t\u53c2\u8003\u8d44\u6599<br \/>\n<\/h2>\n<ul>\n<li>\n\t\t<a href=\"https:\/\/plumbr.io\/outofmemoryerror\/kill-process-or-sacrifice-child\" name=\"Out of memory:Kill process or sacrifice child\" target=\"_blank\" title=\"Out of memory:Kill process or sacrifice child\">Out of memory:Kill process or sacrifice child<\/a>\n\t<\/li>\n<\/ul>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=3373\">Out of memory:Kill process or sacrifice child<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u4e2a\u9519\u8bef\u540c\u6837\u4e0d\u5e38\u89c1\uff0c\u5f88\u5c11\u6709\u4eba\u9047\u5230\uff0c\u4f46\u5e76\u4e0d\u4ee3\u8868\u5b83\u4e0d\u5b58\u5728\uff01\u4eca\u5929\u5c31\u6765\u8bf4\u8bf4&nbsp;Out of memory: K [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,6],"tags":[1727,731,601,1114,1646],"class_list":["post-3373","post","type-post","status-publish","format-standard","hentry","category-java","category-yyzt","tag-java8","tag-jvm","tag-outofmemoryerror","tag-1114","tag-1646"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3373","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3373"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3373\/revisions"}],"predecessor-version":[{"id":3374,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3373\/revisions\/3374"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}