As you know mmap
and malloc
are non-deterministic on a system with Address Space Layout Randomization. To make my memory allocation deterministic, I use mmap
to reserve a very large address space (on a 64 bit system) with no swap space, that is, using MAP_NORESERVE. Then as I require memory, I assign 10 MB of space by doing mmap
with MAX_FIXED within that address space range. Therefore, the memory allocated grows linearly.
When I need to free
memory, I just unmap it using use munmap
. Moreover, I don't reutilize the address space which has been unmapped, but keep on allocating ahead. I guess this doesn't really affect anything as my address space (allocated with mmap
with MAP_NORESERVE) is very large anyway.
Now, the question is, how good a memory allocator is this. It ofcourse isn't a very smart one, as it cannot allocate small chunks of memories, as through mmap
you allocate at least 4096 bytes of memory, but I guess its still quite a workable solution. What do you think?
Also, what for the case where a process allocates memory of factor 4096 only. In that scenario, I think this approach wouldn't be inferior to malloc
.
EDIT
Note that I'm talking about determinism with respect of two identical redundant processes. One is forked from another, so it gets the initial address of the mmaped region with MAP_NORESERVE, as I do fork
afterwards.