From 574700318e34a4d9432270e5044546c511a2815f Mon Sep 17 00:00:00 2001 From: Nathaniel Filardo Date: Thu, 14 Nov 2019 20:31:04 +0000 Subject: [PATCH 1/2] debug_is_empty: don't dealloc() free space We know that these are small objects and that they have already had their cache friendly offsets applied, so jump in to the dealloc path futher down, below the stats calls. Split small_dealloc_offseted into a wrapper around the core to avoid inlining too much into the debug function. While here, move the handling of the Remote objects into its own block so that `p` is out of scope thereafter. Fixes https://github.com/microsoft/snmalloc/issues/98 --- src/mem/alloc.h | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/mem/alloc.h b/src/mem/alloc.h index 6d91ed9..3a162c9 100644 --- a/src/mem/alloc.h +++ b/src/mem/alloc.h @@ -895,13 +895,15 @@ namespace snmalloc }; // Destroy the message queue so that it has no stub message. - Remote* p = message_queue().destroy(); - - while (p != nullptr) { - Remote* n = p->non_atomic_next; - handle_dealloc_remote(p); - p = n; + Remote* p = message_queue().destroy(); + + while (p != nullptr) + { + Remote* n = p->non_atomic_next; + handle_dealloc_remote(p); + p = n; + } } for (size_t i = 0; i < NUM_SMALL_CLASSES; i++) @@ -911,7 +913,10 @@ namespace snmalloc while (prev != nullptr) { auto n = Metaslab::follow_next(prev); - dealloc(remove_cache_friendly_offset(prev, i)); + + Superslab* super = Superslab::get(prev); + small_dealloc_offseted_inner(super, prev, i); + prev = n; } @@ -1222,6 +1227,12 @@ namespace snmalloc MEASURE_TIME(small_dealloc, 4, 16); stats().sizeclass_dealloc(sizeclass); + small_dealloc_offseted_inner(super, p, sizeclass); + } + + SNMALLOC_FAST_PATH void small_dealloc_offseted_inner( + Superslab* super, void* p, sizeclass_t sizeclass) + { Slab* slab = Slab::get(p); if (likely(slab->dealloc_fast(super, p))) return; From 3b2f521c4608fe07b4563de27c6d44fcad5dce6f Mon Sep 17 00:00:00 2001 From: Nathaniel Filardo Date: Sat, 3 Aug 2019 22:51:22 +0100 Subject: [PATCH 2/2] allocstats: assert count doesn't go negative --- src/mem/allocstats.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mem/allocstats.h b/src/mem/allocstats.h index 7b68ae7..19388f1 100644 --- a/src/mem/allocstats.h +++ b/src/mem/allocstats.h @@ -34,6 +34,7 @@ namespace snmalloc void dec() { + assert(current > 0); current--; }