In this patch, a bump-like allocator is introduced to improve the efficiency of
target memory allocation and deallocation. The reason it is called a bump-like
allocator is it supports deallocation. Everytime a memory allocation request is
from the memory manager, it first checks whether there is a fitted slab. If not,
create a new slab. Bump the pointer in the slab and return to the memory manager,
like a regular bump allocator. We set a reference count for each slab to track
the number of memory requests from the slab.
Of course it is possible that we may run out of target memory. Then the memory
manager will try to release all its buffered memory in its FreeLists. For each
deallocation, the allocator first finds the slab it is from. If it cannot find
a slab, then it must be allocated directly on device so it will be deallocated
directly from the device. Otherwise, just decrease the reference count of the
slab. If the reference count is zero, which means all memory allocated are
returned. So we will call the device routine to deallocate the slab.
It is worth noting that the deallocation might only be called in three cases:
- Destructor of the memory manager;
- We are out of memory. The memory manager wants to free all its hold free memory;
- A large block of memory which is not allocated from a slab. For this case,
we might optimize it such that if the size is not too large, we may take it as
another slab when it is gonna be released by the memory manager.
Tests, comments, and debug output have not been added yet, but will soon.