Re: Memory allocation troubles



On Tue, 19 Oct 2004 11:09:08 -0400, John Vetterli <jvetterli linux ca> wrote:
[...]
If you're running this program on Linux, you have a bit of a problem.
When a process asks the Linux kernel for more memory, the kernel
increases size of the process' data segment, but does not actually
assign physical memory (ram or swap) until the program tries to access
it.  So while the initial call to malloc (and therefore g_new) may
succeed, your program may still be suddenly terminated if the system
runs out of memory.

From the linux malloc(3) manpage:
  "Linux follows an optimistic memory allocation strategy.  This means
  that when malloc() returns non-NULL there is no guarantee that the
  memory really is available.  In case it turns  out  that  the system
  is out of memory, one or more processes will be killed by the infamous
  OOM killer."

Theese are really extreme cases though, (A good example is when you are
running a JVM and the JVM has allocated an excesive amount of threads,
in which case the thread meta-data is not swappable and is polluting physical
memory).
    I may be mistaken, but I believe that the MM will refuse to
allocate virtual
memory addresses when it knows it cant possibly allocate that much memory
in physical addresses even when swapping out all other proceeses (And thats
probably something like 90% or 95% of available physical memory for
a user process).

Cheers,
                                                    -Tristan



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