mongodbdocker

mongodb docker vm.max_map_count is too low even if set to 524288


mongodb run as docker container always gives the warning 'vm.max_map_count is too low' if I enter mongosh.

vm.max_map_count is set to 524288 in the host system permanently. If I run 'docker exec mongodb sysctl vm.max_map_count' (mongodb is the container name) the result is vm.max_map_count = 524288. So I assume the setting is replicated inside the container correctly.

Tried different values, different hosts (all ubuntu 22.04), always the same on every mongodb running in docker container. Restarting or recreating didn't help. If I run the mongod directly on the host, the warning is not shown.

Any ideas?


Solution

  • Each network connection requires 2 mapped virtual memory areas.

    When mongod starts up, it checks the value from /proc/sys/vm/max_map_count to ensure it is at least double the maximum permitted number of inbound connections.

    That warning is generated here: https://github.com/mongodb/mongo/blob/r8.0.0/src/mongo/transport/transport_layer_manager_impl.cpp#L223-L2466

    Specifically:

    requiredMapCount = 2 * maxConns
    

    So there is no absolute value that triggers the warning, it is just pointing out to you that if your server actually tries to accept all of the connections allowed by net.maxIncomingConnections, it will not have enough maps, which will trigger as posix error, probably assertion failure, and possibly cause the mongod to crash.

    If you think 524288 is enough maps, reduce the number of allowed incoming connections 262144 or less.