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>
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)
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)
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})
+++ /dev/null
-// -*- 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
-
#include <string>
#include <vector>
-#include "common/allocator.h"
#include "common/ceph_mutex.h"
#include "common/config_proxy.h"
#include "common/event_socket.h"
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;
#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>
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;
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