From fed9a880c811fc56f7563efcb0a70c6ffe401c5f Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Wed, 19 Apr 2017 16:14:54 -0700 Subject: [PATCH] Trim before commit in extent_recycle(). This avoids creating clean committed pages as a side effect of aligned allocation. For configurations that decommit memory, purged pages are decommitted, and decommitted extents cannot be coalesced with committed extents. Unless the clean committed pages happen to be selected during allocation, they cause unnecessary permanent extent fragmentation. This resolves #766. --- src/extent.c | 8 ++++++-- src/extent_mmap.c | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/extent.c b/src/extent.c index 6b7da3f9..d08ccdb3 100644 --- a/src/extent.c +++ b/src/extent.c @@ -829,12 +829,16 @@ extent_recycle(tsdn_t *tsdn, arena_t *arena, extent_hooks_t **r_extent_hooks, rtree_ctx_t rtree_ctx_fallback; rtree_ctx_t *rtree_ctx = tsdn_rtree_ctx(tsdn, &rtree_ctx_fallback); + bool committed = false; extent_t *extent = extent_recycle_extract(tsdn, arena, r_extent_hooks, rtree_ctx, extents, false, new_addr, size, pad, alignment, slab, - zero, commit); + zero, &committed); if (extent == NULL) { return NULL; } + if (committed) { + *commit = true; + } extent = extent_recycle_split(tsdn, arena, r_extent_hooks, rtree_ctx, extents, new_addr, size, pad, alignment, slab, szind, extent); @@ -996,7 +1000,7 @@ extent_grow_retained(tsdn_t *tsdn, arena_t *arena, assert(new_addr == NULL || leadsize == 0); assert(alloc_size >= leadsize + esize); size_t trailsize = alloc_size - leadsize - esize; - if (extent_zeroed_get(extent)) { + if (extent_zeroed_get(extent) && extent_committed_get(extent)) { *zero = true; } if (extent_committed_get(extent)) { diff --git a/src/extent_mmap.c b/src/extent_mmap.c index b1862753..be099373 100644 --- a/src/extent_mmap.c +++ b/src/extent_mmap.c @@ -15,7 +15,9 @@ extent_alloc_mmap(void *new_addr, size_t size, size_t alignment, bool *zero, return NULL; } assert(ret != NULL); - *zero = true; + if (*commit) { + *zero = true; + } return ret; }