Hi Tiberiu,

Tiberiu Motoc wrote:
I have some questions about memory allocation in uClinux for the ARM architecture. I found out that there are 2 memory allocation functions: malloc and malloc-simple. I think the article was on Blackfin, but I think same applies to ARM. Anyway, I also read that malloc-simple doesn't exist anymore, and it actually replaced malloc. Is this true?

Well, over the years there have been a few different implementations
of malloc. But for the most part I think most people now just use
the uClibc's simple malloc on most non-MMU platforms.


Also, I have a question about how the stack and the heap of a process. The stack is defined at compile time,

Yes.


however how does the heap grow at run time without VM?

It grows by asking the kernel to give it more memory - using mmap
on non-MMU systems. The memory will mostly likely not be contiguous
with any previous allocations.


I read that uClinux manages the free space using a global pool.

Yes, in fact it relys on the kernels global memory pool. The kernel
does the hard work of managing the allocated memory.


Is the heap of a process grown contiguously in the global pool?

No.


If yes, then what happens if another process gets loaded and the heap of the first process overwrites the second process? If no, then how is this possible to manage without a VM?

Trivially easy as it turns out. You call malloc(), you get some
memory, it will be a single contiguous chunk. Everything works
as expected.


I also read that uClinux developers need to be aware of memory fragmentation and "try to utilize smaller allocation blocks". What exactly does that mean? Does it mean that it is better to have "for i = 1 to 1000 { malloc(1) }" than "malloc(1000)"?

In this example it is better to malloc(1000) than 1000 malloc(1)'s.
Lots of small allocations is slow and generally not good for
fragmentation.

"Small" in this case is a relative thing. Large allocations (especially
say larger than about 64k) can be difficult for the kernel/mmap to
satisfy - due to fragmentation, after the system has been running for
a while. Allocations of around 4k should always be simple to allocate -
up until you run out of memory anyway.


I apologize if the questions are too naive, but I spent a long time in a non-C environment and it is tough to get back on the horse now.

Hope that helps.

Regards
Greg



------------------------------------------------------------------------
Greg Ungerer  --  Chief Software Dude       EMAIL:     [EMAIL PROTECTED]
Secure Computing Corporation                PHONE:       +61 7 3435 2888
825 Stanley St,                             FAX:         +61 7 3891 3630
Woolloongabba, QLD, 4102, Australia         WEB: http://www.SnapGear.com
_______________________________________________
uClinux-dev mailing list
[email protected]
http://mailman.uclinux.org/mailman/listinfo/uclinux-dev
This message was resent by [email protected]
To unsubscribe see:
http://mailman.uclinux.org/mailman/options/uclinux-dev

Reply via email to