Memory Manager

The memory manager is responsible for managing all memory within BitThunder. For systems with MMU’s the mm, is also responsible for managing all virtual memory mappings for each process.

User-space Memory Allocation API.

API Description


POSIX compliant malloc implementation.


POSIX compliant free implementation.

Kernel-mode API.

API Description


Allocates arbitrary amounts of memory for use in the kernel, e.g. drivers etc.


Frees a kernel memory allocation.


Remaps a physical address to a usable virtual address. THIS MUST BE USED EVEN WITH NO MMU.

Page Allocation

API Description


Allocates page-aligned, page multiples of atleast the requested size.


Frees page-aligned memory as requested from bt_page_alloc().

Design Overview

The memory manager has a few different implementations which are used depending on the kernel configurations.

Basic MM

Typical micro-controller applications use a mono-lithic, space-efficient heap. The heap consists of a free linked list, and the heap structure is stored within the heaps memory directly. This means its possible for threads/processes to cause heap corruption.

Powerful MM (Page based and Virtual Memory Management)

In these more powerful systems with MMUs, its possible to configure support for page based memory allocations and optionally virtual memory if desired.

The page based allocator becomes the lowest-level memory allocator on which the kernel heap, and process heaps are based.

The kernel heap is really efficient SLAB based algorithm, with all O(1) constant time operations.

To be implemented:

  • mmap()
  • User-space heaps.

In progress

  • vmalloc() api - Virtual memory allocation and mappings.

Further Reading

The full API is defined under:


See the implementation under:


os/src/mm/slab.c os/src/mm/bt_page.c