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

malloc()

POSIX compliant malloc implementation.

free()

POSIX compliant free implementation.

Kernel-mode API.

API Description

BT_kMalloc()

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

BT_kFree()

Frees a kernel memory allocation.

bt_ioremap()

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

Page Allocation

API Description

bt_page_alloc()

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

bt_page_free()

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:

os/include/syslog/bt_printk.h

See the implementation under:

os/src/syslog/bt_printk.c

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

Back