Can the maximum malloc size stand out?

my os is a 64 bit bit.

free -m result below

  total used free shared buffers cached
 Mem: 32172 31909 262 0 119 13054
 - / + buffers / cache: 18735 13436
 Swap: 258,258 0
  ulimit -a
 core file size (blocks, -c) unlimited
 data seg size (kbytes, -d) unlimited
 scheduling priority (-e) 20
 file size (blocks, -f) unlimited
 pending signals (-i) 257329
 max locked memory (kbytes, -l) 64
 max memory size (kbytes, -m) unlimited
 open files (-n) 1024
 pipe size (512 bytes, -p) 8
 POSIX message queues (bytes, -q) 819200
 real-time priority (-r) 0
 stack size (kbytes, -s) 8192
 cpu time (seconds, -t) unlimited
 max user processes (-u) 257329
 virtual memory (kbytes, -v) unlimited
 file locks (-x) unlimited

kenerl overcommit_memroy parameter is 0

But when I try to use malloc to allocate 2G bytes, I cannot for this reason: can not allocate memory?

+7
source share
1 answer

In fact, it can be anything. It may have worked before because free memory was all continuous, and now there is no free memory, or it may be that your memory request does not allow the use of heuristics.

see this link here - http://linuxtoolkit.blogspot.com/2011/08/tweaking-linux-kernel-overcommit.html - for more information on how to enable excess information.

Basically:

  • 0 = system heuristically determines if overcommit is allowed
  • 1 = always overcommit (even if from a range of addresses, so stupid if you ask me)
  • 2 = never recompile past specific restrictions
+3
source

All Articles