2010-01-17 01:53:50 +08:00
|
|
|
#define JEMALLOC_HUGE_C_
|
2010-02-12 06:45:59 +08:00
|
|
|
#include "jemalloc/internal/jemalloc_internal.h"
|
2010-01-17 01:53:50 +08:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
void *
|
2016-05-11 13:21:10 +08:00
|
|
|
huge_malloc(tsdn_t *tsdn, arena_t *arena, size_t usize, bool zero)
|
2012-04-11 01:50:33 +08:00
|
|
|
{
|
|
|
|
|
2016-02-26 07:29:49 +08:00
|
|
|
assert(usize == s2u(usize));
|
2014-10-06 08:54:10 +08:00
|
|
|
|
2016-05-11 13:21:10 +08:00
|
|
|
return (huge_palloc(tsdn, arena, usize, chunksize, zero));
|
2012-04-11 01:50:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2016-05-11 13:21:10 +08:00
|
|
|
huge_palloc(tsdn_t *tsdn, arena_t *arena, size_t usize, size_t alignment,
|
2016-04-23 05:34:14 +08:00
|
|
|
bool zero)
|
2010-01-17 01:53:50 +08:00
|
|
|
{
|
2016-02-26 07:29:49 +08:00
|
|
|
size_t ausize;
|
2016-03-24 12:09:28 +08:00
|
|
|
extent_t *extent;
|
2012-04-22 07:04:51 +08:00
|
|
|
bool is_zeroed;
|
2010-01-17 01:53:50 +08:00
|
|
|
|
|
|
|
/* Allocate one or more contiguous chunks for this request. */
|
|
|
|
|
2016-05-11 13:21:10 +08:00
|
|
|
assert(!tsdn_null(tsdn) || arena != NULL);
|
|
|
|
|
2016-02-26 07:29:49 +08:00
|
|
|
ausize = sa2u(usize, alignment);
|
|
|
|
if (unlikely(ausize == 0 || ausize > HUGE_MAXCLASS))
|
2015-07-24 08:16:32 +08:00
|
|
|
return (NULL);
|
2016-02-26 07:29:49 +08:00
|
|
|
assert(ausize >= chunksize);
|
2015-07-24 08:16:32 +08:00
|
|
|
|
2012-04-22 07:04:51 +08:00
|
|
|
/*
|
|
|
|
* Copy zero into is_zeroed and pass the copy to chunk_alloc(), so that
|
|
|
|
* it is possible to make correct junk/zero fill decisions below.
|
|
|
|
*/
|
|
|
|
is_zeroed = zero;
|
2016-05-12 07:52:58 +08:00
|
|
|
if (likely(!tsdn_null(tsdn)))
|
|
|
|
arena = arena_choose(tsdn_tsd(tsdn), arena);
|
2016-05-19 12:02:46 +08:00
|
|
|
if (unlikely(arena == NULL) || (extent = arena_chunk_alloc_huge(tsdn,
|
|
|
|
arena, usize, alignment, &is_zeroed)) == NULL)
|
2010-01-17 01:53:50 +08:00
|
|
|
return (NULL);
|
|
|
|
|
2016-05-19 12:02:46 +08:00
|
|
|
if (usize < extent_size_get(extent))
|
|
|
|
extent_size_set(extent, usize);
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2016-03-24 12:09:28 +08:00
|
|
|
/* Insert extent into huge. */
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_lock(tsdn, &arena->huge_mtx);
|
2016-03-24 12:09:28 +08:00
|
|
|
ql_elm_new(extent, ql_link);
|
|
|
|
ql_tail_insert(&arena->huge, extent, ql_link);
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &arena->huge_mtx);
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2014-10-16 09:02:02 +08:00
|
|
|
if (zero || (config_fill && unlikely(opt_zero))) {
|
2016-05-24 05:56:35 +08:00
|
|
|
if (!is_zeroed) {
|
|
|
|
memset(extent_addr_get(extent), 0,
|
|
|
|
extent_size_get(extent));
|
|
|
|
}
|
|
|
|
} else if (config_fill && unlikely(opt_junk_alloc)) {
|
|
|
|
memset(extent_addr_get(extent), JEMALLOC_ALLOC_JUNK,
|
|
|
|
extent_size_get(extent));
|
|
|
|
}
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2016-05-11 13:21:10 +08:00
|
|
|
arena_decay_tick(tsdn, arena);
|
2016-05-19 12:02:46 +08:00
|
|
|
return (extent_addr_get(extent));
|
2010-01-17 01:53:50 +08:00
|
|
|
}
|
|
|
|
|
Implement in-place huge allocation shrinking.
Trivial example:
#include <stdlib.h>
int main(void) {
void *ptr = malloc(1024 * 1024 * 8);
if (!ptr) return 1;
ptr = realloc(ptr, 1024 * 1024 * 4);
if (!ptr) return 1;
}
Before:
mmap(NULL, 8388608, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fcfff000000
mmap(NULL, 4194304, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fcffec00000
madvise(0x7fcfff000000, 8388608, MADV_DONTNEED) = 0
After:
mmap(NULL, 8388608, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1934800000
madvise(0x7f1934c00000, 4194304, MADV_DONTNEED) = 0
Closes #134
2014-09-30 22:33:46 +08:00
|
|
|
#ifdef JEMALLOC_JET
|
|
|
|
#undef huge_dalloc_junk
|
|
|
|
#define huge_dalloc_junk JEMALLOC_N(huge_dalloc_junk_impl)
|
|
|
|
#endif
|
|
|
|
static void
|
2016-05-11 13:21:10 +08:00
|
|
|
huge_dalloc_junk(tsdn_t *tsdn, void *ptr, size_t usize)
|
Implement in-place huge allocation shrinking.
Trivial example:
#include <stdlib.h>
int main(void) {
void *ptr = malloc(1024 * 1024 * 8);
if (!ptr) return 1;
ptr = realloc(ptr, 1024 * 1024 * 4);
if (!ptr) return 1;
}
Before:
mmap(NULL, 8388608, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fcfff000000
mmap(NULL, 4194304, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fcffec00000
madvise(0x7fcfff000000, 8388608, MADV_DONTNEED) = 0
After:
mmap(NULL, 8388608, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1934800000
madvise(0x7f1934c00000, 4194304, MADV_DONTNEED) = 0
Closes #134
2014-09-30 22:33:46 +08:00
|
|
|
{
|
|
|
|
|
2014-12-09 05:12:41 +08:00
|
|
|
if (config_fill && have_dss && unlikely(opt_junk_free)) {
|
Implement in-place huge allocation shrinking.
Trivial example:
#include <stdlib.h>
int main(void) {
void *ptr = malloc(1024 * 1024 * 8);
if (!ptr) return 1;
ptr = realloc(ptr, 1024 * 1024 * 4);
if (!ptr) return 1;
}
Before:
mmap(NULL, 8388608, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fcfff000000
mmap(NULL, 4194304, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fcffec00000
madvise(0x7fcfff000000, 8388608, MADV_DONTNEED) = 0
After:
mmap(NULL, 8388608, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1934800000
madvise(0x7f1934c00000, 4194304, MADV_DONTNEED) = 0
Closes #134
2014-09-30 22:33:46 +08:00
|
|
|
/*
|
|
|
|
* Only bother junk filling if the chunk isn't about to be
|
|
|
|
* unmapped.
|
|
|
|
*/
|
2016-05-11 13:21:10 +08:00
|
|
|
if (!config_munmap || (have_dss && chunk_in_dss(tsdn, ptr)))
|
2016-03-28 14:28:39 +08:00
|
|
|
memset(ptr, JEMALLOC_FREE_JUNK, usize);
|
Implement in-place huge allocation shrinking.
Trivial example:
#include <stdlib.h>
int main(void) {
void *ptr = malloc(1024 * 1024 * 8);
if (!ptr) return 1;
ptr = realloc(ptr, 1024 * 1024 * 4);
if (!ptr) return 1;
}
Before:
mmap(NULL, 8388608, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fcfff000000
mmap(NULL, 4194304, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fcffec00000
madvise(0x7fcfff000000, 8388608, MADV_DONTNEED) = 0
After:
mmap(NULL, 8388608, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1934800000
madvise(0x7f1934c00000, 4194304, MADV_DONTNEED) = 0
Closes #134
2014-09-30 22:33:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef JEMALLOC_JET
|
|
|
|
#undef huge_dalloc_junk
|
|
|
|
#define huge_dalloc_junk JEMALLOC_N(huge_dalloc_junk)
|
|
|
|
huge_dalloc_junk_t *huge_dalloc_junk = JEMALLOC_N(huge_dalloc_junk_impl);
|
|
|
|
#endif
|
|
|
|
|
2014-10-13 13:53:59 +08:00
|
|
|
static void
|
2016-05-19 12:02:46 +08:00
|
|
|
huge_ralloc_no_move_similar(tsdn_t *tsdn, extent_t *extent, size_t usize_min,
|
|
|
|
size_t usize_max, bool zero)
|
2014-10-13 13:53:59 +08:00
|
|
|
{
|
2015-09-12 07:18:53 +08:00
|
|
|
size_t usize, usize_next;
|
2016-05-19 12:02:46 +08:00
|
|
|
arena_t *arena = extent_arena_get(extent);
|
|
|
|
size_t oldsize = extent_size_get(extent);
|
Generalize chunk management hooks.
Add the "arena.<i>.chunk_hooks" mallctl, which replaces and expands on
the "arena.<i>.chunk.{alloc,dalloc,purge}" mallctls. The chunk hooks
allow control over chunk allocation/deallocation, decommit/commit,
purging, and splitting/merging, such that the application can rely on
jemalloc's internal chunk caching and retaining functionality, yet
implement a variety of chunk management mechanisms and policies.
Merge the chunks_[sz]ad_{mmap,dss} red-black trees into
chunks_[sz]ad_retained. This slightly reduces how hard jemalloc tries
to honor the dss precedence setting; prior to this change the precedence
setting was also consulted when recycling chunks.
Fix chunk purging. Don't purge chunks in arena_purge_stashed(); instead
deallocate them in arena_unstash_purged(), so that the dirty memory
linkage remains valid until after the last time it is used.
This resolves #176 and #201.
2015-07-28 23:28:19 +08:00
|
|
|
chunk_hooks_t chunk_hooks = CHUNK_HOOKS_INITIALIZER;
|
2015-09-25 07:38:45 +08:00
|
|
|
bool pre_zeroed, post_zeroed;
|
2014-10-13 13:53:59 +08:00
|
|
|
|
|
|
|
/* Increase usize to incorporate extra. */
|
2015-09-12 07:18:53 +08:00
|
|
|
for (usize = usize_min; usize < usize_max && (usize_next = s2u(usize+1))
|
|
|
|
<= oldsize; usize = usize_next)
|
|
|
|
; /* Do nothing. */
|
2014-10-13 13:53:59 +08:00
|
|
|
|
2014-10-15 13:20:00 +08:00
|
|
|
if (oldsize == usize)
|
|
|
|
return;
|
2014-10-13 13:53:59 +08:00
|
|
|
|
2016-03-24 12:09:28 +08:00
|
|
|
pre_zeroed = extent_zeroed_get(extent);
|
2015-03-19 09:55:33 +08:00
|
|
|
|
2014-10-16 09:02:02 +08:00
|
|
|
/* Fill if necessary (shrinking). */
|
|
|
|
if (oldsize > usize) {
|
2015-03-26 09:56:55 +08:00
|
|
|
size_t sdiff = oldsize - usize;
|
2014-12-09 05:12:41 +08:00
|
|
|
if (config_fill && unlikely(opt_junk_free)) {
|
2016-05-19 12:02:46 +08:00
|
|
|
memset((void *)((uintptr_t)extent_addr_get(extent) +
|
|
|
|
usize), JEMALLOC_FREE_JUNK, sdiff);
|
2015-09-25 07:38:45 +08:00
|
|
|
post_zeroed = false;
|
2015-08-28 12:45:51 +08:00
|
|
|
} else {
|
2016-05-11 13:21:10 +08:00
|
|
|
post_zeroed = !chunk_purge_wrapper(tsdn, arena,
|
2016-05-24 06:10:25 +08:00
|
|
|
&chunk_hooks, extent, usize, sdiff);
|
2014-10-16 09:02:02 +08:00
|
|
|
}
|
|
|
|
} else
|
2015-09-25 07:38:45 +08:00
|
|
|
post_zeroed = pre_zeroed;
|
2014-10-16 09:02:02 +08:00
|
|
|
|
2014-10-15 13:20:00 +08:00
|
|
|
/* Update the size of the huge allocation. */
|
2016-03-24 12:09:28 +08:00
|
|
|
assert(extent_size_get(extent) != usize);
|
2016-03-24 11:29:33 +08:00
|
|
|
malloc_mutex_lock(tsdn, &arena->huge_mtx);
|
2016-03-24 12:09:28 +08:00
|
|
|
extent_size_set(extent, usize);
|
2016-03-24 11:29:33 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &arena->huge_mtx);
|
2015-09-25 07:38:45 +08:00
|
|
|
/* Update zeroed. */
|
2016-03-24 12:09:28 +08:00
|
|
|
extent_zeroed_set(extent, post_zeroed);
|
2014-10-13 13:53:59 +08:00
|
|
|
|
2016-05-19 12:02:46 +08:00
|
|
|
arena_chunk_ralloc_huge_similar(tsdn, arena, extent, oldsize);
|
2014-10-13 13:53:59 +08:00
|
|
|
|
2014-10-15 13:20:00 +08:00
|
|
|
/* Fill if necessary (growing). */
|
2014-10-13 13:53:59 +08:00
|
|
|
if (oldsize < usize) {
|
2014-10-16 09:02:02 +08:00
|
|
|
if (zero || (config_fill && unlikely(opt_zero))) {
|
2015-09-25 07:38:45 +08:00
|
|
|
if (!pre_zeroed) {
|
2016-05-19 12:02:46 +08:00
|
|
|
memset((void *)
|
|
|
|
((uintptr_t)extent_addr_get(extent) +
|
|
|
|
oldsize), 0, usize - oldsize);
|
2014-11-18 01:54:49 +08:00
|
|
|
}
|
2014-12-09 05:12:41 +08:00
|
|
|
} else if (config_fill && unlikely(opt_junk_alloc)) {
|
2016-05-19 12:02:46 +08:00
|
|
|
memset((void *)((uintptr_t)extent_addr_get(extent) +
|
|
|
|
oldsize), JEMALLOC_ALLOC_JUNK, usize - oldsize);
|
2014-11-18 01:54:49 +08:00
|
|
|
}
|
2014-10-15 13:20:00 +08:00
|
|
|
}
|
2014-10-13 13:53:59 +08:00
|
|
|
}
|
|
|
|
|
Generalize chunk management hooks.
Add the "arena.<i>.chunk_hooks" mallctl, which replaces and expands on
the "arena.<i>.chunk.{alloc,dalloc,purge}" mallctls. The chunk hooks
allow control over chunk allocation/deallocation, decommit/commit,
purging, and splitting/merging, such that the application can rely on
jemalloc's internal chunk caching and retaining functionality, yet
implement a variety of chunk management mechanisms and policies.
Merge the chunks_[sz]ad_{mmap,dss} red-black trees into
chunks_[sz]ad_retained. This slightly reduces how hard jemalloc tries
to honor the dss precedence setting; prior to this change the precedence
setting was also consulted when recycling chunks.
Fix chunk purging. Don't purge chunks in arena_purge_stashed(); instead
deallocate them in arena_unstash_purged(), so that the dirty memory
linkage remains valid until after the last time it is used.
This resolves #176 and #201.
2015-07-28 23:28:19 +08:00
|
|
|
static bool
|
2016-05-19 12:02:46 +08:00
|
|
|
huge_ralloc_no_move_shrink(tsdn_t *tsdn, extent_t *extent, size_t usize)
|
2014-10-13 13:53:59 +08:00
|
|
|
{
|
2016-05-19 12:02:46 +08:00
|
|
|
arena_t *arena = extent_arena_get(extent);
|
|
|
|
size_t oldsize = extent_size_get(extent);
|
|
|
|
chunk_hooks_t chunk_hooks = chunk_hooks_get(tsdn, arena);
|
|
|
|
size_t cdiff = CHUNK_CEILING(oldsize) - CHUNK_CEILING(usize);
|
|
|
|
size_t sdiff = CHUNK_CEILING(usize) - usize;
|
2015-03-19 09:55:33 +08:00
|
|
|
|
2015-09-12 07:18:53 +08:00
|
|
|
assert(oldsize > usize);
|
|
|
|
|
Generalize chunk management hooks.
Add the "arena.<i>.chunk_hooks" mallctl, which replaces and expands on
the "arena.<i>.chunk.{alloc,dalloc,purge}" mallctls. The chunk hooks
allow control over chunk allocation/deallocation, decommit/commit,
purging, and splitting/merging, such that the application can rely on
jemalloc's internal chunk caching and retaining functionality, yet
implement a variety of chunk management mechanisms and policies.
Merge the chunks_[sz]ad_{mmap,dss} red-black trees into
chunks_[sz]ad_retained. This slightly reduces how hard jemalloc tries
to honor the dss precedence setting; prior to this change the precedence
setting was also consulted when recycling chunks.
Fix chunk purging. Don't purge chunks in arena_purge_stashed(); instead
deallocate them in arena_unstash_purged(), so that the dirty memory
linkage remains valid until after the last time it is used.
This resolves #176 and #201.
2015-07-28 23:28:19 +08:00
|
|
|
/* Split excess chunks. */
|
2016-05-19 12:02:46 +08:00
|
|
|
if (cdiff != 0) {
|
|
|
|
extent_t *trail = chunk_split_wrapper(tsdn, arena, &chunk_hooks,
|
|
|
|
extent, CHUNK_CEILING(usize), cdiff);
|
|
|
|
if (trail == NULL)
|
|
|
|
return (true);
|
2014-10-13 13:53:59 +08:00
|
|
|
|
2015-03-26 09:56:55 +08:00
|
|
|
if (config_fill && unlikely(opt_junk_free)) {
|
2016-05-19 12:02:46 +08:00
|
|
|
huge_dalloc_junk(tsdn, extent_addr_get(trail),
|
|
|
|
extent_size_get(trail));
|
|
|
|
}
|
|
|
|
|
2016-05-24 05:56:35 +08:00
|
|
|
arena_chunk_cache_dalloc(tsdn, arena, &chunk_hooks, trail);
|
2016-05-19 12:02:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Optionally fill trailing subchunk. */
|
|
|
|
if (sdiff != 0) {
|
|
|
|
bool post_zeroed;
|
|
|
|
|
|
|
|
if (config_fill && unlikely(opt_junk_free)) {
|
|
|
|
huge_dalloc_junk(tsdn,
|
|
|
|
(void *)((uintptr_t)extent_addr_get(extent) +
|
|
|
|
usize), sdiff);
|
2015-09-25 07:38:45 +08:00
|
|
|
post_zeroed = false;
|
2015-08-28 12:45:51 +08:00
|
|
|
} else {
|
2016-05-11 13:21:10 +08:00
|
|
|
post_zeroed = !chunk_purge_wrapper(tsdn, arena,
|
2016-05-24 06:10:25 +08:00
|
|
|
&chunk_hooks, extent, usize, sdiff);
|
2014-10-16 09:02:02 +08:00
|
|
|
|
2016-05-19 12:02:46 +08:00
|
|
|
if (config_fill && unlikely(opt_zero) && !post_zeroed) {
|
|
|
|
memset((void *)
|
|
|
|
((uintptr_t)extent_addr_get(extent) +
|
|
|
|
usize), 0, sdiff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
extent_zeroed_set(extent, post_zeroed);
|
|
|
|
}
|
2014-10-13 13:53:59 +08:00
|
|
|
|
2016-05-19 12:02:46 +08:00
|
|
|
arena_chunk_ralloc_huge_shrink(tsdn, arena, extent, oldsize);
|
Generalize chunk management hooks.
Add the "arena.<i>.chunk_hooks" mallctl, which replaces and expands on
the "arena.<i>.chunk.{alloc,dalloc,purge}" mallctls. The chunk hooks
allow control over chunk allocation/deallocation, decommit/commit,
purging, and splitting/merging, such that the application can rely on
jemalloc's internal chunk caching and retaining functionality, yet
implement a variety of chunk management mechanisms and policies.
Merge the chunks_[sz]ad_{mmap,dss} red-black trees into
chunks_[sz]ad_retained. This slightly reduces how hard jemalloc tries
to honor the dss precedence setting; prior to this change the precedence
setting was also consulted when recycling chunks.
Fix chunk purging. Don't purge chunks in arena_purge_stashed(); instead
deallocate them in arena_unstash_purged(), so that the dirty memory
linkage remains valid until after the last time it is used.
This resolves #176 and #201.
2015-07-28 23:28:19 +08:00
|
|
|
|
|
|
|
return (false);
|
2014-10-13 13:53:59 +08:00
|
|
|
}
|
|
|
|
|
Attempt to expand huge allocations in-place.
This adds support for expanding huge allocations in-place by requesting
memory at a specific address from the chunk allocator.
It's currently only implemented for the chunk recycling path, although
in theory it could also be done by optimistically allocating new chunks.
On Linux, it could attempt an in-place mremap. However, that won't work
in practice since the heap is grown downwards and memory is not unmapped
(in a normal build, at least).
Repeated vector reallocation micro-benchmark:
#include <string.h>
#include <stdlib.h>
int main(void) {
for (size_t i = 0; i < 100; i++) {
void *ptr = NULL;
size_t old_size = 0;
for (size_t size = 4; size < (1 << 30); size *= 2) {
ptr = realloc(ptr, size);
if (!ptr) return 1;
memset(ptr + old_size, 0xff, size - old_size);
old_size = size;
}
free(ptr);
}
}
The glibc allocator fails to do any in-place reallocations on this
benchmark once it passes the M_MMAP_THRESHOLD (default 128k) but it
elides the cost of copies via mremap, which is currently not something
that jemalloc can use.
With this improvement, jemalloc still fails to do any in-place huge
reallocations for the first outer loop, but then succeeds 100% of the
time for the remaining 99 iterations. The time spent doing allocations
and copies drops down to under 5%, with nearly all of it spent doing
purging + faulting (when huge pages are disabled) and the array memset.
An improved mremap API (MREMAP_RETAIN - #138) would be far more general
but this is a portable optimization and would still be useful on Linux
for xallocx.
Numbers with transparent huge pages enabled:
glibc (copies elided via MREMAP_MAYMOVE): 8.471s
jemalloc: 17.816s
jemalloc + no-op madvise: 13.236s
jemalloc + this commit: 6.787s
jemalloc + this commit + no-op madvise: 6.144s
Numbers with transparent huge pages disabled:
glibc (copies elided via MREMAP_MAYMOVE): 15.403s
jemalloc: 39.456s
jemalloc + no-op madvise: 12.768s
jemalloc + this commit: 15.534s
jemalloc + this commit + no-op madvise: 6.354s
Closes #137
2014-10-04 13:39:32 +08:00
|
|
|
static bool
|
2016-05-19 12:02:46 +08:00
|
|
|
huge_ralloc_no_move_expand(tsdn_t *tsdn, extent_t *extent, size_t usize,
|
|
|
|
bool zero)
|
2016-03-24 12:09:28 +08:00
|
|
|
{
|
2016-05-19 12:02:46 +08:00
|
|
|
arena_t *arena = extent_arena_get(extent);
|
|
|
|
size_t oldsize = extent_size_get(extent);
|
|
|
|
bool is_zeroed_subchunk = extent_zeroed_get(extent);
|
|
|
|
bool is_zeroed_chunk = false;
|
|
|
|
chunk_hooks_t chunk_hooks = chunk_hooks_get(tsdn, arena);
|
|
|
|
size_t cdiff = CHUNK_CEILING(usize) - CHUNK_CEILING(oldsize);
|
|
|
|
void *nchunk =
|
|
|
|
(void *)CHUNK_CEILING((uintptr_t)extent_past_get(extent));
|
|
|
|
extent_t *trail;
|
|
|
|
|
|
|
|
if ((trail = arena_chunk_cache_alloc(tsdn, arena, &chunk_hooks, nchunk,
|
|
|
|
cdiff, chunksize, &is_zeroed_chunk)) == NULL) {
|
|
|
|
bool commit = true;
|
|
|
|
if ((trail = chunk_alloc_wrapper(tsdn, arena, &chunk_hooks,
|
2016-05-25 09:22:10 +08:00
|
|
|
nchunk, cdiff, chunksize, &is_zeroed_chunk, &commit, false))
|
|
|
|
== NULL)
|
2016-05-19 12:02:46 +08:00
|
|
|
return (true);
|
|
|
|
}
|
Attempt to expand huge allocations in-place.
This adds support for expanding huge allocations in-place by requesting
memory at a specific address from the chunk allocator.
It's currently only implemented for the chunk recycling path, although
in theory it could also be done by optimistically allocating new chunks.
On Linux, it could attempt an in-place mremap. However, that won't work
in practice since the heap is grown downwards and memory is not unmapped
(in a normal build, at least).
Repeated vector reallocation micro-benchmark:
#include <string.h>
#include <stdlib.h>
int main(void) {
for (size_t i = 0; i < 100; i++) {
void *ptr = NULL;
size_t old_size = 0;
for (size_t size = 4; size < (1 << 30); size *= 2) {
ptr = realloc(ptr, size);
if (!ptr) return 1;
memset(ptr + old_size, 0xff, size - old_size);
old_size = size;
}
free(ptr);
}
}
The glibc allocator fails to do any in-place reallocations on this
benchmark once it passes the M_MMAP_THRESHOLD (default 128k) but it
elides the cost of copies via mremap, which is currently not something
that jemalloc can use.
With this improvement, jemalloc still fails to do any in-place huge
reallocations for the first outer loop, but then succeeds 100% of the
time for the remaining 99 iterations. The time spent doing allocations
and copies drops down to under 5%, with nearly all of it spent doing
purging + faulting (when huge pages are disabled) and the array memset.
An improved mremap API (MREMAP_RETAIN - #138) would be far more general
but this is a portable optimization and would still be useful on Linux
for xallocx.
Numbers with transparent huge pages enabled:
glibc (copies elided via MREMAP_MAYMOVE): 8.471s
jemalloc: 17.816s
jemalloc + no-op madvise: 13.236s
jemalloc + this commit: 6.787s
jemalloc + this commit + no-op madvise: 6.144s
Numbers with transparent huge pages disabled:
glibc (copies elided via MREMAP_MAYMOVE): 15.403s
jemalloc: 39.456s
jemalloc + no-op madvise: 12.768s
jemalloc + this commit: 15.534s
jemalloc + this commit + no-op madvise: 6.354s
Closes #137
2014-10-04 13:39:32 +08:00
|
|
|
|
2016-05-19 12:02:46 +08:00
|
|
|
if (chunk_merge_wrapper(tsdn, arena, &chunk_hooks, extent, trail)) {
|
2016-05-24 05:56:35 +08:00
|
|
|
chunk_dalloc_wrapper(tsdn, arena, &chunk_hooks, trail);
|
2014-10-15 13:20:00 +08:00
|
|
|
return (true);
|
2016-05-19 12:02:46 +08:00
|
|
|
}
|
Attempt to expand huge allocations in-place.
This adds support for expanding huge allocations in-place by requesting
memory at a specific address from the chunk allocator.
It's currently only implemented for the chunk recycling path, although
in theory it could also be done by optimistically allocating new chunks.
On Linux, it could attempt an in-place mremap. However, that won't work
in practice since the heap is grown downwards and memory is not unmapped
(in a normal build, at least).
Repeated vector reallocation micro-benchmark:
#include <string.h>
#include <stdlib.h>
int main(void) {
for (size_t i = 0; i < 100; i++) {
void *ptr = NULL;
size_t old_size = 0;
for (size_t size = 4; size < (1 << 30); size *= 2) {
ptr = realloc(ptr, size);
if (!ptr) return 1;
memset(ptr + old_size, 0xff, size - old_size);
old_size = size;
}
free(ptr);
}
}
The glibc allocator fails to do any in-place reallocations on this
benchmark once it passes the M_MMAP_THRESHOLD (default 128k) but it
elides the cost of copies via mremap, which is currently not something
that jemalloc can use.
With this improvement, jemalloc still fails to do any in-place huge
reallocations for the first outer loop, but then succeeds 100% of the
time for the remaining 99 iterations. The time spent doing allocations
and copies drops down to under 5%, with nearly all of it spent doing
purging + faulting (when huge pages are disabled) and the array memset.
An improved mremap API (MREMAP_RETAIN - #138) would be far more general
but this is a portable optimization and would still be useful on Linux
for xallocx.
Numbers with transparent huge pages enabled:
glibc (copies elided via MREMAP_MAYMOVE): 8.471s
jemalloc: 17.816s
jemalloc + no-op madvise: 13.236s
jemalloc + this commit: 6.787s
jemalloc + this commit + no-op madvise: 6.144s
Numbers with transparent huge pages disabled:
glibc (copies elided via MREMAP_MAYMOVE): 15.403s
jemalloc: 39.456s
jemalloc + no-op madvise: 12.768s
jemalloc + this commit: 15.534s
jemalloc + this commit + no-op madvise: 6.354s
Closes #137
2014-10-04 13:39:32 +08:00
|
|
|
|
2014-10-16 09:02:02 +08:00
|
|
|
if (zero || (config_fill && unlikely(opt_zero))) {
|
|
|
|
if (!is_zeroed_subchunk) {
|
2016-05-19 12:02:46 +08:00
|
|
|
memset((void *)((uintptr_t)extent_addr_get(extent) +
|
|
|
|
oldsize), 0, CHUNK_CEILING(oldsize) - oldsize);
|
2014-10-16 09:02:02 +08:00
|
|
|
}
|
|
|
|
if (!is_zeroed_chunk) {
|
2016-05-19 12:02:46 +08:00
|
|
|
memset((void *)((uintptr_t)extent_addr_get(extent) +
|
2014-11-18 01:54:49 +08:00
|
|
|
CHUNK_CEILING(oldsize)), 0, usize -
|
2014-10-16 09:02:02 +08:00
|
|
|
CHUNK_CEILING(oldsize));
|
|
|
|
}
|
2014-12-09 05:12:41 +08:00
|
|
|
} else if (config_fill && unlikely(opt_junk_alloc)) {
|
2016-05-19 12:02:46 +08:00
|
|
|
memset((void *)((uintptr_t)extent_addr_get(extent) + oldsize),
|
|
|
|
JEMALLOC_ALLOC_JUNK, usize - oldsize);
|
2014-11-18 01:54:49 +08:00
|
|
|
}
|
2014-10-13 13:53:59 +08:00
|
|
|
|
2016-05-19 12:02:46 +08:00
|
|
|
if (usize < extent_size_get(extent))
|
|
|
|
extent_size_set(extent, usize);
|
|
|
|
|
|
|
|
arena_chunk_ralloc_huge_expand(tsdn, arena, extent, oldsize);
|
|
|
|
|
Attempt to expand huge allocations in-place.
This adds support for expanding huge allocations in-place by requesting
memory at a specific address from the chunk allocator.
It's currently only implemented for the chunk recycling path, although
in theory it could also be done by optimistically allocating new chunks.
On Linux, it could attempt an in-place mremap. However, that won't work
in practice since the heap is grown downwards and memory is not unmapped
(in a normal build, at least).
Repeated vector reallocation micro-benchmark:
#include <string.h>
#include <stdlib.h>
int main(void) {
for (size_t i = 0; i < 100; i++) {
void *ptr = NULL;
size_t old_size = 0;
for (size_t size = 4; size < (1 << 30); size *= 2) {
ptr = realloc(ptr, size);
if (!ptr) return 1;
memset(ptr + old_size, 0xff, size - old_size);
old_size = size;
}
free(ptr);
}
}
The glibc allocator fails to do any in-place reallocations on this
benchmark once it passes the M_MMAP_THRESHOLD (default 128k) but it
elides the cost of copies via mremap, which is currently not something
that jemalloc can use.
With this improvement, jemalloc still fails to do any in-place huge
reallocations for the first outer loop, but then succeeds 100% of the
time for the remaining 99 iterations. The time spent doing allocations
and copies drops down to under 5%, with nearly all of it spent doing
purging + faulting (when huge pages are disabled) and the array memset.
An improved mremap API (MREMAP_RETAIN - #138) would be far more general
but this is a portable optimization and would still be useful on Linux
for xallocx.
Numbers with transparent huge pages enabled:
glibc (copies elided via MREMAP_MAYMOVE): 8.471s
jemalloc: 17.816s
jemalloc + no-op madvise: 13.236s
jemalloc + this commit: 6.787s
jemalloc + this commit + no-op madvise: 6.144s
Numbers with transparent huge pages disabled:
glibc (copies elided via MREMAP_MAYMOVE): 15.403s
jemalloc: 39.456s
jemalloc + no-op madvise: 12.768s
jemalloc + this commit: 15.534s
jemalloc + this commit + no-op madvise: 6.354s
Closes #137
2014-10-04 13:39:32 +08:00
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
|
2014-01-13 07:05:44 +08:00
|
|
|
bool
|
2016-05-19 12:02:46 +08:00
|
|
|
huge_ralloc_no_move(tsdn_t *tsdn, extent_t *extent, size_t usize_min,
|
|
|
|
size_t usize_max, bool zero)
|
2010-01-17 01:53:50 +08:00
|
|
|
{
|
2015-09-12 07:18:53 +08:00
|
|
|
|
2016-05-19 12:02:46 +08:00
|
|
|
assert(s2u(extent_size_get(extent)) == extent_size_get(extent));
|
2016-02-26 07:29:49 +08:00
|
|
|
/* The following should have been caught by callers. */
|
|
|
|
assert(usize_min > 0 && usize_max <= HUGE_MAXCLASS);
|
2016-05-19 12:02:46 +08:00
|
|
|
/* Both allocation sizes must be huge to avoid a move. */
|
|
|
|
assert(extent_size_get(extent) >= chunksize && usize_max >= chunksize);
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2016-05-19 12:02:46 +08:00
|
|
|
if (CHUNK_CEILING(usize_max) > CHUNK_CEILING(extent_size_get(extent))) {
|
2015-09-12 07:18:53 +08:00
|
|
|
/* Attempt to expand the allocation in-place. */
|
2016-05-19 12:02:46 +08:00
|
|
|
if (!huge_ralloc_no_move_expand(tsdn, extent, usize_max,
|
|
|
|
zero)) {
|
2016-03-24 11:29:33 +08:00
|
|
|
arena_decay_tick(tsdn, extent_arena_get(extent));
|
2015-09-12 07:18:53 +08:00
|
|
|
return (false);
|
2016-02-20 12:09:31 +08:00
|
|
|
}
|
2015-09-12 07:18:53 +08:00
|
|
|
/* Try again, this time with usize_min. */
|
|
|
|
if (usize_min < usize_max && CHUNK_CEILING(usize_min) >
|
2016-05-19 12:02:46 +08:00
|
|
|
CHUNK_CEILING(extent_size_get(extent)) &&
|
|
|
|
huge_ralloc_no_move_expand(tsdn, extent, usize_min, zero)) {
|
2016-03-24 11:29:33 +08:00
|
|
|
arena_decay_tick(tsdn, extent_arena_get(extent));
|
2015-09-12 07:18:53 +08:00
|
|
|
return (false);
|
2016-02-20 12:09:31 +08:00
|
|
|
}
|
2014-10-06 08:54:10 +08:00
|
|
|
}
|
Implement in-place huge allocation shrinking.
Trivial example:
#include <stdlib.h>
int main(void) {
void *ptr = malloc(1024 * 1024 * 8);
if (!ptr) return 1;
ptr = realloc(ptr, 1024 * 1024 * 4);
if (!ptr) return 1;
}
Before:
mmap(NULL, 8388608, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fcfff000000
mmap(NULL, 4194304, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fcffec00000
madvise(0x7fcfff000000, 8388608, MADV_DONTNEED) = 0
After:
mmap(NULL, 8388608, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1934800000
madvise(0x7f1934c00000, 4194304, MADV_DONTNEED) = 0
Closes #134
2014-09-30 22:33:46 +08:00
|
|
|
|
Add {,r,s,d}allocm().
Add allocm(), rallocm(), sallocm(), and dallocm(), which are a
functional superset of malloc(), calloc(), posix_memalign(),
malloc_usable_size(), and free().
2010-09-18 06:46:18 +08:00
|
|
|
/*
|
2014-10-06 08:54:10 +08:00
|
|
|
* Avoid moving the allocation if the existing chunk size accommodates
|
|
|
|
* the new size.
|
Add {,r,s,d}allocm().
Add allocm(), rallocm(), sallocm(), and dallocm(), which are a
functional superset of malloc(), calloc(), posix_memalign(),
malloc_usable_size(), and free().
2010-09-18 06:46:18 +08:00
|
|
|
*/
|
2016-05-19 12:02:46 +08:00
|
|
|
if (CHUNK_CEILING(extent_size_get(extent)) >= CHUNK_CEILING(usize_min)
|
|
|
|
&& CHUNK_CEILING(extent_size_get(extent)) <=
|
|
|
|
CHUNK_CEILING(usize_max)) {
|
|
|
|
huge_ralloc_no_move_similar(tsdn, extent, usize_min, usize_max,
|
|
|
|
zero);
|
2016-03-24 11:29:33 +08:00
|
|
|
arena_decay_tick(tsdn, extent_arena_get(extent));
|
2014-01-13 07:05:44 +08:00
|
|
|
return (false);
|
2010-01-17 01:53:50 +08:00
|
|
|
}
|
|
|
|
|
Generalize chunk management hooks.
Add the "arena.<i>.chunk_hooks" mallctl, which replaces and expands on
the "arena.<i>.chunk.{alloc,dalloc,purge}" mallctls. The chunk hooks
allow control over chunk allocation/deallocation, decommit/commit,
purging, and splitting/merging, such that the application can rely on
jemalloc's internal chunk caching and retaining functionality, yet
implement a variety of chunk management mechanisms and policies.
Merge the chunks_[sz]ad_{mmap,dss} red-black trees into
chunks_[sz]ad_retained. This slightly reduces how hard jemalloc tries
to honor the dss precedence setting; prior to this change the precedence
setting was also consulted when recycling chunks.
Fix chunk purging. Don't purge chunks in arena_purge_stashed(); instead
deallocate them in arena_unstash_purged(), so that the dirty memory
linkage remains valid until after the last time it is used.
This resolves #176 and #201.
2015-07-28 23:28:19 +08:00
|
|
|
/* Attempt to shrink the allocation in-place. */
|
2016-05-19 12:02:46 +08:00
|
|
|
if (CHUNK_CEILING(extent_size_get(extent)) > CHUNK_CEILING(usize_max)) {
|
|
|
|
if (!huge_ralloc_no_move_shrink(tsdn, extent, usize_max)) {
|
2016-03-24 11:29:33 +08:00
|
|
|
arena_decay_tick(tsdn, extent_arena_get(extent));
|
2016-02-20 12:09:31 +08:00
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
}
|
2015-09-12 07:18:53 +08:00
|
|
|
return (true);
|
|
|
|
}
|
Implement in-place huge allocation shrinking.
Trivial example:
#include <stdlib.h>
int main(void) {
void *ptr = malloc(1024 * 1024 * 8);
if (!ptr) return 1;
ptr = realloc(ptr, 1024 * 1024 * 4);
if (!ptr) return 1;
}
Before:
mmap(NULL, 8388608, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fcfff000000
mmap(NULL, 4194304, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fcffec00000
madvise(0x7fcfff000000, 8388608, MADV_DONTNEED) = 0
After:
mmap(NULL, 8388608, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1934800000
madvise(0x7f1934c00000, 4194304, MADV_DONTNEED) = 0
Closes #134
2014-09-30 22:33:46 +08:00
|
|
|
|
2015-09-12 07:18:53 +08:00
|
|
|
static void *
|
2016-05-11 13:21:10 +08:00
|
|
|
huge_ralloc_move_helper(tsdn_t *tsdn, arena_t *arena, size_t usize,
|
2016-04-23 05:34:14 +08:00
|
|
|
size_t alignment, bool zero)
|
2015-09-12 07:18:53 +08:00
|
|
|
{
|
Attempt to expand huge allocations in-place.
This adds support for expanding huge allocations in-place by requesting
memory at a specific address from the chunk allocator.
It's currently only implemented for the chunk recycling path, although
in theory it could also be done by optimistically allocating new chunks.
On Linux, it could attempt an in-place mremap. However, that won't work
in practice since the heap is grown downwards and memory is not unmapped
(in a normal build, at least).
Repeated vector reallocation micro-benchmark:
#include <string.h>
#include <stdlib.h>
int main(void) {
for (size_t i = 0; i < 100; i++) {
void *ptr = NULL;
size_t old_size = 0;
for (size_t size = 4; size < (1 << 30); size *= 2) {
ptr = realloc(ptr, size);
if (!ptr) return 1;
memset(ptr + old_size, 0xff, size - old_size);
old_size = size;
}
free(ptr);
}
}
The glibc allocator fails to do any in-place reallocations on this
benchmark once it passes the M_MMAP_THRESHOLD (default 128k) but it
elides the cost of copies via mremap, which is currently not something
that jemalloc can use.
With this improvement, jemalloc still fails to do any in-place huge
reallocations for the first outer loop, but then succeeds 100% of the
time for the remaining 99 iterations. The time spent doing allocations
and copies drops down to under 5%, with nearly all of it spent doing
purging + faulting (when huge pages are disabled) and the array memset.
An improved mremap API (MREMAP_RETAIN - #138) would be far more general
but this is a portable optimization and would still be useful on Linux
for xallocx.
Numbers with transparent huge pages enabled:
glibc (copies elided via MREMAP_MAYMOVE): 8.471s
jemalloc: 17.816s
jemalloc + no-op madvise: 13.236s
jemalloc + this commit: 6.787s
jemalloc + this commit + no-op madvise: 6.144s
Numbers with transparent huge pages disabled:
glibc (copies elided via MREMAP_MAYMOVE): 15.403s
jemalloc: 39.456s
jemalloc + no-op madvise: 12.768s
jemalloc + this commit: 15.534s
jemalloc + this commit + no-op madvise: 6.354s
Closes #137
2014-10-04 13:39:32 +08:00
|
|
|
|
2015-09-12 07:18:53 +08:00
|
|
|
if (alignment <= chunksize)
|
2016-05-11 13:21:10 +08:00
|
|
|
return (huge_malloc(tsdn, arena, usize, zero));
|
|
|
|
return (huge_palloc(tsdn, arena, usize, alignment, zero));
|
Add {,r,s,d}allocm().
Add allocm(), rallocm(), sallocm(), and dallocm(), which are a
functional superset of malloc(), calloc(), posix_memalign(),
malloc_usable_size(), and free().
2010-09-18 06:46:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2016-05-19 12:02:46 +08:00
|
|
|
huge_ralloc(tsdn_t *tsdn, arena_t *arena, extent_t *extent, size_t usize,
|
|
|
|
size_t alignment, bool zero, tcache_t *tcache)
|
Add {,r,s,d}allocm().
Add allocm(), rallocm(), sallocm(), and dallocm(), which are a
functional superset of malloc(), calloc(), posix_memalign(),
malloc_usable_size(), and free().
2010-09-18 06:46:18 +08:00
|
|
|
{
|
|
|
|
void *ret;
|
|
|
|
size_t copysize;
|
|
|
|
|
2016-02-26 07:29:49 +08:00
|
|
|
/* The following should have been caught by callers. */
|
|
|
|
assert(usize > 0 && usize <= HUGE_MAXCLASS);
|
2016-05-19 12:02:46 +08:00
|
|
|
/* Both allocation sizes must be huge to avoid a move. */
|
|
|
|
assert(extent_size_get(extent) >= chunksize && usize >= chunksize);
|
2016-02-26 07:29:49 +08:00
|
|
|
|
Add {,r,s,d}allocm().
Add allocm(), rallocm(), sallocm(), and dallocm(), which are a
functional superset of malloc(), calloc(), posix_memalign(),
malloc_usable_size(), and free().
2010-09-18 06:46:18 +08:00
|
|
|
/* Try to avoid moving the allocation. */
|
2016-05-19 12:02:46 +08:00
|
|
|
if (!huge_ralloc_no_move(tsdn, extent, usize, usize, zero))
|
|
|
|
return (extent_addr_get(extent));
|
Add {,r,s,d}allocm().
Add allocm(), rallocm(), sallocm(), and dallocm(), which are a
functional superset of malloc(), calloc(), posix_memalign(),
malloc_usable_size(), and free().
2010-09-18 06:46:18 +08:00
|
|
|
|
2010-01-17 01:53:50 +08:00
|
|
|
/*
|
2016-05-19 12:02:46 +08:00
|
|
|
* usize and old size are different enough that we need to use a
|
Add {,r,s,d}allocm().
Add allocm(), rallocm(), sallocm(), and dallocm(), which are a
functional superset of malloc(), calloc(), posix_memalign(),
malloc_usable_size(), and free().
2010-09-18 06:46:18 +08:00
|
|
|
* different size class. In that case, fall back to allocating new
|
|
|
|
* space and copying.
|
2010-01-17 01:53:50 +08:00
|
|
|
*/
|
2016-04-06 07:52:36 +08:00
|
|
|
ret = huge_ralloc_move_helper(tsdn, arena, usize, alignment, zero);
|
2015-09-12 07:18:53 +08:00
|
|
|
if (ret == NULL)
|
|
|
|
return (NULL);
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2016-05-19 12:02:46 +08:00
|
|
|
copysize = (usize < extent_size_get(extent)) ? usize :
|
|
|
|
extent_size_get(extent);
|
|
|
|
memcpy(ret, extent_addr_get(extent), copysize);
|
|
|
|
isdalloct(tsdn, extent, extent_addr_get(extent),
|
|
|
|
extent_size_get(extent), tcache, true);
|
2010-01-17 01:53:50 +08:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-05-19 12:02:46 +08:00
|
|
|
huge_dalloc(tsdn_t *tsdn, extent_t *extent)
|
2010-01-17 01:53:50 +08:00
|
|
|
{
|
Move centralized chunk management into arenas.
Migrate all centralized data structures related to huge allocations and
recyclable chunks into arena_t, so that each arena can manage huge
allocations and recyclable virtual memory completely independently of
other arenas.
Add chunk node caching to arenas, in order to avoid contention on the
base allocator.
Use chunks_rtree to look up huge allocations rather than a red-black
tree. Maintain a per arena unsorted list of huge allocations (which
will be needed to enumerate huge allocations during arena reset).
Remove the --enable-ivsalloc option, make ivsalloc() always available,
and use it for size queries if --enable-debug is enabled. The only
practical implications to this removal are that 1) ivsalloc() is now
always available during live debugging (and the underlying radix tree is
available during core-based debugging), and 2) size query validation can
no longer be enabled independent of --enable-debug.
Remove the stats.chunks.{current,total,high} mallctls, and replace their
underlying statistics with simpler atomically updated counters used
exclusively for gdump triggering. These statistics are no longer very
useful because each arena manages chunks independently, and per arena
statistics provide similar information.
Simplify chunk synchronization code, now that base chunk allocation
cannot cause recursive lock acquisition.
2015-02-12 04:24:27 +08:00
|
|
|
arena_t *arena;
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2016-03-24 12:09:28 +08:00
|
|
|
arena = extent_arena_get(extent);
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_lock(tsdn, &arena->huge_mtx);
|
2016-03-24 12:09:28 +08:00
|
|
|
ql_remove(&arena->huge, extent, ql_link);
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &arena->huge_mtx);
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2016-03-24 12:09:28 +08:00
|
|
|
huge_dalloc_junk(tsdn, extent_addr_get(extent),
|
|
|
|
extent_size_get(extent));
|
2016-05-24 05:56:35 +08:00
|
|
|
arena_chunk_dalloc_huge(tsdn, extent_arena_get(extent), extent);
|
2016-02-20 12:09:31 +08:00
|
|
|
|
2016-05-11 13:21:10 +08:00
|
|
|
arena_decay_tick(tsdn, arena);
|
2010-01-17 01:53:50 +08:00
|
|
|
}
|
|
|
|
|
2014-11-28 03:22:36 +08:00
|
|
|
size_t
|
2016-05-19 12:02:46 +08:00
|
|
|
huge_salloc(tsdn_t *tsdn, const extent_t *extent)
|
2014-11-28 03:22:36 +08:00
|
|
|
{
|
Move centralized chunk management into arenas.
Migrate all centralized data structures related to huge allocations and
recyclable chunks into arena_t, so that each arena can manage huge
allocations and recyclable virtual memory completely independently of
other arenas.
Add chunk node caching to arenas, in order to avoid contention on the
base allocator.
Use chunks_rtree to look up huge allocations rather than a red-black
tree. Maintain a per arena unsorted list of huge allocations (which
will be needed to enumerate huge allocations during arena reset).
Remove the --enable-ivsalloc option, make ivsalloc() always available,
and use it for size queries if --enable-debug is enabled. The only
practical implications to this removal are that 1) ivsalloc() is now
always available during live debugging (and the underlying radix tree is
available during core-based debugging), and 2) size query validation can
no longer be enabled independent of --enable-debug.
Remove the stats.chunks.{current,total,high} mallctls, and replace their
underlying statistics with simpler atomically updated counters used
exclusively for gdump triggering. These statistics are no longer very
useful because each arena manages chunks independently, and per arena
statistics provide similar information.
Simplify chunk synchronization code, now that base chunk allocation
cannot cause recursive lock acquisition.
2015-02-12 04:24:27 +08:00
|
|
|
size_t size;
|
|
|
|
arena_t *arena;
|
2010-01-17 01:53:50 +08:00
|
|
|
|
2016-03-24 12:09:28 +08:00
|
|
|
arena = extent_arena_get(extent);
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_lock(tsdn, &arena->huge_mtx);
|
2016-03-24 12:09:28 +08:00
|
|
|
size = extent_size_get(extent);
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &arena->huge_mtx);
|
Move centralized chunk management into arenas.
Migrate all centralized data structures related to huge allocations and
recyclable chunks into arena_t, so that each arena can manage huge
allocations and recyclable virtual memory completely independently of
other arenas.
Add chunk node caching to arenas, in order to avoid contention on the
base allocator.
Use chunks_rtree to look up huge allocations rather than a red-black
tree. Maintain a per arena unsorted list of huge allocations (which
will be needed to enumerate huge allocations during arena reset).
Remove the --enable-ivsalloc option, make ivsalloc() always available,
and use it for size queries if --enable-debug is enabled. The only
practical implications to this removal are that 1) ivsalloc() is now
always available during live debugging (and the underlying radix tree is
available during core-based debugging), and 2) size query validation can
no longer be enabled independent of --enable-debug.
Remove the stats.chunks.{current,total,high} mallctls, and replace their
underlying statistics with simpler atomically updated counters used
exclusively for gdump triggering. These statistics are no longer very
useful because each arena manages chunks independently, and per arena
statistics provide similar information.
Simplify chunk synchronization code, now that base chunk allocation
cannot cause recursive lock acquisition.
2015-02-12 04:24:27 +08:00
|
|
|
|
|
|
|
return (size);
|
2010-01-17 01:53:50 +08:00
|
|
|
}
|
|
|
|
|
2014-08-19 07:22:13 +08:00
|
|
|
prof_tctx_t *
|
2016-05-19 12:02:46 +08:00
|
|
|
huge_prof_tctx_get(tsdn_t *tsdn, const extent_t *extent)
|
2010-02-11 02:37:56 +08:00
|
|
|
{
|
Move centralized chunk management into arenas.
Migrate all centralized data structures related to huge allocations and
recyclable chunks into arena_t, so that each arena can manage huge
allocations and recyclable virtual memory completely independently of
other arenas.
Add chunk node caching to arenas, in order to avoid contention on the
base allocator.
Use chunks_rtree to look up huge allocations rather than a red-black
tree. Maintain a per arena unsorted list of huge allocations (which
will be needed to enumerate huge allocations during arena reset).
Remove the --enable-ivsalloc option, make ivsalloc() always available,
and use it for size queries if --enable-debug is enabled. The only
practical implications to this removal are that 1) ivsalloc() is now
always available during live debugging (and the underlying radix tree is
available during core-based debugging), and 2) size query validation can
no longer be enabled independent of --enable-debug.
Remove the stats.chunks.{current,total,high} mallctls, and replace their
underlying statistics with simpler atomically updated counters used
exclusively for gdump triggering. These statistics are no longer very
useful because each arena manages chunks independently, and per arena
statistics provide similar information.
Simplify chunk synchronization code, now that base chunk allocation
cannot cause recursive lock acquisition.
2015-02-12 04:24:27 +08:00
|
|
|
prof_tctx_t *tctx;
|
|
|
|
arena_t *arena;
|
2010-02-11 02:37:56 +08:00
|
|
|
|
2016-03-24 12:09:28 +08:00
|
|
|
arena = extent_arena_get(extent);
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_lock(tsdn, &arena->huge_mtx);
|
2016-03-24 12:09:28 +08:00
|
|
|
tctx = extent_prof_tctx_get(extent);
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &arena->huge_mtx);
|
2012-03-14 07:31:41 +08:00
|
|
|
|
Move centralized chunk management into arenas.
Migrate all centralized data structures related to huge allocations and
recyclable chunks into arena_t, so that each arena can manage huge
allocations and recyclable virtual memory completely independently of
other arenas.
Add chunk node caching to arenas, in order to avoid contention on the
base allocator.
Use chunks_rtree to look up huge allocations rather than a red-black
tree. Maintain a per arena unsorted list of huge allocations (which
will be needed to enumerate huge allocations during arena reset).
Remove the --enable-ivsalloc option, make ivsalloc() always available,
and use it for size queries if --enable-debug is enabled. The only
practical implications to this removal are that 1) ivsalloc() is now
always available during live debugging (and the underlying radix tree is
available during core-based debugging), and 2) size query validation can
no longer be enabled independent of --enable-debug.
Remove the stats.chunks.{current,total,high} mallctls, and replace their
underlying statistics with simpler atomically updated counters used
exclusively for gdump triggering. These statistics are no longer very
useful because each arena manages chunks independently, and per arena
statistics provide similar information.
Simplify chunk synchronization code, now that base chunk allocation
cannot cause recursive lock acquisition.
2015-02-12 04:24:27 +08:00
|
|
|
return (tctx);
|
2012-03-14 07:31:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-05-19 12:02:46 +08:00
|
|
|
huge_prof_tctx_set(tsdn_t *tsdn, extent_t *extent, prof_tctx_t *tctx)
|
2012-03-14 07:31:41 +08:00
|
|
|
{
|
Move centralized chunk management into arenas.
Migrate all centralized data structures related to huge allocations and
recyclable chunks into arena_t, so that each arena can manage huge
allocations and recyclable virtual memory completely independently of
other arenas.
Add chunk node caching to arenas, in order to avoid contention on the
base allocator.
Use chunks_rtree to look up huge allocations rather than a red-black
tree. Maintain a per arena unsorted list of huge allocations (which
will be needed to enumerate huge allocations during arena reset).
Remove the --enable-ivsalloc option, make ivsalloc() always available,
and use it for size queries if --enable-debug is enabled. The only
practical implications to this removal are that 1) ivsalloc() is now
always available during live debugging (and the underlying radix tree is
available during core-based debugging), and 2) size query validation can
no longer be enabled independent of --enable-debug.
Remove the stats.chunks.{current,total,high} mallctls, and replace their
underlying statistics with simpler atomically updated counters used
exclusively for gdump triggering. These statistics are no longer very
useful because each arena manages chunks independently, and per arena
statistics provide similar information.
Simplify chunk synchronization code, now that base chunk allocation
cannot cause recursive lock acquisition.
2015-02-12 04:24:27 +08:00
|
|
|
arena_t *arena;
|
2012-03-14 07:31:41 +08:00
|
|
|
|
2016-03-24 12:09:28 +08:00
|
|
|
arena = extent_arena_get(extent);
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_lock(tsdn, &arena->huge_mtx);
|
2016-03-24 12:09:28 +08:00
|
|
|
extent_prof_tctx_set(extent, tctx);
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &arena->huge_mtx);
|
2012-03-14 07:31:41 +08:00
|
|
|
}
|
2015-09-15 14:48:11 +08:00
|
|
|
|
|
|
|
void
|
2016-05-19 12:02:46 +08:00
|
|
|
huge_prof_tctx_reset(tsdn_t *tsdn, extent_t *extent)
|
2015-09-15 14:48:11 +08:00
|
|
|
{
|
|
|
|
|
2016-05-19 12:02:46 +08:00
|
|
|
huge_prof_tctx_set(tsdn, extent, (prof_tctx_t *)(uintptr_t)1U);
|
2015-09-15 14:48:11 +08:00
|
|
|
}
|