Skip to content
Lucretia edited this page Dec 5, 2012 · 4 revisions

Memory model

Memory management is one of the most complex areas in an OS as there needs to be multiple levels, usually there area kernel routines, i.e. kmalloc, kfree, then there are syscalls which handle the allocation, freeing and extending of the address space at page granularity. e.g. mmap, munmap, sbrk, and then there are user-level routines, e.g. malloc and free, which handle the actual byte granularity of the memory blocks.

We will have a flat memory model with paging from the start, this will make any ports to modern hardware a lot easier. We can also follow the *nix path of having the process implement a container for the memory pages, threads and other resources.

Program sections

Each ELF binary consists of Text, Data, BSS sections, as is usual, the Text and BSS sections are of a set size, so the Text section will be loaded at address 0, followed by BSS, initialised to zero followed by the data section which will contain thread stacks and the heap.

+---------+ 16#0000_0000#
|  Text   |
|         |
|         |
|         |
+---------+
|   BSS   |
+---------+
|  Data   |
|         |
|  Stack  |
|  Stack  |
|  Stack  |
|   \/    |
|         |
|   /\    |
|  Heap   |
+---------+ 16#FFFF_FFFF#

We may not load the application to start on the first page, sometimes it's useful to have any access to address 0 cause a hardware exception.

As can be seen stacks grow downwards and the heap grows upwards in memory, they may converge at some point, at which time the memory will be exhausted; on demand paging and alleviate this by sending pages to disk. We will not be implementing demand paging at this time; this will be considered future work.

Clone this wiki locally