Fix psz/pind edge cases.

Add an "over-size" extent heap in which to store extents which exceed
the maximum size class (plus cache-oblivious padding, if enabled).
Remove psz2ind_clamp() and use psz2ind() instead so that trying to
allocate the maximum size class can in principle succeed.  In practice,
this allows assertions to hold so that OOM errors can be successfully
generated.
This commit is contained in:
Jason Evans
2016-11-03 21:18:50 -07:00
parent 8dd5ea87ca
commit ea9961acdb
7 changed files with 39 additions and 53 deletions

View File

@@ -1696,7 +1696,7 @@ arena_new(tsdn_t *tsdn, unsigned ind)
WITNESS_RANK_ARENA_LARGE))
return (NULL);
for (i = 0; i < NPSIZES; i++) {
for (i = 0; i < NPSIZES+1; i++) {
extent_heap_new(&arena->extents_cached[i]);
extent_heap_new(&arena->extents_retained[i]);
}

View File

@@ -45,7 +45,7 @@ static size_t highpages;
*/
static void extent_record(tsdn_t *tsdn, arena_t *arena,
extent_hooks_t **r_extent_hooks, extent_heap_t extent_heaps[NPSIZES],
extent_hooks_t **r_extent_hooks, extent_heap_t extent_heaps[NPSIZES+1],
bool cache, extent_t *extent);
/******************************************************************************/
@@ -190,11 +190,11 @@ extent_ad_comp(const extent_t *a, const extent_t *b)
ph_gen(, extent_heap_, extent_heap_t, extent_t, ph_link, extent_ad_comp)
static void
extent_heaps_insert(tsdn_t *tsdn, extent_heap_t extent_heaps[NPSIZES],
extent_heaps_insert(tsdn_t *tsdn, extent_heap_t extent_heaps[NPSIZES+1],
extent_t *extent)
{
size_t psz = extent_size_quantize_floor(extent_size_get(extent));
pszind_t pind = psz2ind_clamp(psz);
pszind_t pind = psz2ind(psz);
malloc_mutex_assert_owner(tsdn, &extent_arena_get(extent)->extents_mtx);
@@ -202,11 +202,11 @@ extent_heaps_insert(tsdn_t *tsdn, extent_heap_t extent_heaps[NPSIZES],
}
static void
extent_heaps_remove(tsdn_t *tsdn, extent_heap_t extent_heaps[NPSIZES],
extent_heaps_remove(tsdn_t *tsdn, extent_heap_t extent_heaps[NPSIZES+1],
extent_t *extent)
{
size_t psz = extent_size_quantize_floor(extent_size_get(extent));
pszind_t pind = psz2ind_clamp(psz);
pszind_t pind = psz2ind(psz);
malloc_mutex_assert_owner(tsdn, &extent_arena_get(extent)->extents_mtx);
@@ -358,15 +358,14 @@ extent_deregister(tsdn_t *tsdn, extent_t *extent)
*/
static extent_t *
extent_first_best_fit(tsdn_t *tsdn, arena_t *arena,
extent_heap_t extent_heaps[NPSIZES], size_t size)
extent_heap_t extent_heaps[NPSIZES+1], size_t size)
{
pszind_t pind, i;
malloc_mutex_assert_owner(tsdn, &arena->extents_mtx);
pind = psz2ind(extent_size_quantize_ceil(size));
assert(pind < NPSIZES);
for (i = pind; i < NPSIZES; i++) {
for (i = pind; i < NPSIZES+1; i++) {
extent_t *extent = extent_heap_first(&extent_heaps[i]);
if (extent != NULL)
return (extent);
@@ -393,7 +392,7 @@ extent_leak(tsdn_t *tsdn, arena_t *arena, extent_hooks_t **r_extent_hooks,
static extent_t *
extent_recycle(tsdn_t *tsdn, arena_t *arena, extent_hooks_t **r_extent_hooks,
extent_heap_t extent_heaps[NPSIZES], bool locked, bool cache,
extent_heap_t extent_heaps[NPSIZES+1], bool locked, bool cache,
void *new_addr, size_t usize, size_t pad, size_t alignment, bool *zero,
bool *commit, bool slab)
{
@@ -758,7 +757,7 @@ extent_can_coalesce(const extent_t *a, const extent_t *b)
static void
extent_try_coalesce(tsdn_t *tsdn, arena_t *arena,
extent_hooks_t **r_extent_hooks, extent_t *a, extent_t *b,
extent_heap_t extent_heaps[NPSIZES], bool cache)
extent_heap_t extent_heaps[NPSIZES+1], bool cache)
{
if (!extent_can_coalesce(a, b))
@@ -786,7 +785,7 @@ extent_try_coalesce(tsdn_t *tsdn, arena_t *arena,
static void
extent_record(tsdn_t *tsdn, arena_t *arena, extent_hooks_t **r_extent_hooks,
extent_heap_t extent_heaps[NPSIZES], bool cache, extent_t *extent)
extent_heap_t extent_heaps[NPSIZES+1], bool cache, extent_t *extent)
{
extent_t *prev, *next;
rtree_ctx_t rtree_ctx_fallback;

View File

@@ -83,7 +83,7 @@ enum {
static uint8_t malloc_slow_flags;
JEMALLOC_ALIGNED(CACHELINE)
const size_t pind2sz_tab[NPSIZES] = {
const size_t pind2sz_tab[NPSIZES+1] = {
#define PSZ_yes(lg_grp, ndelta, lg_delta) \
(((ZU(1)<<lg_grp) + (ZU(ndelta)<<lg_delta))),
#define PSZ_no(lg_grp, ndelta, lg_delta)
@@ -93,6 +93,7 @@ const size_t pind2sz_tab[NPSIZES] = {
#undef PSZ_yes
#undef PSZ_no
#undef SC
(LARGE_MAXCLASS + PAGE)
};
JEMALLOC_ALIGNED(CACHELINE)