Discussion:
Custom Memory Allocator
Jim Burnes
2014-06-23 20:17:30 UTC
Permalink
I'm developing a small distributed OS kernel that can be hosted on POSIX,
Windows etc and includes a LuaJIT VM subsystem to run user space programs
and scripts.

The kernel is a derivative of another kernel that:

1. Includes it's own allocator which divides the world into
(a) kernel memory pool
(b) VM pool
(c) multimedia pool (graphics, audio)

2. Currently I have an early version of the OS running where both the
kernel and LuaJIT use the kernel's malloc allocator. For reasons of
organization, memory "protection" and max memory control I'd like to
fulfill LuaJIT's malloc calls from the VM pool.

3. So I thought I'd just hook into LuaJITs malloc calls and tell it to
request memory from the OS VM pool to keep things neat and clean.

4. Then I found out that LuaJIT can use it's own custom version of Doug
Lea's dmalloc, which is probably much more evolved than the one in my
kernel.

My question (and I know question's like this are usually answered by "it
depends"), but any suggestions on documents to read to integrate the LuaJIT
custom dmalloc cleanly into my system?

There are only a couple features which would need to be implemented in any
allocator:

a) obviously the ability to use it via the standard malloc/free interface
for the kernel code that assumes it's memory is allocated from a default
(kernel) pool.

b) within LuaJIT, the ability to specify from which pool I want to allocate
memory.

I'll continue reading the LuaJIT sources, but any good tips are greatly
appreciated.

thx,

jim burnes

Loading...