std::allocator::deallocate support sized-deallocation
authorPádraig Brady <pbrady@fb.com>
Mon, 20 May 2019 11:15:03 +0000 (11:15 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Mon, 20 May 2019 11:15:03 +0000 (12:15 +0100)
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  <pbrady@fb.com>

* libstdc++-v3/include/ext/new_allocator.h (deallocate): Pass the size
to the deallocator with -fsized-deallocation.

From-SVN: r271409

libstdc++-v3/ChangeLog
libstdc++-v3/include/ext/new_allocator.h

index 0b07d0efdcde5b50efc2b39bba8f8429587cdd14..74717dea5a03d5c4c36fb6ad4d50398ac9563f83 100644 (file)
@@ -1,3 +1,8 @@
+2019-05-20  Pádraig Brady  <pbrady@fb.com>
+
+       * libstdc++-v3/include/ext/new_allocator.h (deallocate): Pass the size
+       to the deallocator with -fsized-deallocation.
+
 2019-05-20  Jonathan Wakely  <jwakely@redhat.com>
 
        * testsuite/experimental/memory_resource/new_delete_resource.cc: Fix
index e24539100f9e9885cf0d590a8801740c9fa521f6..f1ff7da530b69975cba1918eb59e1021fb3057e5 100644 (file)
@@ -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