Simplify extent_node_t and add extent_node_init().

This commit is contained in:
Jason Evans 2015-02-17 15:13:52 -08:00
parent ee41ad409a
commit a4e1888d1a
6 changed files with 38 additions and 42 deletions

View File

@ -30,19 +30,12 @@ struct extent_node_s {
*/
bool en_achunk;
union {
/* Profile counters, used for huge objects. */
prof_tctx_t *en_prof_tctx;
/* Profile counters, used for huge objects. */
prof_tctx_t *en_prof_tctx;
struct {
/*
* Linkage for arena's runs_dirty and chunks_dirty
* rings.
*/
qr(extent_node_t) cd_link;
arena_chunk_map_misc_t runs_dirty;
};
};
/* Linkage for arena's runs_dirty and chunks_dirty rings. */
qr(extent_node_t) cd_link;
arena_chunk_map_misc_t runs_dirty;
union {
/* Linkage for the size/address-ordered tree. */
@ -82,6 +75,8 @@ void extent_node_size_set(extent_node_t *node, size_t size);
void extent_node_zeroed_set(extent_node_t *node, bool zeroed);
void extent_node_achunk_set(extent_node_t *node, bool achunk);
void extent_node_prof_tctx_set(extent_node_t *node, prof_tctx_t *tctx);
void extent_node_init(extent_node_t *node, arena_t *arena, void *addr,
size_t size, bool zeroed);
#endif
#if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_EXTENT_C_))
@ -168,6 +163,20 @@ extent_node_prof_tctx_set(extent_node_t *node, prof_tctx_t *tctx)
node->en_prof_tctx = tctx;
}
JEMALLOC_INLINE void
extent_node_init(extent_node_t *node, arena_t *arena, void *addr, size_t size,
bool zeroed)
{
extent_node_arena_set(node, arena);
extent_node_addr_set(node, addr);
extent_node_size_set(node, size);
extent_node_zeroed_set(node, zeroed);
extent_node_achunk_set(node, false);
if (config_prof)
extent_node_prof_tctx_set(node, NULL);
}
#endif
#endif /* JEMALLOC_H_INLINES */

View File

@ -182,6 +182,7 @@ extent_node_addr_get
extent_node_addr_set
extent_node_arena_get
extent_node_arena_set
extent_node_init
extent_node_prof_tctx_get
extent_node_prof_tctx_set
extent_node_size_get

View File

@ -465,9 +465,7 @@ arena_chunk_alloc_internal(arena_t *arena, bool *zero)
chunk = (arena_chunk_t *)chunk_alloc_arena(chunk_alloc, chunk_dalloc,
arena->ind, NULL, chunksize, chunksize, zero);
if (chunk != NULL) {
extent_node_arena_set(&chunk->node, arena);
extent_node_addr_set(&chunk->node, chunk);
extent_node_size_set(&chunk->node, chunksize);
extent_node_init(&chunk->node, arena, chunk, chunksize, *zero);
extent_node_achunk_set(&chunk->node, true);
if (chunk_register(chunk, &chunk->node)) {
chunk_dalloc((void *)chunk, chunksize, arena->ind);
@ -1055,10 +1053,7 @@ arena_stash_dirty(arena_t *arena, bool all, size_t npurge,
* just cached a node.
*/
assert(tnode != NULL);
extent_node_arena_set(tnode, arena);
extent_node_addr_set(tnode, addr);
extent_node_size_set(tnode, size);
extent_node_zeroed_set(tnode, zeroed);
extent_node_init(tnode, arena, addr, size, zeroed);
arena_chunk_dirty_node_init(tnode);
/* Stash. */
arena_chunk_dirty_insert(purge_runs_sentinel,

View File

@ -60,8 +60,7 @@ base_chunk_alloc(size_t minsize)
if (config_stats)
base_allocated += nsize;
}
extent_node_addr_set(node, addr);
extent_node_size_set(node, csize);
extent_node_init(node, NULL, addr, csize, true);
return (node);
}
@ -84,8 +83,7 @@ base_alloc(size_t size)
*/
csize = CACHELINE_CEILING(size);
extent_node_addr_set(&key, NULL);
extent_node_size_set(&key, csize);
extent_node_init(&key, NULL, NULL, csize, false);
malloc_mutex_lock(&base_mtx);
node = extent_tree_szad_nsearch(&base_avail_szad, &key);
if (node != NULL) {

View File

@ -79,8 +79,7 @@ chunk_recycle(arena_t *arena, extent_tree_t *chunks_szad,
/* Beware size_t wrap-around. */
if (alloc_size < size)
return (NULL);
extent_node_addr_set(&key, new_addr);
extent_node_size_set(&key, alloc_size);
extent_node_init(&key, arena, new_addr, alloc_size, false);
malloc_mutex_lock(&arena->chunks_mtx);
node = (new_addr != NULL) ? extent_tree_ad_search(chunks_ad, &key) :
extent_tree_szad_nsearch(chunks_szad, &key);
@ -121,9 +120,8 @@ chunk_recycle(arena_t *arena, extent_tree_t *chunks_szad,
return (NULL);
}
}
extent_node_addr_set(node, (void *)((uintptr_t)(ret) + size));
extent_node_size_set(node, trailsize);
extent_node_zeroed_set(node, zeroed);
extent_node_init(node, arena, (void *)((uintptr_t)(ret) + size),
trailsize, zeroed);
extent_tree_szad_insert(chunks_szad, node);
extent_tree_ad_insert(chunks_ad, node);
arena_chunk_dirty_maybe_insert(arena, node, dirty);
@ -288,7 +286,8 @@ chunk_record(arena_t *arena, extent_tree_t *chunks_szad,
JEMALLOC_VALGRIND_MAKE_MEM_NOACCESS(chunk, size);
malloc_mutex_lock(&arena->chunks_mtx);
extent_node_addr_set(&key, (void *)((uintptr_t)chunk + size));
extent_node_init(&key, arena, (void *)((uintptr_t)chunk + size), 0,
false);
node = extent_tree_ad_nsearch(chunks_ad, &key);
/* Try to coalesce forward. */
if (node != NULL && extent_node_addr_get(node) ==
@ -301,7 +300,7 @@ chunk_record(arena_t *arena, extent_tree_t *chunks_szad,
extent_tree_szad_remove(chunks_szad, node);
arena_chunk_dirty_maybe_remove(arena, node, dirty);
extent_node_addr_set(node, chunk);
extent_node_size_set(node, extent_node_size_get(node) + size);
extent_node_size_set(node, size + extent_node_size_get(node));
extent_node_zeroed_set(node, extent_node_zeroed_get(node) &&
!unzeroed);
extent_tree_szad_insert(chunks_szad, node);
@ -320,9 +319,7 @@ chunk_record(arena_t *arena, extent_tree_t *chunks_szad,
pages_purge(chunk, size);
goto label_return;
}
extent_node_addr_set(node, chunk);
extent_node_size_set(node, size);
extent_node_zeroed_set(node, !unzeroed);
extent_node_init(node, arena, chunk, size, !unzeroed);
extent_tree_ad_insert(chunks_ad, node);
extent_tree_szad_insert(chunks_szad, node);
arena_chunk_dirty_maybe_insert(arena, node, dirty);
@ -343,10 +340,10 @@ chunk_record(arena_t *arena, extent_tree_t *chunks_szad,
extent_tree_szad_remove(chunks_szad, node);
arena_chunk_dirty_maybe_remove(arena, node, dirty);
extent_node_addr_set(node, extent_node_addr_get(prev));
extent_node_size_set(node, extent_node_size_get(node) +
extent_node_size_get(prev));
extent_node_zeroed_set(node, extent_node_zeroed_get(node) &&
extent_node_zeroed_get(prev));
extent_node_size_set(node, extent_node_size_get(prev) +
extent_node_size_get(node));
extent_node_zeroed_set(node, extent_node_zeroed_get(prev) &&
extent_node_zeroed_get(node));
extent_tree_szad_insert(chunks_szad, node);
arena_chunk_dirty_maybe_insert(arena, node, dirty);

View File

@ -73,11 +73,7 @@ huge_palloc(tsd_t *tsd, arena_t *arena, size_t usize, size_t alignment,
return (NULL);
}
extent_node_arena_set(node, arena);
extent_node_addr_set(node, ret);
extent_node_size_set(node, usize);
extent_node_achunk_set(node, false);
extent_node_zeroed_set(node, is_zeroed);
extent_node_init(node, arena, ret, usize, is_zeroed);
if (huge_node_set(ret, node)) {
arena_chunk_dalloc_huge(arena, ret, usize);