From: Kefu Chai Date: Fri, 14 May 2021 13:31:20 +0000 (+0800) Subject: librbd: do not use ceph::allocator<> X-Git-Tag: v17.1.0~1897^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8b19c0aef7a11f5d9ef87042e8524be435e2de1d;p=ceph.git librbd: do not use ceph::allocator<> 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 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 55647fa24aba..0e17a5403e42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 index b28572faac1f..000000000000 --- a/src/common/allocator.h +++ /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 -#include -#endif -#include - -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 -struct allocator : public std::allocator { - using pointer = typename std::allocator::pointer; - using size_type = typename std::allocator::size_type; - - template - struct rebind { - typedef allocator other; - }; - - allocator() noexcept { - } - - allocator(const allocator& other) noexcept : std::allocator(other) { - } - - template - allocator(const allocator& other) noexcept : std::allocator(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(memalign(alignof(T), n * sizeof(T))); - } - return std::allocator::allocate(n, hint); - } -}; - -#else // LIBTCMALLOC_MISSING_ALIGNED_ALLOC - -// re-use the full std::allocator implementation if tcmalloc is functional - -template -using allocator = std::allocator; - -#endif // LIBTCMALLOC_MISSING_ALIGNED_ALLOC - -} // namespace ceph - -#endif // CEPH_COMMON_ALLOCATOR_H - diff --git a/src/librbd/ImageCtx.h b/src/librbd/ImageCtx.h index 31d9a67547d6..ba44d314c86c 100644 --- a/src/librbd/ImageCtx.h +++ b/src/librbd/ImageCtx.h @@ -13,7 +13,6 @@ #include #include -#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* plugin_registry; - typedef boost::lockfree::queue< - io::AioCompletion*, - boost::lockfree::allocator>> Completions; + using Completions = boost::lockfree::queue; Completions event_socket_completions; EventSocket event_socket; diff --git a/src/librbd/crypto/CryptoContextPool.h b/src/librbd/crypto/CryptoContextPool.h index c0ebce0c2333..00486dacdd65 100644 --- a/src/librbd/crypto/CryptoContextPool.h +++ b/src/librbd/crypto/CryptoContextPool.h @@ -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 @@ -44,9 +43,7 @@ public: return m_data_cryptor->update_context(ctx, in, out, len); } - typedef boost::lockfree::queue< - T*, - boost::lockfree::allocator>> ContextQueue; + using ContextQueue = boost::lockfree::queue; private: DataCryptor* m_data_cryptor; diff --git a/src/perfglue/CMakeLists.txt b/src/perfglue/CMakeLists.txt index b2cb608da286..66e2f2bf9631 100644 --- a/src/perfglue/CMakeLists.txt +++ b/src/perfglue/CMakeLists.txt @@ -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