[uClibc]Malloc problems on uClinux/ARM

Thuys, Michiel michiel.thuys at intersil.com
Wed Feb 14 15:37:28 UTC 2001


Hi all,

I'm using the latest uClibc malloc (the default malloc, not malloc-simple or
malloc-930716) on an ARM9 running uClinux. I Experience the following problem:

When allocating and freeing a small amount of memory (<256 bytes), the memory
isn't freed. This is caused by the following: Allocating <256 bytes of memory is
done by the hunk manager. When freeing such a small area, the start of the hunk
is found by the macro "PAGE_DOWNALIGNP". In our case, it aligns down to a
page_size of 4096. So for example, a pointer of 0x81ea056 is aligned at
0x81ea000. However, this is not the location of the Hunk struct, since the mmap
that allocated the hunk returned  0x81ea018 instead of 0x81ea000! Therefore, the
start of the hunk cannot be found and the memory can't be freed. The 24 bytes
difference between a 4096 page boundary and the address mmap returns are the
page_descriptor and the block_header of kmalloc.

When I look at the code, it seems to me that all targets with a 4096 page size
should suffer from the same problem. Therefore I wonder if anyone has
experienced the same and knows a solution to it.

Furthermore, mmapping '4096' bytes seems to be inefficient, since kmalloc
allocates 8192-24 bytes for size > 4096-24. Isn't it much more efficient to mmap
4096-24 bytes?

Michiel Thuys






More information about the uClibc mailing list