Allocator pondering
Posted: Sat Oct 13, 2007 12:18 am
Yes, as always, I am pondering allocators.
Funnily enough, Im still pondering on interesting ways to implement a buddy allocator (the other allocator design I was working on has gotten slightly boring for now, so... here we are).
A long while ago, I remember JNC spoke of an allocator he created, which was bitmap powered. IIRC, Seperate bitmaps for each granularity.
Back around then, I implemented a clone of the design he spoke of, did some basic benchmarks and found it would be usable in a real system even though it had a relatively high count in clock cycles for a the entire managed address space to be split into blocks of the minimum granularity.
So, I began to ponder...
and wander.
And ponder some more.
Much time passed, many bad things happened and life, oh life, how it has changed.
Out of the recent carnage, I have sat down and started tinkering an alternative design for my buddy allocator. Unlike JNCs, it is powered by an AVL tree. Well, multiple AVL trees.
Now, I get the feeling that a lot of people will cringe about this, yknow, since Trees typically have large overhead and/or node structure (pointers, etc). But, because I strive to be an eager-beaver, I have managed to cut down the node size insanely.
I have ended up encoding the following into 8bytes.
If anyone has any idea on how I could make it 4bytes, please speak up...
- 3 node pointers (left, parent, right).
- node balance
- block address and size.
+ a few of the bits left over being used to make the AVL code slightly
easier.
The idea is similar, I have an two arrays of trees. A tree for each granularity, one for blocks of granularity size in use and available.
Anyway, the question here... isnt about the internals of my little idea, but more in the tone of... Would using an AVL tree for this kind of system (Addresses can be in random order, but are typically ascending... lookup must be fast, for finding blocks of requested size, or freeing blocks of requested size, aswell as merging blocks... which, the AVL's property of sorting will make deviously easy...) actually be worthwhile, considering the somewhat massive increase in overhead?
ie: Would the speed gain be WORTH the gain in overhead?
Ie, Lets say we are tracking 8MiB of space, total. Minimum granularity is 4K.
Using JNC's system, it would take around ~520 to ~540 bytes to store bitmaps, tracking granularities 4K to 8MiB. Using my system, it would take 16KiB. In this case, my system uses roughly 31 times the space JNC's requires.
Point is, would it actually be worth it? In terms of performance? Or, is this not really a straightforward question? Does it depend more on... say, Is the buddy allocator going to be in use a GREAT deal? Or is it one of those deeply burried Kernel subsystems that is called once in a while...
If it is called once in awhile, then it is relatively acceptable for it to be a tad slow. If it is going to be called a great deal, in short succession, then it really does need to be as fast as possible. Right?
Anyways, as usual, any feedback on this matter would be greatly appreciated.
Id be really quite interested to see what your opinions are on this
~Z
Funnily enough, Im still pondering on interesting ways to implement a buddy allocator (the other allocator design I was working on has gotten slightly boring for now, so... here we are).
A long while ago, I remember JNC spoke of an allocator he created, which was bitmap powered. IIRC, Seperate bitmaps for each granularity.
Back around then, I implemented a clone of the design he spoke of, did some basic benchmarks and found it would be usable in a real system even though it had a relatively high count in clock cycles for a the entire managed address space to be split into blocks of the minimum granularity.
So, I began to ponder...
and wander.
And ponder some more.
Much time passed, many bad things happened and life, oh life, how it has changed.
Out of the recent carnage, I have sat down and started tinkering an alternative design for my buddy allocator. Unlike JNCs, it is powered by an AVL tree. Well, multiple AVL trees.
Now, I get the feeling that a lot of people will cringe about this, yknow, since Trees typically have large overhead and/or node structure (pointers, etc). But, because I strive to be an eager-beaver, I have managed to cut down the node size insanely.
I have ended up encoding the following into 8bytes.
If anyone has any idea on how I could make it 4bytes, please speak up...
- 3 node pointers (left, parent, right).
- node balance
- block address and size.
+ a few of the bits left over being used to make the AVL code slightly
easier.
The idea is similar, I have an two arrays of trees. A tree for each granularity, one for blocks of granularity size in use and available.
Anyway, the question here... isnt about the internals of my little idea, but more in the tone of... Would using an AVL tree for this kind of system (Addresses can be in random order, but are typically ascending... lookup must be fast, for finding blocks of requested size, or freeing blocks of requested size, aswell as merging blocks... which, the AVL's property of sorting will make deviously easy...) actually be worthwhile, considering the somewhat massive increase in overhead?
ie: Would the speed gain be WORTH the gain in overhead?
Ie, Lets say we are tracking 8MiB of space, total. Minimum granularity is 4K.
Using JNC's system, it would take around ~520 to ~540 bytes to store bitmaps, tracking granularities 4K to 8MiB. Using my system, it would take 16KiB. In this case, my system uses roughly 31 times the space JNC's requires.
Point is, would it actually be worth it? In terms of performance? Or, is this not really a straightforward question? Does it depend more on... say, Is the buddy allocator going to be in use a GREAT deal? Or is it one of those deeply burried Kernel subsystems that is called once in a while...
If it is called once in awhile, then it is relatively acceptable for it to be a tad slow. If it is going to be called a great deal, in short succession, then it really does need to be as fast as possible. Right?
Anyways, as usual, any feedback on this matter would be greatly appreciated.
Id be really quite interested to see what your opinions are on this
~Z