[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Behaviour of malloc()



Hi,

I vaguely remember seeing a post concerning how malloc() behaves in case
of "very big allocations". I've thrown the mail away, so if I'm
repeating an akready given answer, please forgive me.

While browsing kernel-documentation (Documentation/proc.txt) I found the
following information about the file /proc/sys/vm/overcommit_memory:
---
overcommit_memory
   This file contains one value. The following algorithm is used to
   decide if there's enough memory: if the value of overcommit_memory
   is positive, then there's always enough memory. This is a useful
   feature, since programs often malloc() huge amounts of memory 'just
   in case', while they only use a small part of it. Leaving this
   value at 0 will lead to the failure of such a huge malloc(), when
   in fact the system has enough memory for the program to run.

   On the other hand, enabling this feature can cause you to run out
   of memory and thrash the system to death, so large and/or important
   servers will want to set this value to 0.
---

So the behaviour can actually be controlled run-time :)

<nil> I love Linux.


-- 
    Fredrik Juhlin        laz@rjdk.com        http://www.rjdk.com/
    Cellular: +46 (0)709 52 40 72      Office: +46 (0)31 755 25 10
                                Quidquid latine dictum sit, altum viditur.


Reply to: