26

On a fresh Ubuntu 16.04 EC2 instance the warnings appear like so:

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.
WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.

How to eliminate them permanently?

legel
  • 2,507
  • 3
  • 23
  • 22

2 Answers2

20

Like the warning suggests, just add the line vm.overcommit_memory=1 to the bottom of /etc/sysctl.conf, with something like sudo vi /etc/sysctl.conf.

But permissions don't allow you to edit THP as the warning suggests, so instead do

sudo apt install hugepages

and add the command sudo hugeadm --thp-never to the bottom of your .bashrc, with something like sudo vi ~/.bashrc.

Then just sudo reboot and next time you SSH in run redis-server and the warnings are gone!

legel
  • 2,507
  • 3
  • 23
  • 22
  • 4
    Is simply making the warning go away dangerous at all? When would it be desirable for a 'background save' to fail under low memory conditions? Could it be problematic to just blindly set 'vm.overcommit_memory=1'? – Scott Skiles Jan 10 '18 at 18:53
  • @ScottSkiles: I believe Redis does a background save by calling `fork()` which immediately **doubles** the apparent memory use. But since it is all virtual memory until things change in the parent, things should be OK until the save finishes. – Zan Lynx Jul 20 '18 at 22:59
  • 17
    how to do that in docker container? – Heril Muratovic Mar 29 '19 at 21:58
  • 1
    @HerilMuratovic according to discussions I've seen on github, these settings (probably) go on the host system and docker gets them from there. E.g.: https://github.com/docker-library/redis/issues/19#issuecomment-96080885 – Kostas Mouratidis Jul 14 '19 at 13:17
3

With Linux and Ubuntu, I did this before running redis-server, and it seems to work...

sudo add-apt-repository ppa:redislabs/redis
sudo apt-get update
sudo apt-get install redis

https://redis.io/download

Dhia Djobbi
  • 1,176
  • 2
  • 15
  • 35
  • Nice, it appears to be a better fix (achieved with the native library). If someone can verify that this solves the problem, then I'll award this as the new best answer. – legel May 09 '21 at 03:33
  • 2
    In my case, upgrading redis to v.6.2.6 via the indicated PPA removed the Transparent Huge Page warning, but NOT the overcommit_memory one – Giuseppe Jan 22 '22 at 14:05