How to handle memory management via mmap properly?
<p>I'm trying to write my own <code>malloc</code> and <code>free</code> implementation for the sake of learning, with just <code>mmap</code> and <code>munmap</code> (since <code>brk</code> and <code>sbrk</code> are obsoletes). I've read a fair amount of documentation on the subject, but every example I see either use <code>sbrk</code> or doesn't explain very well how to handle large zones of mapped memory.</p>

<p>The idea of what I'm trying to write is this: I first map a big zone (i.e.  512 pages); this zone will contains all allocations between 1 and 992 bytes, in 16 bytes increments. I'll do the same later with a 4096 pages zone for bigger allocations (or mmap directly if the requested size is bigger than a page). So I need a way to store informations about every chunk that I allocate or free.</p>

<p>My question is, how do I handle these informations properly ?</p>

<p>My problematics are: If I create a linked list, how do I allocate more space for each node ? Or do I need to copy it to the mapped zone ? If so, how can I juggle between data space and reserved space ? Or is it better to use a static sized array ? Problem with this is that my zone's size depends on the page size.</p>