Question

I am currently working on a bare metal project with an arm processor using GCC arm compiler. If I call malloc, is the allocated memory tracked in the MMU? For some reason I had assumed an OS typically handled this but since the call to malloc compiles and I see it is defined in the libc/usr/include I am now thinking that the os implements another layer of memory management on top of the hardware management.
I guess i've got two questions: With full os (posix or windows) is the hardware tracking the allocated memory or is the os? With arm compiler is is the hardware tracking the allocated memory or is the os?

Was it helpful?

Solution

Memory allocation by malloc is mostly a software function.  Typically the blocks allocated by software are too small for the MMU to manage.  For example, an MMU typically manages pages of size 4k or larger.  In fact, the larger the pages, the more efficient the hardware can be.  Hardware also manages pages on page aligned boundaries (often like 4k), so, page sizes and alignments don't always correspond to software allocation sizes and alignment requirements.

TL;DR, software memory allocation is somewhat independent of hardware page management, as software carves (and releases) both small objects and larger arrays out of the available address space, while hardware manages the working set in terms of resident pages.

Licensed under: CC-BY-SA with attribution
scroll top