Fix arena bugs.
Move part of arena_bin_lower_run() into the callers, since the conditions under which it should be called differ slightly between callers. Fix arena_chunk_purge() to omit run size in the last map entry for each run it temporarily allocates.
This commit is contained in:
parent
12ca91402b
commit
8de6a02823
@ -435,6 +435,12 @@ arena_chunk_alloc(arena_t *arena)
|
|||||||
runs_avail = &arena->runs_avail_clean;
|
runs_avail = &arena->runs_avail_clean;
|
||||||
else
|
else
|
||||||
runs_avail = &arena->runs_avail_dirty;
|
runs_avail = &arena->runs_avail_dirty;
|
||||||
|
assert((chunk->map[0].bits & ~PAGE_MASK) == arena_maxclass);
|
||||||
|
assert((chunk->map[chunk_npages-1-map_bias].bits & ~PAGE_MASK)
|
||||||
|
== arena_maxclass);
|
||||||
|
assert((chunk->map[0].bits & CHUNK_MAP_DIRTY) ==
|
||||||
|
(chunk->map[chunk_npages-1-map_bias].bits &
|
||||||
|
CHUNK_MAP_DIRTY));
|
||||||
arena_avail_tree_insert(runs_avail, &chunk->map[0]);
|
arena_avail_tree_insert(runs_avail, &chunk->map[0]);
|
||||||
} else {
|
} else {
|
||||||
bool zero;
|
bool zero;
|
||||||
@ -683,8 +689,8 @@ arena_chunk_purge(arena_t *arena, arena_chunk_t *chunk)
|
|||||||
&arena->runs_avail_dirty, mapelm);
|
&arena->runs_avail_dirty, mapelm);
|
||||||
|
|
||||||
mapelm->bits = (npages << PAGE_SHIFT) |
|
mapelm->bits = (npages << PAGE_SHIFT) |
|
||||||
CHUNK_MAP_LARGE | CHUNK_MAP_ALLOCATED |
|
flag_unzeroed | CHUNK_MAP_LARGE |
|
||||||
flag_unzeroed;
|
CHUNK_MAP_ALLOCATED;
|
||||||
/*
|
/*
|
||||||
* Update internal elements in the page map, so
|
* Update internal elements in the page map, so
|
||||||
* that CHUNK_MAP_UNZEROED is properly set.
|
* that CHUNK_MAP_UNZEROED is properly set.
|
||||||
@ -696,9 +702,8 @@ arena_chunk_purge(arena_t *arena, arena_chunk_t *chunk)
|
|||||||
if (npages > 1) {
|
if (npages > 1) {
|
||||||
chunk->map[
|
chunk->map[
|
||||||
pageind+npages-1-map_bias].bits =
|
pageind+npages-1-map_bias].bits =
|
||||||
(npages << PAGE_SHIFT) |
|
flag_unzeroed | CHUNK_MAP_LARGE |
|
||||||
CHUNK_MAP_LARGE |
|
CHUNK_MAP_ALLOCATED;
|
||||||
CHUNK_MAP_ALLOCATED | flag_unzeroed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
arena->nactive += npages;
|
arena->nactive += npages;
|
||||||
@ -894,9 +899,16 @@ arena_run_dalloc(arena_t *arena, arena_run_t *run, bool dirty)
|
|||||||
>> PAGE_SHIFT);
|
>> PAGE_SHIFT);
|
||||||
assert(run_ind >= map_bias);
|
assert(run_ind >= map_bias);
|
||||||
assert(run_ind < chunk_npages);
|
assert(run_ind < chunk_npages);
|
||||||
if ((chunk->map[run_ind-map_bias].bits & CHUNK_MAP_LARGE) != 0)
|
if ((chunk->map[run_ind-map_bias].bits & CHUNK_MAP_LARGE) != 0) {
|
||||||
size = chunk->map[run_ind-map_bias].bits & ~PAGE_MASK;
|
size = chunk->map[run_ind-map_bias].bits & ~PAGE_MASK;
|
||||||
else
|
assert(size == PAGE_SIZE ||
|
||||||
|
(chunk->map[run_ind+(size>>PAGE_SHIFT)-1-map_bias].bits &
|
||||||
|
~PAGE_MASK) == 0);
|
||||||
|
assert((chunk->map[run_ind+(size>>PAGE_SHIFT)-1-map_bias].bits &
|
||||||
|
CHUNK_MAP_LARGE) != 0);
|
||||||
|
assert((chunk->map[run_ind+(size>>PAGE_SHIFT)-1-map_bias].bits &
|
||||||
|
CHUNK_MAP_ALLOCATED) != 0);
|
||||||
|
} else
|
||||||
size = run->bin->run_size;
|
size = run->bin->run_size;
|
||||||
run_pages = (size >> PAGE_SHIFT);
|
run_pages = (size >> PAGE_SHIFT);
|
||||||
arena->nactive -= run_pages;
|
arena->nactive -= run_pages;
|
||||||
@ -993,6 +1005,10 @@ arena_run_dalloc(arena_t *arena, arena_run_t *run, bool dirty)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Insert into runs_avail, now that coalescing is complete. */
|
/* Insert into runs_avail, now that coalescing is complete. */
|
||||||
|
assert((chunk->map[run_ind-map_bias].bits & ~PAGE_MASK) ==
|
||||||
|
(chunk->map[run_ind+run_pages-1-map_bias].bits & ~PAGE_MASK));
|
||||||
|
assert((chunk->map[run_ind-map_bias].bits & CHUNK_MAP_DIRTY) ==
|
||||||
|
(chunk->map[run_ind+run_pages-1-map_bias].bits & CHUNK_MAP_DIRTY));
|
||||||
arena_avail_tree_insert(runs_avail, &chunk->map[run_ind-map_bias]);
|
arena_avail_tree_insert(runs_avail, &chunk->map[run_ind-map_bias]);
|
||||||
|
|
||||||
if (dirty) {
|
if (dirty) {
|
||||||
@ -1229,6 +1245,9 @@ arena_bin_malloc_hard(arena_t *arena, arena_bin_t *bin)
|
|||||||
* from the run.
|
* from the run.
|
||||||
*/
|
*/
|
||||||
chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(run);
|
chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(run);
|
||||||
|
if (run->nfree == bin->nregs)
|
||||||
|
arena_dalloc_bin_run(arena, chunk, run, bin);
|
||||||
|
else
|
||||||
arena_bin_lower_run(arena, chunk, run, bin);
|
arena_bin_lower_run(arena, chunk, run, bin);
|
||||||
}
|
}
|
||||||
return (ret);
|
return (ret);
|
||||||
@ -1904,12 +1923,9 @@ arena_bin_lower_run(arena_t *arena, arena_chunk_t *chunk, arena_run_t *run,
|
|||||||
arena_bin_t *bin)
|
arena_bin_t *bin)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (run->nfree == bin->nregs)
|
|
||||||
arena_dalloc_bin_run(arena, chunk, run, bin);
|
|
||||||
else if (run->nfree == 1 && run != bin->runcur) {
|
|
||||||
/*
|
/*
|
||||||
* Make sure that bin->runcur always refers to the lowest
|
* Make sure that bin->runcur always refers to the lowest non-full run,
|
||||||
* non-full run, if one exists.
|
* if one exists.
|
||||||
*/
|
*/
|
||||||
if (bin->runcur == NULL)
|
if (bin->runcur == NULL)
|
||||||
bin->runcur = run;
|
bin->runcur = run;
|
||||||
@ -1918,15 +1934,13 @@ arena_bin_lower_run(arena_t *arena, arena_chunk_t *chunk, arena_run_t *run,
|
|||||||
if (bin->runcur->nfree > 0) {
|
if (bin->runcur->nfree > 0) {
|
||||||
arena_chunk_t *runcur_chunk =
|
arena_chunk_t *runcur_chunk =
|
||||||
CHUNK_ADDR2BASE(bin->runcur);
|
CHUNK_ADDR2BASE(bin->runcur);
|
||||||
size_t runcur_pageind =
|
size_t runcur_pageind = (((uintptr_t)bin->runcur -
|
||||||
(((uintptr_t)bin->runcur -
|
|
||||||
(uintptr_t)runcur_chunk)) >> PAGE_SHIFT;
|
(uintptr_t)runcur_chunk)) >> PAGE_SHIFT;
|
||||||
arena_chunk_map_t *runcur_mapelm =
|
arena_chunk_map_t *runcur_mapelm =
|
||||||
&runcur_chunk->map[runcur_pageind-map_bias];
|
&runcur_chunk->map[runcur_pageind-map_bias];
|
||||||
|
|
||||||
/* Insert runcur. */
|
/* Insert runcur. */
|
||||||
arena_run_tree_insert(&bin->runs,
|
arena_run_tree_insert(&bin->runs, runcur_mapelm);
|
||||||
runcur_mapelm);
|
|
||||||
}
|
}
|
||||||
bin->runcur = run;
|
bin->runcur = run;
|
||||||
} else {
|
} else {
|
||||||
@ -1935,11 +1949,9 @@ arena_bin_lower_run(arena_t *arena, arena_chunk_t *chunk, arena_run_t *run,
|
|||||||
arena_chunk_map_t *run_mapelm =
|
arena_chunk_map_t *run_mapelm =
|
||||||
&chunk->map[run_pageind-map_bias];
|
&chunk->map[run_pageind-map_bias];
|
||||||
|
|
||||||
assert(arena_run_tree_search(&bin->runs, run_mapelm) ==
|
assert(arena_run_tree_search(&bin->runs, run_mapelm) == NULL);
|
||||||
NULL);
|
|
||||||
arena_run_tree_insert(&bin->runs, run_mapelm);
|
arena_run_tree_insert(&bin->runs, run_mapelm);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1968,6 +1980,9 @@ arena_dalloc_bin(arena_t *arena, arena_chunk_t *chunk, void *ptr,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
arena_run_reg_dalloc(run, ptr);
|
arena_run_reg_dalloc(run, ptr);
|
||||||
|
if (run->nfree == bin->nregs)
|
||||||
|
arena_dalloc_bin_run(arena, chunk, run, bin);
|
||||||
|
else if (run->nfree == 1 && run != bin->runcur)
|
||||||
arena_bin_lower_run(arena, chunk, run, bin);
|
arena_bin_lower_run(arena, chunk, run, bin);
|
||||||
|
|
||||||
#ifdef JEMALLOC_STATS
|
#ifdef JEMALLOC_STATS
|
||||||
|
Loading…
Reference in New Issue
Block a user