refactor tcache_dalloc_small
Add a cache_bin_dalloc_easy (to match the alloc_easy function), and use it in tcache_dalloc_small. It will also be used in the new free fastpath.
This commit is contained in:
parent
5e795297b3
commit
e2ab215324
@ -90,7 +90,7 @@ cache_bin_alloc_easy(cache_bin_t *bin, bool *success) {
|
|||||||
|
|
||||||
bin->ncached--;
|
bin->ncached--;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check for both bin->ncached == 0 and ncached < low_water
|
* Check for both bin->ncached == 0 and ncached < low_water
|
||||||
* in a single branch.
|
* in a single branch.
|
||||||
*/
|
*/
|
||||||
@ -102,7 +102,7 @@ cache_bin_alloc_easy(cache_bin_t *bin, bool *success) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* success (instead of ret) should be checked upon the return of this
|
* success (instead of ret) should be checked upon the return of this
|
||||||
* function. We avoid checking (ret == NULL) because there is never a
|
* function. We avoid checking (ret == NULL) because there is never a
|
||||||
@ -116,4 +116,16 @@ cache_bin_alloc_easy(cache_bin_t *bin, bool *success) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JEMALLOC_ALWAYS_INLINE bool
|
||||||
|
cache_bin_dalloc_easy(cache_bin_t *bin, cache_bin_info_t *bin_info, void *ptr) {
|
||||||
|
if (unlikely(bin->ncached == bin_info->ncached_max)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
assert(bin->ncached < bin_info->ncached_max);
|
||||||
|
bin->ncached++;
|
||||||
|
*(bin->avail - bin->ncached) = ptr;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* JEMALLOC_INTERNAL_CACHE_BIN_H */
|
#endif /* JEMALLOC_INTERNAL_CACHE_BIN_H */
|
||||||
|
@ -175,13 +175,12 @@ tcache_dalloc_small(tsd_t *tsd, tcache_t *tcache, void *ptr, szind_t binind,
|
|||||||
|
|
||||||
bin = tcache_small_bin_get(tcache, binind);
|
bin = tcache_small_bin_get(tcache, binind);
|
||||||
bin_info = &tcache_bin_info[binind];
|
bin_info = &tcache_bin_info[binind];
|
||||||
if (unlikely(bin->ncached == bin_info->ncached_max)) {
|
if (unlikely(!cache_bin_dalloc_easy(bin, bin_info, ptr))) {
|
||||||
tcache_bin_flush_small(tsd, tcache, bin, binind,
|
tcache_bin_flush_small(tsd, tcache, bin, binind,
|
||||||
(bin_info->ncached_max >> 1));
|
(bin_info->ncached_max >> 1));
|
||||||
|
bool ret = cache_bin_dalloc_easy(bin, bin_info, ptr);
|
||||||
|
assert(ret);
|
||||||
}
|
}
|
||||||
assert(bin->ncached < bin_info->ncached_max);
|
|
||||||
bin->ncached++;
|
|
||||||
*(bin->avail - bin->ncached) = ptr;
|
|
||||||
|
|
||||||
tcache_event(tsd, tcache);
|
tcache_event(tsd, tcache);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user