[uClibc]Re: malloc, munmap, etc...

Miles Bader miles at lsi.nec.co.jp
Thu Oct 31 01:40:26 UTC 2002

Uwe Beutin <uwe at imbrium.de> writes:
> I'm a little confused about the stories I've read about malloc() in the
> list. I'm using uClinux-dist-20020927 with the uClibc and running three
> applications where I have taken thorough precautions that any
> malloc()'ed memory is also free()'d.
> But with time moving on, I can see that the free memory keeps degrading 
> slowly but surely and at some point (a couple of days, depending) I get 
> a Kernel Panic (out of Memory) and have to reset.

Well, first of all, you should give some more information:

  * What kernel are you running (in uClinux-dist-20020927 at least,
    there are two -- 2.0.x and 2.4.x)?  What processor architecture?

  * Which malloc are you using (in your uClibc `Config' file, there's a
    line that says `MALLOC = ...', which should give that info).

  * Are your programs continually running, or do they periodically exec
    new programs and exit etc.?

  * Are you getting messages on the console like:

      munmap of non-mmaped memory by process PID (NAME): ADDR

I'm not sure what version of uClibc is included in uClinux-dist-20020927
(in fact I didn't even know there _was_ a uClinux-dist-20020927, since
the uClinux mailing list is apparently dead :-( ), but there has been
at least one important change for uClinux in the `MALLOC = malloc'
version of malloc, which could fix a memory leak.

On the other hand, if you're using `MALLOC = malloc-simple', then
malloc/free calls are translated directly to kernel calls, so your
observations would point to a possible kernel bug.

It would be useful to have more concrete information about how the
process sizes are growing/shrinking (if the process sizes _aren't_
growing and you're still running out of memory, then there's a kernel
bug).  The version of ps on my uClinux (which I think is the busybox
version) doesn't correctly print process memory sizes, but you can see
how much memory your processes are using by doing `cat /proc/PID', where
PID is the process-id of your process.

Anyway, give some more details.


The secret to creativity is knowing how to hide your sources.
  --Albert Einstein

More information about the uClibc mailing list