On Wed, May 04, 2011 at 11:56:58PM -0500, Amit Kulkarni wrote:

> > The random number is derived from a global, which is incremented by a
> > few bits every time a chunk is needed (with a small optimization if
> > only one free slot is left).
> > 
> 
> I have no feedback on this diff but a question on random placing in 
> another two functions.
> 
> In static void unmap()
>       for (i = 0; tounmap > 0 && i < mopts.malloc_cache; i++) {
>               r = &d->free_regions[(i + offset) & (mopts.malloc_cache - 
> 1)];
> 
> In static void map()
>       for (i = 0; i < mopts.malloc_cache; i++) {
>               r = &d->free_regions[(i + offset) & (mopts.malloc_cache - 
> 1)];
> 
> AFAIK
> malloc_cache = 64
> offset = {0 , 15} interval
> free_regions[MALLOC_MAXCACHE] = 256
> 
> the effect of logical 'and' is useless because you are only 
> really indexing free_regions from i+15, max of 64+15.
> 
> If you want to index free_regions randomly over its full range, maybe you 
> should do something else?

malloc_cache is a power of the, so a bitwise and with malloc_cache - 1
is equivalent to modulo malloc_cache.

        -Otto

> 
> Thanks,
> amit 

Reply via email to