redislinux-kernelyoctosystemdsysctl

How to solve a redis service warning about the kernel parameter vm.overcommit_memory?


On my Yocto based Linux distribution I have installed an instance of Redis 6.0.5 which use AOF persistence policy.

Because I'm having some problems with this instance of Redis Server I have checked the log of the systemd service redis.service by the command:

journalctl -u redis | less

In the output of this command I have found the following Warning:

redis-server[320]: 320:M 19 Feb 2025 15:40:12.802 # 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 th
is to take effect.

I'm trying to follow the suggestion provided by the warning, but on my system I don't find any file /etc/sysctl.conf. So I have tried to apply the other hint provided by the same warning, and I have executed the command:

sysctl vm.overcommit_memory=1

The previous command can be executed on my system without error and gives the output:

vm.overcommit_memory = 1

But when I restart my system the warning is always present on the journal of the redis service.

So I have tried to create a file /etc/sysctl.conf with the following content:

vm.overcommit_memory = 1

but when I reboot my system the warning is still present.

I have read some other posts about the same topic, for example this, but I haven't found a valid solution (many of the links use Docker, but it is not my case).

How can I solve this warning?


Solution

  • At this link I have found the following sentence:

    This man page describes the configuration files for procps sysctl. If you are using systemd-sysctl(8), refer to sysctl.d(5) and note that it won't use the file /etc/sysctl.conf.

    I have discovered that my Linux distribution is using systemd-sysctl and the previous sentence tells that systemd-sysctl doesn't use the configuration file /etc/sysctl.conf. In the sentence there is an other link and in it I have found that:

    At boot, systemd-sysctl.service(8) reads configuration files from the directories:
    /etc/sysctl.d/.conf
    /run/sysctl.d/
    .conf
    /usr/local/lib/sysctl.d/.conf
    /usr/lib/sysctl.d/
    .conf
    to configure sysctl(8) kernel parameters.

    So to set the parameter vm.overcommit_memory = 1 in my system, I have decided to set it by the configuration file /etc/sysctl.d/kernel_vm_overcommit_memory.conf; the content of this file is the following:

    vm.overcommit_memory = 1
    

    By the adding of this configuration file, and after a reboot, the kernel parameter is set to 1 as I can see by the execution of the following command:

    # sysctl -a | grep vm.overcommit_memory
    vm.overcommit_memory = 1
    

    and the redis-server service stops to give the warning:

    # 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.