Different kernel heap implementations

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
LPeter
Member
Member
Posts: 30
Joined: Wed Jan 28, 2015 7:41 am

Different kernel heap implementations

Post 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! :)
JulienDarc
Member
Member
Posts: 97
Joined: Tue Mar 10, 2015 10:08 am

Re: Different kernel heap implementations

Post by JulienDarc »

Are you talking about heap memory allocation like malloc or friends ?

I am not sure to understand your question(s)
LPeter
Member
Member
Posts: 30
Joined: Wed Jan 28, 2015 7:41 am

Re: Different kernel heap implementations

Post 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.
JulienDarc
Member
Member
Posts: 97
Joined: Tue Mar 10, 2015 10:08 am

Re: Different kernel heap implementations

Post 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 !
LPeter
Member
Member
Posts: 30
Joined: Wed Jan 28, 2015 7:41 am

Re: Different kernel heap implementations

Post 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 *).
dschatz
Member
Member
Posts: 61
Joined: Wed Nov 10, 2010 10:55 pm

Re: Different kernel heap implementations

Post 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.
Post Reply