Fix two quarantine regressions.

Fix quarantine to actually update tsd when expanding, and to avoid
double initialization (leaking the first quarantine) due to recursive
initialization.

This resolves #161.
This commit is contained in:
Jason Evans 2014-11-04 18:03:11 -08:00
parent 2b2f6dc1e4
commit c002a5c800
3 changed files with 26 additions and 2 deletions

View File

@ -339,6 +339,7 @@ prof_thread_name_set
quarantine quarantine
quarantine_alloc_hook quarantine_alloc_hook
quarantine_cleanup quarantine_cleanup
quarantine_alloc_hook_work
quarantine_init quarantine_init
register_zone register_zone
rtree_delete rtree_delete

View File

@ -30,6 +30,7 @@ struct quarantine_s {
#ifdef JEMALLOC_H_EXTERNS #ifdef JEMALLOC_H_EXTERNS
quarantine_t *quarantine_init(tsd_t *tsd, size_t lg_maxobjs); quarantine_t *quarantine_init(tsd_t *tsd, size_t lg_maxobjs);
void quarantine_alloc_hook_work(tsd_t *tsd);
void quarantine(tsd_t *tsd, void *ptr); void quarantine(tsd_t *tsd, void *ptr);
void quarantine_cleanup(tsd_t *tsd); void quarantine_cleanup(tsd_t *tsd);
@ -50,8 +51,8 @@ quarantine_alloc_hook(void)
assert(config_fill && opt_quarantine); assert(config_fill && opt_quarantine);
tsd = tsd_fetch(); tsd = tsd_fetch();
if (tsd_quarantine_get(tsd) == NULL && tsd_nominal(tsd)) if (tsd_quarantine_get(tsd) == NULL)
tsd_quarantine_set(tsd, quarantine_init(tsd, LG_MAXOBJS_INIT)); quarantine_alloc_hook_work(tsd);
} }
#endif #endif

View File

@ -24,6 +24,8 @@ quarantine_init(tsd_t *tsd, size_t lg_maxobjs)
{ {
quarantine_t *quarantine; quarantine_t *quarantine;
assert(tsd_nominal(tsd));
quarantine = (quarantine_t *)imalloc(tsd, offsetof(quarantine_t, objs) + quarantine = (quarantine_t *)imalloc(tsd, offsetof(quarantine_t, objs) +
((ZU(1) << lg_maxobjs) * sizeof(quarantine_obj_t))); ((ZU(1) << lg_maxobjs) * sizeof(quarantine_obj_t)));
if (quarantine == NULL) if (quarantine == NULL)
@ -36,6 +38,25 @@ quarantine_init(tsd_t *tsd, size_t lg_maxobjs)
return (quarantine); return (quarantine);
} }
void
quarantine_alloc_hook_work(tsd_t *tsd)
{
quarantine_t *quarantine;
if (!tsd_nominal(tsd))
return;
quarantine = quarantine_init(tsd, LG_MAXOBJS_INIT);
/*
* Check again whether quarantine has been initialized, because
* qurantine_init() may have triggered recursive initialization.
*/
if (tsd_quarantine_get(tsd) == NULL)
tsd_quarantine_set(tsd, quarantine);
else
idalloc(tsd, quarantine);
}
static quarantine_t * static quarantine_t *
quarantine_grow(tsd_t *tsd, quarantine_t *quarantine) quarantine_grow(tsd_t *tsd, quarantine_t *quarantine)
{ {
@ -67,6 +88,7 @@ quarantine_grow(tsd_t *tsd, quarantine_t *quarantine)
} }
idalloc(tsd, quarantine); idalloc(tsd, quarantine);
tsd_quarantine_set(tsd, ret);
return (ret); return (ret);
} }