有关linux下redis overcommit_memory的问题,以及导致的:Cannot allocate memory问题
背景
公司的redis有時background save db不成功,通過log發(fā)現(xiàn)下面的告警,很可能由它引起的:[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 ‘vm.overcommit_memory = 1’ to /etc/sysctl.conf and then reboot or run the command ‘sysctl vm.overcommit_memory=1’ for this to take effect.
于是通過搜索,也有人跟我遇到同樣的問題,基本可以確定是由它引起的。
該配置導致的java啟動問題有
ava HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00007f0a0a475000, 65536, 1) failed; error=',' (errno=12) # # There is insufficient memory for the Java Runtime Environment to continue. # Native memory allocation (mmap) failed to map 65536 bytes for committing reserved memory. # An error report file with more information is saved as: # /root/.jenkins/workspace/aplan.dev.xxxx/properties-pom/hs_err_pid1189.log # # Compiler replay data is saved as: # /root/.jenkins/workspace/aplan.dev.xxxx/properties-pom/replay_pid1189.log [aplan.dev.xxxx] $ /bin/sh -xe /tmp/jenkins1610945537852977915.sh /root/.jenkins/workspace/aplan.dev.xxx/qt360-web/target/xxxx: No such file or directory Build step 'Execute shell' marked build as failure ERROR: Maven JVM terminated unexpectedly with exit code 1 SSH: Current build result is [FAILURE], not going to run. Finished: FAILURE內核參數(shù)overcommit_memory
它是 內存分配策略
可選值:0、1、2。
0, 表示內核將檢查是否有足夠的可用內存供應用進程使用;如果有足夠的可用內存,內存申請允許;否則,內存申請失敗,并把錯誤返回給應用進程。
1, 表示內核允許分配所有的物理內存,而不管當前的內存狀態(tài)如何。
2, 表示內核允許分配超過所有物理內存和交換空間總和的內存
什么是Overcommit和OOM
Linux對大部分申請內存的請求都回復"yes",以便能跑更多更大的程序。因為申請內存后,并不會馬上使用內存。這種技術叫做Overcommit。當linux發(fā)現(xiàn)內存不足時,會發(fā)生OOM killer(OOM=out-of-memory)。它會選擇殺死一些進程(用戶態(tài)進程,不是內核線程),以便釋放內存。當oom-killer發(fā)生時,linux會選擇殺死哪些進程?選擇進程的函數(shù)是oom_badness函數(shù)(在mm/oom_kill.c中),該函數(shù)會計算每個進程的點數(shù)(0~1000)。點數(shù)越高,這個進程越有可能被殺死。每個進程的點數(shù)跟oom_score_adj有關,而且oom_score_adj可以被設置(-1000最低,1000最高)。解決方法:
很簡單,按提示的操作(將vm.overcommit_memory 設為1)即可:有三種方式修改內核參數(shù),但要有root權限:(1)編輯/etc/sysctl.conf ,改vm.overcommit_memory=1,然后sysctl -p 使配置文件生效
(2)sysctl vm.overcommit_memory=1
(3)echo 1 > /proc/sys/vm/overcommit_memory
總結
以上是生活随笔為你收集整理的有关linux下redis overcommit_memory的问题,以及导致的:Cannot allocate memory问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 全球购骑士卡怎么消费
- 下一篇: 零钱通有什么用