问题
I'm performing a pressure test with leveldb.
In util/env_poisx.cc : NewRandomAccessFile()
void* base = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
after 3 million data (each 100k) insert. The errno says Cannot allocate memory
.
why?
More details:
top:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
19794 root 20 0 290g 4.9g 4.7g S 98.6 7.8 2348:00 ldb
free -m:
total used free shared buffers cached
Mem: 64350 60623 3726 0 179 59353
-/+ buffers/cache: 1090 63259
Swap: 996 0 996
ulimit -a:
core file size (blocks, -c) unlimited
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
pending signals (-i) 1024
max locked memory (kbytes, -l) 32
max memory size (kbytes, -m) unlimited
open files (-n) 10240
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 530432
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
sysctl:
vm.max_map_count = 300000
kernel.shmmni = 8092
kernel.shmall = 4194304
kernel.shmmax = 2147483648
回答1:
man mmap:
"ENOMEM No memory is available, or the process's maximum number of mappings would have been exceeded."
When you write "3 million data (each 100k)", it seems to correlate with vm.max_map_count is 300000. Try to change this limit if you sure you have enough memory.
Please give /proc/[pid]/maps | wc -l when error happening
来源:https://stackoverflow.com/questions/12667397/mmap-returns-can-not-allocate-memory-even-though-there-is-enough