日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

有关linux下redis overcommit_memory的问题,以及导致的:Cannot allocate memory问题

發布時間:2024/9/27 linux 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 有关linux下redis overcommit_memory的问题,以及导致的:Cannot allocate memory问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

背景

公司的redis有時background save db不成功,通過log發現下面的告警,很可能由它引起的:

[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

內核參數overcommit_memory

它是 內存分配策略

可選值:0、1、2。
0, 表示內核將檢查是否有足夠的可用內存供應用進程使用;如果有足夠的可用內存,內存申請允許;否則,內存申請失敗,并把錯誤返回給應用進程。
1, 表示內核允許分配所有的物理內存,而不管當前的內存狀態如何。
2, 表示內核允許分配超過所有物理內存和交換空間總和的內存

什么是Overcommit和OOM

Linux對大部分申請內存的請求都回復"yes",以便能跑更多更大的程序。因為申請內存后,并不會馬上使用內存。這種技術叫做Overcommit。當linux發現內存不足時,會發生OOM killer(OOM=out-of-memory)。它會選擇殺死一些進程(用戶態進程,不是內核線程),以便釋放內存。當oom-killer發生時,linux會選擇殺死哪些進程?選擇進程的函數是oom_badness函數(在mm/oom_kill.c中),該函數會計算每個進程的點數(0~1000)。點數越高,這個進程越有可能被殺死。每個進程的點數跟oom_score_adj有關,而且oom_score_adj可以被設置(-1000最低,1000最高)。

解決方法:

很簡單,按提示的操作(將vm.overcommit_memory 設為1)即可:有三種方式修改內核參數,但要有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问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。