{"id":851,"date":"2021-08-19T17:59:41","date_gmt":"2021-08-19T09:59:41","guid":{"rendered":"https:\/\/www.zhuyanbin.com\/?p=851"},"modified":"2021-08-19T17:59:41","modified_gmt":"2021-08-19T09:59:41","slug":"linux%e7%9a%84vm-overcommit_memory%e7%9a%84%e5%86%85%e5%ad%98%e5%88%86%e9%85%8d%e5%8f%82%e6%95%b0%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/www.yanbin888.com\/?p=851","title":{"rendered":"Linux\u7684vm.overcommit_memory\u7684\u5185\u5b58\u5206\u914d\u53c2\u6570\u8be6\u89e3"},"content":{"rendered":"\n<p><strong>\u5185\u6838\u53c2\u6570overcommit_memory&nbsp;<\/strong><\/p>\n\n\n\n<p>\u5b83\u662f&nbsp;\u5185\u5b58\u5206\u914d\u7b56\u7565<\/p>\n\n\n\n<p>\u53ef\u9009\u503c\uff1a0\u30011\u30012\u3002<br \/>0\uff0c \u8868\u793a\u5185\u6838\u5c06\u68c0\u67e5\u662f\u5426\u6709\u8db3\u591f\u7684\u53ef\u7528\u5185\u5b58\u4f9b\u5e94\u7528\u8fdb\u7a0b\u4f7f\u7528\uff1b\u5982\u679c\u6709\u8db3\u591f\u7684\u53ef\u7528\u5185\u5b58\uff0c\u5185\u5b58\u7533\u8bf7\u5141\u8bb8\uff1b\u5426\u5219\uff0c\u5185\u5b58\u7533\u8bf7\u5931\u8d25\uff0c\u5e76\u628a\u9519\u8bef\u8fd4\u56de\u7ed9\u5e94\u7528\u8fdb\u7a0b\u3002<br \/>1\uff0c \u8868\u793a\u5185\u6838\u5141\u8bb8\u5206\u914d\u6240\u6709\u7684\u7269\u7406\u5185\u5b58\uff0c\u800c\u4e0d\u7ba1\u5f53\u524d\u7684\u5185\u5b58\u72b6\u6001\u5982\u4f55\u3002<br \/>2\uff0c \u8868\u793a\u5185\u6838\u5141\u8bb8\u5206\u914d\u8d85\u8fc7\u6240\u6709\u7269\u7406\u5185\u5b58\u548c\u4ea4\u6362\u7a7a\u95f4\u603b\u548c\u7684\u5185\u5b58<\/p>\n\n\n\n<p><strong>\u4ec0\u4e48\u662fOvercommit\u548cOOM<\/strong><\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;Linux\u5bf9\u5927\u90e8\u5206\u7533\u8bf7\u5185\u5b58\u7684\u8bf7\u6c42\u90fd\u56de\u590d&#8221;yes&#8221;\uff0c\u4ee5\u4fbf\u80fd\u8dd1\u66f4\u591a\u66f4\u5927\u7684\u7a0b\u5e8f\u3002\u56e0\u4e3a\u7533\u8bf7\u5185\u5b58\u540e\uff0c\u5e76\u4e0d\u4f1a\u9a6c\u4e0a\u4f7f\u7528\u5185\u5b58\u3002\u8fd9\u79cd\u6280\u672f\u53eb\u505a<strong>&nbsp;Overcommi<\/strong><strong>t<\/strong>\u3002\u5f53linux\u53d1\u73b0\u5185\u5b58\u4e0d\u8db3\u65f6\uff0c\u4f1a\u53d1\u751fOOM killer(OOM=out-of-memory)\u3002\u5b83\u4f1a\u9009\u62e9\u6740\u6b7b\u4e00\u4e9b\u8fdb\u7a0b(\u7528\u6237\u6001\u8fdb\u7a0b\uff0c\u4e0d\u662f\u5185\u6838\u7ebf\u7a0b)\uff0c\u4ee5\u4fbf\u91ca\u653e\u5185\u5b58\u3002<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u5f53oom-killer\u53d1\u751f\u65f6\uff0clinux\u4f1a\u9009\u62e9\u6740\u6b7b\u54ea\u4e9b\u8fdb\u7a0b\uff1f\u9009\u62e9\u8fdb\u7a0b\u7684\u51fd\u6570\u662foom_badness\u51fd\u6570(\u5728mm\/oom_kill.c\u4e2d)\uff0c\u8be5 \u51fd\u6570\u4f1a\u8ba1\u7b97\u6bcf\u4e2a\u8fdb\u7a0b\u7684\u70b9\u6570(0~1000)\u3002\u70b9\u6570\u8d8a\u9ad8\uff0c\u8fd9\u4e2a\u8fdb\u7a0b\u8d8a\u6709\u53ef\u80fd\u88ab\u6740\u6b7b\u3002\u6bcf\u4e2a\u8fdb\u7a0b\u7684\u70b9\u6570\u8ddfoom_score_adj\u6709\u5173\uff0c\u800c\u4e14 oom_score_adj\u53ef\u4ee5\u88ab\u8bbe\u7f6e(-1000\u6700\u4f4e\uff0c1000\u6700\u9ad8)\u3002<\/p>\n\n\n\n<p><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp;\u5f88\u7b80\u5355\uff0c\u6309\u63d0\u793a\u7684\u64cd\u4f5c\uff08\u5c06vm.overcommit_memory \u8bbe\u4e3a1\uff09\u5373\u53ef\uff1a<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp;\u6709\u4e09\u79cd\u65b9\u5f0f\u4fee\u6539\u5185\u6838\u53c2\u6570\uff0c\u4f46\u8981\u6709root\u6743\u9650\uff1a<\/p>\n\n\n\n<p>&nbsp;\uff081\uff09\u7f16\u8f91<strong>\/etc\/sysctl.conf<\/strong>&nbsp;\uff0c\u6539<strong>vm.overcommit_memory=1<\/strong>\uff0c\u7136\u540e<strong>sysctl -p<\/strong>\u4f7f\u914d\u7f6e\u6587\u4ef6\u751f\u6548<\/p>\n\n\n\n<p>&nbsp;\uff082\uff09<strong>sysctl vm.overcommit_memory=1<\/strong><\/p>\n\n\n\n<p>\u00a0\uff083\uff09<strong>echo 1 > \/proc\/sys\/vm\/overcommit_memory<\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Link: <a href=\"https:\/\/www.cnblogs.com\/zxc2man\/p\/12911427.html\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.cnblogs.com\/zxc2man\/p\/12911427.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5185\u6838\u53c2\u6570overcommit_memory&nbsp; \u5b83\u662f&nbsp;\u5185\u5b58\u5206\u914d\u7b56\u7565 \u53ef\u9009\u503c\uff1a0\u30011\u30012\u30020\uff0c <span class=\"ellipsis\">&hellip;<\/span> <span class=\"more-link-wrap\"><a href=\"https:\/\/www.yanbin888.com\/?p=851\" class=\"more-link\"><span>Read More &rarr;<\/span><\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[23],"class_list":["post-851","post","type-post","status-publish","format-standard","hentry","category-linux","tag-linux"],"_links":{"self":[{"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/posts\/851","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=851"}],"version-history":[{"count":1,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/posts\/851\/revisions"}],"predecessor-version":[{"id":852,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/posts\/851\/revisions\/852"}],"wp:attachment":[{"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=851"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=851"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=851"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}