Vincent
Vincent

Reputation: 530

Mlock error at mongo console opening - failed to mlock: Cannot allocate locked memory

I have just tried to install MongoDB on a fresh Ubuntu 18 machine.

For this I went through the tutorial from the website.

Everything went fine - including starting the server with 

sudo systemctl start mongod 

and checking that it runs with:

sudo systemctl status mongod

Only I can't seem to start a mongo console. When I type mongo, I get the following error:

2020-07-17T13:26:48.049+0000 F - [main] Failed to mlock: Cannot allocate locked memory. For more details see: https://dochub.mongodb.org/core/cannot-allocate-locked-memory: Operation not permitted
2020-07-17T13:26:48.049+0000 F - [main] Fatal Assertion 28832 at src/mongo/base/secure_allocator.cpp 255
2020-07-17T13:26:48.049+0000 F - [main]


***aborting after fassert() failure

I checked for the suggested link but there seems to be no limitation problem as resources are not limited (as per check with ulimit). Machine has 16Gb RAM. Any idea what the problem/solution might be?

EDIT: the process limits are:

Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            8388608              unlimited            bytes
Max core file size        0                    unlimited            bytes
Max resident set          unlimited            unlimited            bytes
Max processes             64000                64000                processes
Max open files            64000                64000                files
Max locked memory         unlimited            unlimited            bytes
Max address space         unlimited            unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       62761                62761                signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0
Max realtime priority     0                    0
Max realtime timeout      unlimited            unlimited            us

Upvotes: 3

Views: 3082

Answers (3)

Andrés
Andrés

Reputation: 66

If you use some sort of virtualization to deploy your machine, you need to make sure that the @memlock system calls are allowed. For example, for systemd-nspawn, check this answer:https://stackoverflow.com/a/69286781/16085315

Upvotes: 1

Alpy
Alpy

Reputation: 789

I just had this issue on my FreeBSD VM with mongodb following solved my issue as mentioned previously :

# sysctl vm.stats.vm.v_wire_count vm.max_wired
vm.stats.vm.v_wire_count: 1072281
vm.max_wired: 411615
# sysctl -w vm.max_wired=1400000
vm.max_wired: 411615 -> 1400000
# service mongod restart
Stopping mongod.
Waiting for PIDS: 36308.
Starting mongod.
Add the value for a long term set in /etc/sysctl.conf
vm.max_wired=1400000

v_wire_count should be less than max_wired

Upvotes: 0

Matt Simerson
Matt Simerson

Reputation: 1115

I was getting that exact error and that linked mongodb page wasn't helpful for me either. I'm running on FreeBSD and found a useful bit of detail in a bug report for the port. It turns out a system level resource limit was the underlying problem. On FreeBSD, the key are these two sysctl settings:

sysctl vm.stats.vm.v_wire_count vm.max_wired

v_wire_count should be less than max_wired. Increasing max_wired solved the issue for me.

Upvotes: 1

Related Questions