From e5178b986a66848440fbb076287c5a0f87d86c6f Mon Sep 17 00:00:00 2001 From: =?utf8?q?P=C3=A1draig=20Brady?= Date: Mon, 20 May 2019 11:15:03 +0000 Subject: [PATCH] std::allocator::deallocate support sized-deallocation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Pass the size to the allocator so that it may optimize deallocation. This was seen to significantly reduce the work required in jemalloc, with about 40% reduction in CPU cycles in the free path. Note jemalloc >= 5.2 is required to fix a crash with 0 sizes. 2019-05-20 Pádraig Brady * libstdc++-v3/include/ext/new_allocator.h (deallocate): Pass the size to the deallocator with -fsized-deallocation. From-SVN: r271409 --- libstdc++-v3/ChangeLog | 5 +++++ libstdc++-v3/include/ext/new_allocator.h | 14 +++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 0b07d0efdcd..74717dea5a0 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,8 @@ +2019-05-20 Pádraig Brady + + * libstdc++-v3/include/ext/new_allocator.h (deallocate): Pass the size + to the deallocator with -fsized-deallocation. + 2019-05-20 Jonathan Wakely * testsuite/experimental/memory_resource/new_delete_resource.cc: Fix diff --git a/libstdc++-v3/include/ext/new_allocator.h b/libstdc++-v3/include/ext/new_allocator.h index e24539100f9..f1ff7da530b 100644 --- a/libstdc++-v3/include/ext/new_allocator.h +++ b/libstdc++-v3/include/ext/new_allocator.h @@ -116,16 +116,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // __p is not permitted to be a null pointer. void - deallocate(pointer __p, size_type) + deallocate(pointer __p, size_type __t) { #if __cpp_aligned_new if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) { - ::operator delete(__p, std::align_val_t(alignof(_Tp))); + ::operator delete(__p, +# if __cpp_sized_deallocation + __t * sizeof(_Tp), +# endif + std::align_val_t(alignof(_Tp))); return; } #endif - ::operator delete(__p); + ::operator delete(__p +#if __cpp_sized_deallocation + , __t * sizeof(_Tp) +#endif + ); } size_type -- 2.30.2