From: Martin Quinson Date: Thu, 16 Jun 2011 12:10:23 +0000 (+0200) Subject: try to group the mallocs by finality instead of spreading data all around the memory X-Git-Tag: v3_6_2~203^2~17 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/297bd008e5fd397b94fe2513838bf1e6bde073d5 try to group the mallocs by finality instead of spreading data all around the memory --- diff --git a/src/xbt/mallocator.c b/src/xbt/mallocator.c index f1972a00d0..1b0a3ced13 100644 --- a/src/xbt/mallocator.c +++ b/src/xbt/mallocator.c @@ -111,17 +111,27 @@ void *xbt_mallocator_get(xbt_mallocator_t m) { void *object; - if (m->current_size > 0) { - /* there is at least an available object */ - /* XBT_DEBUG("Reuse an old object for mallocator %p (size:%d/%d)", m, - m->current_size, m->max_size); */ - object = m->objects[--m->current_size]; - } else { - /* otherwise we must allocate a new object */ + if (m->current_size <= 0) { + /* No object is ready yet. Create a bunch of them to try to group the mallocs + * on the same memory pages (to help the cache lines) */ + /* XBT_DEBUG("Create a new object for mallocator %p (size:%d/%d)", m, m->current_size, m->max_size); */ - object = (*(m->new_f)) (); + int i; + int amount=MIN( (m->max_size) /2,1000); + for (i=0;iobjects[i] = (*(m->new_f)) (); + m->current_size=amount; } + + /* there is at least an available object, now */ + /* XBT_DEBUG("Reuse an old object for mallocator %p (size:%d/%d)", m, + m->current_size, m->max_size); */ + if (MC_IS_ENABLED) /* no mallocator with MC */ + object = (*(m->new_f)) (); + else + object = m->objects[--m->current_size]; + (*(m->reset_f)) (object); return object; }