memory.f
Any time you allocate memory with a mmap syscall you are going to get a block of memory that is a multiple of 4k in size. This means that if you repeatedly allocate three byes of memory you are going to be repeatedly given 4096 bytes. You will be using only 3 bytes in each of these blocks so you will be wasting 4093 bytes of memory with each allocation.
This file allocates heaps of memory and on request sub-allocates pieces parts of those heaps for you with a granularity of 16 bytes. If you require a block of memory that is larger than the largest free block within any available heap then this code will allocate a new heap and give you a piece (or all) of that instead.
As you free up allocated blocks the code merges them with adjacent free blocks within the same heap which helps prevent fragmentation. When you free up all the allocated blocks within a heap this code will return that heap to the operating system.