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!
Different kernel heap implementations
-
- Member
- Posts: 97
- Joined: Tue Mar 10, 2015 10:08 am
Re: Different kernel heap implementations
Are you talking about heap memory allocation like malloc or friends ?
I am not sure to understand your question(s)
I am not sure to understand your question(s)
Re: Different kernel heap implementations
Yes, the dynamic memory allocation.JulienDarc wrote:Are you talking about heap memory allocation like malloc or friends ?
I am not sure to understand your question(s)
-
- Member
- Posts: 97
- Joined: Tue Mar 10, 2015 10:08 am
Re: Different kernel heap implementations
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 !
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
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: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 !
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
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.