mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-08-25 00:23:33 +03:00
Add extent_destroy_t and use it during arena destruction.
Add the extent_destroy_t extent destruction hook to extent_hooks_t, and use it during arena destruction. This hook explicitly communicates to the callee that the extent must be destroyed or tracked for later reuse, lest it be permanently leaked. Prior to this change, retained extents could unintentionally be leaked if extent retention was enabled. This resolves #560.
This commit is contained in:
parent
b9ab04a191
commit
c86c8f4ffb
10 changed files with 120 additions and 17 deletions
20
src/arena.c
20
src/arena.c
|
|
@ -1138,21 +1138,19 @@ arena_reset(tsd_t *tsd, arena_t *arena) {
|
|||
static void
|
||||
arena_destroy_retained(tsdn_t *tsdn, arena_t *arena) {
|
||||
/*
|
||||
* Iterate over the retained extents and blindly attempt to deallocate
|
||||
* them. This gives the extent allocator underlying the extent hooks an
|
||||
* opportunity to unmap all retained memory without having to keep its
|
||||
* own metadata structures, but if deallocation fails, that is the
|
||||
* application's decision/problem. In practice, retained extents are
|
||||
* leaked here if opt_retain unless the application provided custom
|
||||
* extent hooks, so best practice is to either disable retain (and avoid
|
||||
* dss for arenas to be destroyed), or provide custom extent hooks that
|
||||
* either unmap retained extents or track them for later use.
|
||||
* Iterate over the retained extents and destroy them. This gives the
|
||||
* extent allocator underlying the extent hooks an opportunity to unmap
|
||||
* all retained memory without having to keep its own metadata
|
||||
* structures. In practice, virtual memory for dss-allocated extents is
|
||||
* leaked here, so best practice is to avoid dss for arenas to be
|
||||
* destroyed, or provide custom extent hooks that track retained
|
||||
* dss-based extents for later reuse.
|
||||
*/
|
||||
extent_hooks_t *extent_hooks = extent_hooks_get(arena);
|
||||
extent_t *extent;
|
||||
while ((extent = extents_evict(tsdn, arena, &extent_hooks,
|
||||
&arena->extents_retained, 0)) != NULL) {
|
||||
extent_dalloc_wrapper_try(tsdn, arena, &extent_hooks, extent);
|
||||
extent_destroy_wrapper(tsdn, arena, &extent_hooks, extent);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1169,7 +1167,7 @@ arena_destroy(tsd_t *tsd, arena_t *arena) {
|
|||
*/
|
||||
assert(extents_npages_get(&arena->extents_dirty) == 0);
|
||||
|
||||
/* Attempt to deallocate retained memory. */
|
||||
/* Deallocate retained memory. */
|
||||
arena_destroy_retained(tsd_tsdn(tsd), arena);
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue