有关linux下redis overcommit_memory的问题
来源:互联网 发布:linux线程优先级设置 编辑:程序博客网 时间:2024/04/30 01:01
背景
公司的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.
于是通过搜索,也有人跟我遇到同样的问题,基本可以确定是由它引起的。
内核参数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的问题
- 有关linux下redis overcommit_memory的问题
- 有关linux下redis overcommit_memory的问题
- 有关linux下redis overcommit_memory的问题
- 有关linux下redis overcommit_memory的问题
- 有关linux下redis overcommit_memory的问题
- 有关linux下redis overcommit_memory的问题
- 有关linux下redis overcommit_memory的问题
- linux下overcommit_memory的问题
- linux-overcommit_memory
- 有关 linux 下用 Graphics 画出中文的问题
- 有关linux下eclipse写C语言遇到的问题
- 有关Linux下的游戏
- overcommit_memory
- overcommit_memory
- overcommit_memory
- overcommit_memory
- overcommit_memory
- Android编译问题
- 一步步学习SPD2010--第十章节--SP网站品牌化(3)--在内容页中识别样式
- 如何一个android工程作为另外一个android工程的lib
- Zookeeper,Hbase,hadoop之间的联系
- 黑马程序员—OI流
- 有关linux下redis overcommit_memory的问题
- 线性代数(三十七) :欧几里得结构-标量积与余弦定理
- Yii rules的验证规则介绍
- Oralce常用技巧
- POJ 1458 Common Subsequence
- Java编程基础之初始化和清除
- linux上安装activeMQ
- AndEngine Example(7):EntityModifierExample
- 实现百度地图的身边雷达的功能效果