]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: do not use ceph::allocator<> 41340/head
authorKefu Chai <kchai@redhat.com>
Fri, 14 May 2021 13:31:20 +0000 (21:31 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 14 May 2021 13:45:26 +0000 (21:45 +0800)
ceph::allocator was originally introduced to address
https://tracker.ceph.com/issues/39703, so that if tcmalloc < 2.6.2
detected, the homebrew allocator is used. otherwise std::allocator would
use the aligned_alloc() function which was not implemented by tcmalloc <
2.6.2. but the fix in tcmalloc implementing aligned_alloc() was
introduced in https://github.com/gperftools/gperftools/commit/d406f228.
that fix was included since gperftools 2.6.2.

- CentOS/RHEL8 includes gperftools 2.7,
- fedora 33 includes gperftools 2.8,
- ubuntu/focal comes with libgoogle-perftools-dev 2.7
- ubuntu/bionic ships libgoogle-perftools-dev 2.5. but since we
  detect libtcmalloc 2.6.2, when building on bionic, JeMalloc
  or libc allocator is used as fallback.

Signed-off-by: Kefu Chai <kchai@redhat.com>
CMakeLists.txt
src/common/allocator.h [deleted file]
src/librbd/ImageCtx.h
src/librbd/crypto/CryptoContextPool.h
src/perfglue/CMakeLists.txt

index 55647fa24aba6a7f969617f051bdda74380470ae..0e17a5403e42c19cf128df98ffd61451f1ddbef7 100644 (file)
@@ -339,7 +339,7 @@ jemalloc, and libc is supported. if not specified, will try to find tcmalloc, \
 and then jemalloc. If neither of then is found. use the one in libc.")
 if(ALLOCATOR)
   if(${ALLOCATOR} MATCHES "tcmalloc(_minimal)?")
-    find_package(gperftools REQUIRED)
+    find_package(gperftools 2.6.2 REQUIRED)
     set(HAVE_LIBTCMALLOC ON)
   elseif(${ALLOCATOR} STREQUAL "jemalloc")
     find_package(JeMalloc REQUIRED)
@@ -348,7 +348,7 @@ if(ALLOCATOR)
     message(FATAL_ERROR "Unsupported allocator selected: ${ALLOCATOR}")
   endif()
 else(ALLOCATOR)
-  find_package(gperftools)
+  find_package(gperftools 2.6.2)
   set(HAVE_LIBTCMALLOC ${gperftools_FOUND})
   if(NOT gperftools_FOUND)
     find_package(JeMalloc)
@@ -373,10 +373,6 @@ else()
   set(EXE_LINKER_USE_PIE ${ENABLE_SHARED})
 endif()
 
-if (HAVE_LIBTCMALLOC AND TCMALLOC_VERSION_STRING VERSION_LESS 2.6.2)
-  set(LIBTCMALLOC_MISSING_ALIGNED_ALLOC ON)
-endif()
-
 find_package(CURL REQUIRED)
 set(CMAKE_REQUIRED_INCLUDES ${CURL_INCLUDE_DIRS})
 set(CMAKE_REQUIRED_LIBRARIES ${CURL_LIBRARIES})
diff --git a/src/common/allocator.h b/src/common/allocator.h
deleted file mode 100644 (file)
index b28572f..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-// vim: ts=8 sw=2 smarttab
-
-#ifndef CEPH_COMMON_ALLOCATOR_H
-#define CEPH_COMMON_ALLOCATOR_H
-
-#include "acconfig.h"
-
-#ifdef LIBTCMALLOC_MISSING_ALIGNED_ALLOC
-#include <malloc.h>
-#include <new>
-#endif
-#include <memory>
-
-namespace ceph {
-
-#ifdef LIBTCMALLOC_MISSING_ALIGNED_ALLOC
-
-// If libtcmalloc is missing 'aligned_alloc', provide a new allocator class that
-// uses memalign which is what newer versions of tcmalloc do internally. C++17
-// will automatically use 'operator new(size_t, align_val_t)' for aligned
-// structures, which will invoke the missing 'aligned_alloc' tcmalloc function.
-// This method was added to tcmalloc (gperftools) in commit d406f228 after
-// the 2.6.1 release was tagged.
-template <typename T>
-struct allocator : public std::allocator<T> {
-  using pointer = typename std::allocator<T>::pointer;
-  using size_type = typename std::allocator<T>::size_type;
-
-  template<class U>
-  struct rebind {
-    typedef allocator<U> other;
-  };
-
-  allocator() noexcept {
-  }
-
-  allocator(const allocator& other) noexcept : std::allocator<T>(other) {
-  }
-
-  template <class U>
-  allocator(const allocator<U>& other) noexcept : std::allocator<T>(other) {
-  }
-
-  pointer allocate(size_type n, const void* hint = nullptr) {
-    if (n > this->max_size()) {
-      throw std::bad_alloc();
-    }
-
-    if (alignof(T) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) {
-      return static_cast<T*>(memalign(alignof(T), n * sizeof(T)));
-    }
-    return std::allocator<T>::allocate(n, hint);
-  }
-};
-
-#else  // LIBTCMALLOC_MISSING_ALIGNED_ALLOC
-
-// re-use the full std::allocator implementation if tcmalloc is functional
-
-template <typename T>
-using allocator = std::allocator<T>;
-
-#endif // LIBTCMALLOC_MISSING_ALIGNED_ALLOC
-
-} // namespace ceph
-
-#endif // CEPH_COMMON_ALLOCATOR_H
-
index 31d9a67547d62998e98da6feb18fc3043e254aba..ba44d314c86c8eb7df60783a061f5f034dce3c29 100644 (file)
@@ -13,7 +13,6 @@
 #include <string>
 #include <vector>
 
-#include "common/allocator.h"
 #include "common/ceph_mutex.h"
 #include "common/config_proxy.h"
 #include "common/event_socket.h"
@@ -200,9 +199,7 @@ namespace librbd {
 
     PluginRegistry<ImageCtx>* plugin_registry;
 
-    typedef boost::lockfree::queue<
-      io::AioCompletion*,
-      boost::lockfree::allocator<ceph::allocator<void>>> Completions;
+    using Completions = boost::lockfree::queue<io::AioCompletion*>;
 
     Completions event_socket_completions;
     EventSocket event_socket;
index c0ebce0c2333eac7123a9a57c66b6cc68e3e85a4..00486dacdd6591922ae97bce5045b29955424cf7 100644 (file)
@@ -5,7 +5,6 @@
 #define CEPH_LIBRBD_CRYPTO_CRYPTO_CONTEXT_POOL_H
 
 #include "librbd/crypto/DataCryptor.h"
-#include "common/allocator.h"
 #include "include/ceph_assert.h"
 #include <boost/lockfree/queue.hpp>
 
@@ -44,9 +43,7 @@ public:
       return m_data_cryptor->update_context(ctx, in, out, len);
     }
 
-    typedef boost::lockfree::queue<
-            T*,
-            boost::lockfree::allocator<ceph::allocator<void>>> ContextQueue;
+    using ContextQueue = boost::lockfree::queue<T*>;
 
 private:
     DataCryptor<T>* m_data_cryptor;
index b2cb608da28665866ceb76f808b7841f6d00b56b..66e2f2bf96315293e5c0a2b51377c2d50b8a88a7 100644 (file)
@@ -11,7 +11,7 @@ endif()
 option(WITH_PROFILER "build extra profiler binaries" OFF)
 
 if(WITH_PROFILER)
-  find_package(gperftools REQUIRED profiler)
+  find_package(gperftools 2.6.2 REQUIRED profiler)
   add_library(cpu_profiler STATIC
     cpu_profiler.cc)
   target_link_libraries(cpu_profiler