TinyVMem is a public domain implementation of the VMem resource allocator first described in the paper “Magazines and Vmem: Extending the Slab Allocator to Many CPUs and Arbitrary Resources”
- VMem, despite its name, is not limited to allocation of virtual address space; it can deal with any sort of interval scale (for example, PIDs).
- Support for multiple allocation strategies such as best-fit and instant fit (constant time). Next-fit support is planned.
- Reduced fragmentation.
- Allows importing spans from other arenas.
TinyVMem is written in portable ANSI C therefore porting to a new platform should be easy enough.
If you’re running on a freestanding environment, you need to define the __KERNEL__
macro and the following functions/macros:
/* Allocates 'n' pages */
void *vmem_alloc_pages(size_t n);
/* Locks a global lock (defined by the user) */
void vmem_lock(void);
/* Locks a global lock (defined by the user) */
void vmem_unlock(void);
/* From libc's string.h */
char *strcpy(char *restrict dst, const char *restrict src);
/* Assertion */
#define ASSERT(...) assert
/* Printf-like function, can be ignored if you're not going to call vmem_dump() */
#define vmem_printf(...) printf
You also need to have a complete implementation of sys/queue.h
available. If not, I suggest you use netbsd’s.
- Implement support for next-fit allocation
- Implement support for VM_NOSLEEP and VM_SLEEP