Avoid validating freshly mapped memory.
Move validation of supposedly zeroed pages from chunk_alloc() to chunk_recycle(). There is little point to validating newly mapped memory returned by chunk_alloc_mmap(), and memory that comes from sbrk() is explicitly zeroed, so there is little risk to assuming that chunk_alloc_dss() actually does the zeroing properly. This relaxation of validation can make a big difference to application startup time and overall system usage on platforms that use jemalloc as the system allocator (namely FreeBSD). Submitted by Ian Lepore <ian@FreeBSD.org>.
This commit is contained in:
parent
13e4e24c42
commit
14a2c6a698
32
src/chunk.c
32
src/chunk.c
@ -78,6 +78,9 @@ chunk_recycle(extent_tree_t *chunks_szad, extent_tree_t *chunks_ad, size_t size,
|
|||||||
assert(node->size >= leadsize + size);
|
assert(node->size >= leadsize + size);
|
||||||
trailsize = node->size - leadsize - size;
|
trailsize = node->size - leadsize - size;
|
||||||
ret = (void *)((uintptr_t)node->addr + leadsize);
|
ret = (void *)((uintptr_t)node->addr + leadsize);
|
||||||
|
zeroed = node->zeroed;
|
||||||
|
if (zeroed)
|
||||||
|
*zero = true;
|
||||||
/* Remove node from the tree. */
|
/* Remove node from the tree. */
|
||||||
extent_tree_szad_remove(chunks_szad, node);
|
extent_tree_szad_remove(chunks_szad, node);
|
||||||
extent_tree_ad_remove(chunks_ad, node);
|
extent_tree_ad_remove(chunks_ad, node);
|
||||||
@ -114,17 +117,22 @@ chunk_recycle(extent_tree_t *chunks_szad, extent_tree_t *chunks_ad, size_t size,
|
|||||||
}
|
}
|
||||||
malloc_mutex_unlock(&chunks_mtx);
|
malloc_mutex_unlock(&chunks_mtx);
|
||||||
|
|
||||||
zeroed = false;
|
if (node != NULL)
|
||||||
if (node != NULL) {
|
|
||||||
if (node->zeroed) {
|
|
||||||
zeroed = true;
|
|
||||||
*zero = true;
|
|
||||||
}
|
|
||||||
base_node_dealloc(node);
|
base_node_dealloc(node);
|
||||||
}
|
|
||||||
VALGRIND_MAKE_MEM_UNDEFINED(ret, size);
|
VALGRIND_MAKE_MEM_UNDEFINED(ret, size);
|
||||||
if (zeroed == false && *zero)
|
if (*zero) {
|
||||||
|
if (zeroed == false)
|
||||||
memset(ret, 0, size);
|
memset(ret, 0, size);
|
||||||
|
else if (config_debug) {
|
||||||
|
size_t i;
|
||||||
|
size_t *p = (size_t *)(uintptr_t)ret;
|
||||||
|
|
||||||
|
VALGRIND_MAKE_MEM_DEFINED(ret, size);
|
||||||
|
for (i = 0; i < size / sizeof(size_t); i++)
|
||||||
|
assert(p[i] == 0);
|
||||||
|
VALGRIND_MAKE_MEM_UNDEFINED(ret, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,14 +201,6 @@ label_return:
|
|||||||
if (config_prof && opt_prof && opt_prof_gdump && gdump)
|
if (config_prof && opt_prof && opt_prof_gdump && gdump)
|
||||||
prof_gdump();
|
prof_gdump();
|
||||||
}
|
}
|
||||||
if (config_debug && *zero && ret != NULL) {
|
|
||||||
size_t i;
|
|
||||||
size_t *p = (size_t *)(uintptr_t)ret;
|
|
||||||
|
|
||||||
VALGRIND_MAKE_MEM_DEFINED(ret, size);
|
|
||||||
for (i = 0; i < size / sizeof(size_t); i++)
|
|
||||||
assert(p[i] == 0);
|
|
||||||
}
|
|
||||||
assert(CHUNK_ADDR2BASE(ret) == ret);
|
assert(CHUNK_ADDR2BASE(ret) == ret);
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user