From ad96ba05c15d1b9bde275dba5fc1dca4362d7263 Mon Sep 17 00:00:00 2001 From: Nathaniel Filardo Date: Mon, 20 May 2019 13:23:51 +0100 Subject: [PATCH] largealloc: don't zero memory twice If the decommit strategy is DecommitSuperLazy, then both the constexpr if and the ordinary if would fire; add an else so we only fall into one. --- src/mem/alloc.h | 1 + src/mem/largealloc.h | 33 +++++++++------------------------ 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/mem/alloc.h b/src/mem/alloc.h index ff9c970..14e35e7 100644 --- a/src/mem/alloc.h +++ b/src/mem/alloc.h @@ -1263,6 +1263,7 @@ namespace snmalloc stats().large_dealloc(large_class); + // Cross-reference largealloc's alloc() decommitted condition. if ((decommit_strategy != DecommitNone) || (large_class > 0)) large_allocator.memory_provider.notify_not_using( pointer_offset(p, OS_PAGE_SIZE), rsize - OS_PAGE_SIZE); diff --git a/src/mem/largealloc.h b/src/mem/largealloc.h index 08048b9..80116d7 100644 --- a/src/mem/largealloc.h +++ b/src/mem/largealloc.h @@ -344,30 +344,14 @@ namespace snmalloc { stats.superslab_pop(); - if constexpr (decommit_strategy == DecommitSuperLazy) - { - if (static_cast(p)->get_kind() == Decommitted) - { - // The first page is already in "use" for the stack element, - // this will need zeroing for a YesZero call. - if constexpr (zero_mem == YesZero) - memory_provider.template zero(p, OS_PAGE_SIZE); + // Cross-reference alloc.h's large_dealloc decommitment condition + // and lazy_decommit_if_needed. + bool decommitted = + ((decommit_strategy == DecommitSuperLazy) && + (static_cast(p)->get_kind() == Decommitted)) || + (large_class > 0) || (decommit_strategy != DecommitNone); - // Notify we are using the rest of the allocation. - // Passing zero_mem ensures the PAL provides zeroed pages if - // required. - memory_provider.template notify_using( - pointer_offset(p, OS_PAGE_SIZE), - bits::align_up(size, OS_PAGE_SIZE) - OS_PAGE_SIZE); - } - else - { - if constexpr (zero_mem == YesZero) - memory_provider.template zero( - p, bits::align_up(size, OS_PAGE_SIZE)); - } - } - if ((decommit_strategy != DecommitNone) || (large_class > 0)) + if (decommitted) { // The first page is already in "use" for the stack element, // this will need zeroing for a YesZero call. @@ -375,7 +359,8 @@ namespace snmalloc memory_provider.template zero(p, OS_PAGE_SIZE); // Notify we are using the rest of the allocation. - // Passing zero_mem ensures the PAL provides zeroed pages if required. + // Passing zero_mem ensures the PAL provides zeroed pages if + // required. memory_provider.template notify_using( pointer_offset(p, OS_PAGE_SIZE), bits::align_up(size, OS_PAGE_SIZE) - OS_PAGE_SIZE);