aboutsummaryrefslogtreecommitdiff
path: root/src/quarantine.c
diff options
context:
space:
mode:
authorQi Wang <interwq@gwu.edu>2015-10-27 15:12:10 -0700
committerJason Evans <je@fb.com>2015-11-10 14:28:34 -0800
commitf4a0f32d340985de477bbe329ecdaecd69ed1055 (patch)
treea148610f4d2253186c59e671dcb065ce3647d2f5 /src/quarantine.c
parent710ca112e31e8621177d08162f60158c27dd2974 (diff)
downloadjemalloc-f4a0f32d340985de477bbe329ecdaecd69ed1055.tar.gz
Fast-path improvement: reduce # of branches and unnecessary operations.
- Combine multiple runtime branches into a single malloc_slow check. - Avoid calling arena_choose / size2index / index2size on fast path. - A few micro optimizations.
Diffstat (limited to 'src/quarantine.c')
-rw-r--r--src/quarantine.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/quarantine.c b/src/quarantine.c
index 6c43dfc..ff8801c 100644
--- a/src/quarantine.c
+++ b/src/quarantine.c
@@ -23,12 +23,14 @@ static quarantine_t *
quarantine_init(tsd_t *tsd, size_t lg_maxobjs)
{
quarantine_t *quarantine;
+ size_t size;
assert(tsd_nominal(tsd));
- quarantine = (quarantine_t *)iallocztm(tsd, offsetof(quarantine_t, objs)
- + ((ZU(1) << lg_maxobjs) * sizeof(quarantine_obj_t)), false,
- tcache_get(tsd, true), true, NULL);
+ size = offsetof(quarantine_t, objs) + ((ZU(1) << lg_maxobjs) *
+ sizeof(quarantine_obj_t));
+ quarantine = (quarantine_t *)iallocztm(tsd, size, size2index(size),
+ false, tcache_get(tsd, true), true, NULL, true);
if (quarantine == NULL)
return (NULL);
quarantine->curbytes = 0;
@@ -55,7 +57,7 @@ quarantine_alloc_hook_work(tsd_t *tsd)
if (tsd_quarantine_get(tsd) == NULL)
tsd_quarantine_set(tsd, quarantine);
else
- idalloctm(tsd, quarantine, tcache_get(tsd, false), true);
+ idalloctm(tsd, quarantine, tcache_get(tsd, false), true, true);
}
static quarantine_t *
@@ -87,7 +89,7 @@ quarantine_grow(tsd_t *tsd, quarantine_t *quarantine)
memcpy(&ret->objs[ncopy_a], quarantine->objs, ncopy_b *
sizeof(quarantine_obj_t));
}
- idalloctm(tsd, quarantine, tcache_get(tsd, false), true);
+ idalloctm(tsd, quarantine, tcache_get(tsd, false), true, true);
tsd_quarantine_set(tsd, ret);
return (ret);
@@ -98,7 +100,7 @@ quarantine_drain_one(tsd_t *tsd, quarantine_t *quarantine)
{
quarantine_obj_t *obj = &quarantine->objs[quarantine->first];
assert(obj->usize == isalloc(obj->ptr, config_prof));
- idalloctm(tsd, obj->ptr, NULL, false);
+ idalloctm(tsd, obj->ptr, NULL, false, true);
quarantine->curbytes -= obj->usize;
quarantine->curobjs--;
quarantine->first = (quarantine->first + 1) & ((ZU(1) <<
@@ -123,7 +125,7 @@ quarantine(tsd_t *tsd, void *ptr)
assert(opt_quarantine);
if ((quarantine = tsd_quarantine_get(tsd)) == NULL) {
- idalloctm(tsd, ptr, NULL, false);
+ idalloctm(tsd, ptr, NULL, false, true);
return;
}
/*
@@ -162,7 +164,7 @@ quarantine(tsd_t *tsd, void *ptr)
}
} else {
assert(quarantine->curbytes == 0);
- idalloctm(tsd, ptr, NULL, false);
+ idalloctm(tsd, ptr, NULL, false, true);
}
}
@@ -177,7 +179,7 @@ quarantine_cleanup(tsd_t *tsd)
quarantine = tsd_quarantine_get(tsd);
if (quarantine != NULL) {
quarantine_drain(tsd, quarantine, 0);
- idalloctm(tsd, quarantine, tcache_get(tsd, false), true);
+ idalloctm(tsd, quarantine, tcache_get(tsd, false), true, true);
tsd_quarantine_set(tsd, NULL);
}
}