Page 1 of 1

Different kernel heap implementations

Posted: Mon May 18, 2015 11:12 am
by LPeter
Hi!
I've looked at the heap implementations on the wiki. My problem is that I can't really interpret other people's code, and I always like to write my own. And I've found no explanations for how these implementations work.
My own implementation consisted of headers and footers surrounding the allocated memory, but it got overcomplicated when I wanted to add the feature for page aligned allocation, that's why I'm trying to look at other approaches.
Could anyone explain briefly how do the different implementations work? (stack, slab, ...)
Thanks in advance! :)

Re: Different kernel heap implementations

Posted: Mon May 18, 2015 2:36 pm
by JulienDarc
Are you talking about heap memory allocation like malloc or friends ?

I am not sure to understand your question(s)

Re: Different kernel heap implementations

Posted: Mon May 18, 2015 10:51 pm
by LPeter
JulienDarc wrote:Are you talking about heap memory allocation like malloc or friends ?

I am not sure to understand your question(s)
Yes, the dynamic memory allocation.

Re: Different kernel heap implementations

Posted: Tue May 19, 2015 8:52 am
by JulienDarc
Ok what is the purpose of your memory allocation ?

Allocating big chunks, little chunks, both (caution with this one, performance penalty in sight), ring buffer, DMA ?

By headers and footers, you mean page guards ?

Optional, depending on the quality of your compiler: do you know assembly ?

Security : do you need to zero out the memory area ? Apply particular strategy (permissions, freeing routine, hooks..)? Want to add a canary ?

Which architecture ? portable code ? Embedded devices ?

Did you maintain a list array of free and used pages ? or more fine grained ?

Memory allocation is not something easy, unless you can answer those questions.

After all, at the end of the day, it is just reserving some space in ram. But you see that there are many ways to get there :)
That is so context dependent !

Re: Different kernel heap implementations

Posted: Tue May 19, 2015 10:08 am
by LPeter
JulienDarc wrote:Ok what is the purpose of your memory allocation ?

Allocating big chunks, little chunks, both (caution with this one, performance penalty in sight), ring buffer, DMA ?

By headers and footers, you mean page guards ?

Optional, depending on the quality of your compiler: do you know assembly ?

Security : do you need to zero out the memory area ? Apply particular strategy (permissions, freeing routine, hooks..)? Want to add a canary ?

Which architecture ? portable code ? Embedded devices ?

Did you maintain a list array of free and used pages ? or more fine grained ?

Memory allocation is not something easy, unless you can answer those questions.

After all, at the end of the day, it is just reserving some space in ram. But you see that there are many ways to get there :)
That is so context dependent !
I want kmalloc and kfree into my kernel (x86). And the "many ways" are that I'm intrested in. Actually I've looked at these:
http://wiki.osdev.org/User:Pancakes/Sim ... ementation
Because I've failed with my method so I'd like to understand other methods too. I need nothing more complicated than just this: kmalloc(uint32_t size, bool page_aligned) and kfree(void *).

Re: Different kernel heap implementations

Posted: Tue May 19, 2015 11:23 am
by dschatz
What code did you look? What code did you understand? What did you not understand? I think you're far more likely to get good help by being specific.