{"id":201364,"date":"2025-05-10T08:05:23","date_gmt":"2025-05-10T00:05:23","guid":{"rendered":"https:\/\/server.hk\/cnblog\/201364\/"},"modified":"2025-05-10T08:05:23","modified_gmt":"2025-05-10T00:05:23","slug":"%e8%a7%a3%e5%86%b3linux%e4%b8%8bredis%e6%95%b0%e6%8d%ae%e5%ba%93overcommit_memory%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/201364\/","title":{"rendered":"\u89e3\u51b3linux\u4e0bredis\u6570\u636e\u5e93overcommit_memory\u95ee\u9898"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u89e3\u51b3linux\u4e0bredis\u6570\u636e\u5e93overcommit_memory\u95ee\u9898<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u5bf9\u4e8e\u4e00\u4e2a\u6570\u636e\u5e93\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u7262\u56fa\u624e\u5b9e\u7684\u57fa\u7840\u662f\u5341\u5206\u91cd\u8981\u7684\uff0cgolang\u5b66\u4e60\u7f51\u5c31\u6765\u5e26\u5927\u5bb6\u4e00\u70b9\u70b9\u7684\u638c\u63e1\u57fa\u7840\u77e5\u8bc6\u70b9\u3002\u4eca\u5929\u672c\u7bc7\u6587\u7ae0\u5e26\u5927\u5bb6\u4e86\u89e3\u300a\u89e3\u51b3linux\u4e0bredis\u6570\u636e\u5e93overcommit_memory\u95ee\u9898\u300b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e86\u95ee\u9898\u3001linuxredis\u3001overcommit memory\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u5feb\u70b9\u6536\u85cf\u8d77\u6765\u5427\uff0c\u5426\u5219\u9700\u8981\u65f6\u5c31\u627e\u4e0d\u5230\u4e86\uff01<\/p>\n<h3>\u80cc\u666f<\/h3>\n<p>\u516c\u53f8\u7684redis\u6709\u65f6background save db\u4e0d\u6210\u529f\uff0c\u901a\u8fc7log\u53d1\u73b0\u4e0b\u9762\u7684\u544a\u8b66\uff0c\u5f88\u53ef\u80fd\u7531\u5b83\u5f15\u8d77\u7684\uff1a<\/p>\n<p>[13223] 17 Mar 13:18:02.207 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add &#8216;vm.overcommit_memory = 1&#8217; to \/etc\/sysctl.conf and then reboot or run the command &#8216;sysctl vm.overcommit_memory=1&#8217; for this to take effect.<\/p>\n<p>\u4e8e\u662f\u901a\u8fc7\u641c\u7d22\uff0c\u4e5f\u6709\u4eba\u8ddf\u6211\u9047\u5230\u540c\u6837\u7684\u95ee\u9898\uff0c\u57fa\u672c\u53ef\u4ee5\u786e\u5b9a\u662f\u7531\u5b83\u5f15\u8d77\u7684\u3002<\/p>\n<h3>\u5185\u6838\u53c2\u6570overcommit_memory&nbsp;<\/h3>\n<p>\u5b83\u662f <code>\u5185\u5b58\u5206\u914d\u7b56\u7565<\/code><\/p>\n<p>\u53ef\u9009\u503c\uff1a0\u30011\u30012\u3002<\/p>\n<ul>\n<li>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<\/li>\n<li>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<\/li>\n<li>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<\/li>\n<\/ul>\n<h3>\u4ec0\u4e48\u662fOvercommit\u548cOOM<\/h3>\n<p>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\u505aOvercommit\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<\/p>\n<p>\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\u4e14oom_score_adj\u53ef\u4ee5\u88ab\u8bbe\u7f6e(-1000\u6700\u4f4e\uff0c1000\u6700\u9ad8)\u3002<\/p>\n<h3>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/h3>\n<p>\u5f88\u7b80\u5355\uff0c\u6309\u63d0\u793a\u7684\u64cd\u4f5c\uff08\u5c06vm.overcommit_memory \u8bbe\u4e3a1\uff09\u5373\u53ef\uff1a<\/p>\n<p>\u6709\u4e09\u79cd\u65b9\u5f0f\u4fee\u6539\u5185\u6838\u53c2\u6570\uff0c\u4f46\u8981\u6709root\u6743\u9650\uff1a<\/p>\n<ul>\n<li>\uff081\uff09\u7f16\u8f91\/etc\/sysctl.conf \uff0c\u6539vm.overcommit_memory=1\uff0c\u7136\u540esysctl -p \u4f7f\u914d\u7f6e\u6587\u4ef6\u751f\u6548<\/li>\n<li>\uff082\uff09sysctl vm.overcommit_memory=1<\/li>\n<li>\uff083\uff09echo 1 &gt; \/proc\/sys\/vm\/overcommit_memory<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u89e3\u51b3linux\u4e0bredis\u6570\u636e\u5e93&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-201364","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201364","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=201364"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201364\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=201364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=201364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=201364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}