Hi Bond, On Tue, Sep 28, 2010 at 1:43 AM, Bond <jamesbond.2k.g@xxxxxxxxx> wrote: > > > On Tue, Sep 28, 2010 at 11:59 AM, Dave Hylands <dhylands@xxxxxxxxx> wrote: > Hi Bond, >>So user mode programs don't allocate memory using kmalloc. I believe >>that they wind up calling __get_free_pages. >>There are many data structures that can be used. The kernel provides 3 >>different implementations of kmalloc, called, slab, slub and slob. It >>all depends on you design criteria. >>The simplest is to maintain a linked list of free spaces. It's simple, >>but suffers performance issues and fragmentation issues. >>You could use a bitmap (one bit per byte). Or you could maintain a >>indexed free list, where an 8-bit index is used. > I googled above thing > http://www.google.co.in/search?sourceid=chrome&client=ubuntu&channel=cs&ie=UTF-8&q=index+free+list > but indexed free list I could not find any where. > Can you give some link to what you are referring to. >>The 8-bit index would >>be stored using the free memory itself. You'd need to have a separate >>list for every 256 bytes, but that would have very low overhead. I don't have a link. But you'd initialize doing something like this: uint8_t data[256]; free_list = 0; for ( i = 1; i < 256; i++ ) { // Add Each byte to the free list. data[i] = free_list; free_list = i; } Finding a free entry would be something like: if ( free_list != 0 ) { uint8_t *avail = &data[free_list]; free_list = *avail; *avail = 0; return avail; } and freeing would be something like this: index = freePtr - data; data[index] = free_list; free_list = index; -- Dave Hylands Shuswap, BC, Canada http://www.DaveHylands.com/ -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ