On Sat, 30 Dec 2017 11:50:53 +0000, Otto Moerbeek wrote: > Slightly different diff: instead of initing all chunk_info structs in > page, do it on demand at first use. Measurements show that a lot of > programs only use a few chunk_info structs, so it is a bit wasteful to > always initialize all of them. Also de-inline the init code for > readability.
Perhaps a point of detail, but how about setting up the bitmap with i = p->total; memset(p->bits, 0xff, sizeof(p->bits[0]) * (i / MALLOC_BITS)); if (i % MALLOC_BITS != 0) p->bits[i / MALLOC_BITS] = (1U << (i % MALLOC_BITS)) - 1; or, since p->total should never be zero, i = p->total - 1; memset(p->bits, 0xff, sizeof(p->bits[0]) * (i / MALLOC_BITS)); p->bits[i / MALLOC_BITS] = (2U << (i % MALLOC_BITS)) - 1; instead of for (i = 0; p->total - i >= MALLOC_BITS; i += MALLOC_BITS) p->bits[i / MALLOC_BITS] = (u_short)~0U; if (i < p->total) p->bits[i / MALLOC_BITS] = 0; for (; i < p->total; i++) p->bits[i / MALLOC_BITS] |= (u_short)1U << (i % MALLOC_BITS); at the end of the new init_chunk_info() function? Besides, a few lines above those loops, I think p->shift could directly be set to MALLOC_MINSHIFT when bits == 0, without having to recalculate it from MALLOC_MINSIZE. Regards, kshe