redis bgsave 失败,因为 fork 无法分配内存 [英] redis bgsave failed because fork Cannot allocate memory

查看:44
本文介绍了redis bgsave 失败,因为 fork 无法分配内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部:这是我的服务器内存信息,带有 'free -m'

all: here is my server memory info with 'free -m'

              total       used       free     shared    buffers     cached
 Mem:         64433       49259      15174          0          3         31
 -/+ buffers/cache:      49224      15209
 Swap:         8197        184       8012

我的redis-server已经使用了46G内存,还有差不多15G内存空闲

my redis-server has used 46G memory, there is almost 15G memory left free

据我所知,fork 是写时复制,当有 15G 空闲内存时它应该不会失败,这足以 malloc 必要的内核结构.

As my knowledge,fork is copy on write, it should not failed when there has 15G free memory,which is enough to malloc necessary kernel structures .

另外,当redis-server使用42G内存时,bgsave可以,fork也可以.

besides, when redis-server used 42G memory, bgsave is ok and fork is ok too.

是否有任何我可以调整的 vm 参数以使 fork 返回成功?

Is there any vm parameter I can tune to make fork return success ?

推荐答案

来自 proc(5) 手册页:

/proc/sys/vm/overcommit_memory

/proc/sys/vm/overcommit_memory

该文件包含内核虚拟内存记帐方式.值为:

This file contains the kernel virtual memory accounting mode. Values are:

0:启发式过量使用(这是默认值)

0: heuristic overcommit (this is the default)

1:总是过量使用,从不检查

1: always overcommit, never check

2:始终检查,永远不要过量

2: always check, never overcommit

模式0下,不检查设置了MAP_NORESERVE的mmap(2)调用,默认检查很弱,导致进程OOM-killed"的风险.在 Linux 2.4 下任何非零值都表示模式 1.在模式 2(自 Linux 2.6 起可用)中,系统上的总虚拟地址空间被限制为 (SS + RAM*(r/100)),其中 SS 是大小交换空间的大小,RAM是物理内存的大小,r是文件/proc/sys/vm/overcommit_ratio的内容.

In mode 0, calls of mmap(2) with MAP_NORESERVE set are not checked, and the default check is very weak, leading to the risk of getting a process "OOM-killed". Under Linux 2.4 any non-zero value implies mode 1. In mode 2 (available since Linux 2.6), the total virtual address space on the system is limited to (SS + RAM*(r/100)), where SS is the size of the swap space, and RAM is the size of the physical memory, and r is the contents of the file /proc/sys/vm/overcommit_ratio.

这篇关于redis bgsave 失败,因为 fork 无法分配内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆