Sunday, February 20, 2022

[SOLVED] redis bgsave failed because fork Cannot allocate memory

Issue

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

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

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 .

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

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


Solution

From proc(5) man pages:

/proc/sys/vm/overcommit_memory

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

0: heuristic overcommit (this is the default)

1: always overcommit, never check

2: always check, never overcommit

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.



Answered By - Utoah
Answer Checked By - Katrina (WPSolving Volunteer)