31#ifndef detail_ut_aligned_alloc_h
32#define detail_ut_aligned_alloc_h
113 template <
bool Zero_initialized>
114 static inline std::pair<data_segment_ptr, std::size_t>
alloc(
115 std::size_t
size, std::size_t alignment)
noexcept {
118 assert(alignment >
alignof(std::max_align_t));
206 const std::size_t data_len =
size + alignment;
207 void *
mem = Alloc_fn::alloc<Zero_initialized>(data_len);
217 reinterpret_cast<void *
>(
reinterpret_cast<std::uintptr_t
>(
mem) + 1);
218 std::size_t
buf_size = data_len - 1;
224 [[maybe_unused]]
auto ret = std::align(alignment,
size,
buf,
buf_size);
225 assert(ret !=
nullptr);
227 return {
buf,
reinterpret_cast<std::uintptr_t
>(
buf) -
228 reinterpret_cast<std::uintptr_t
>(
mem)};
274template <
typename Meta_1_type,
typename Meta_2_type>
290 "Aligned_alloc_impl provides a strong guarantee "
291 "of only up to Aligned_alloc_impl::metadata_size bytes.");
296 std::size_t meta_1_v)
noexcept {
297 assert(meta_1_v <= std::numeric_limits<meta_1_t>::max());
303 std::size_t meta_2_v)
noexcept {
304 assert(meta_2_v <= std::numeric_limits<meta_2_t>::max());
329 return reinterpret_cast<meta_1_t *
>(data) - 1;
405 template <
bool Zero_initialized>
406 static inline void *
alloc(std::size_t
size, std::size_t alignment) {
407 auto ret = Aligned_alloc_impl::alloc<Zero_initialized>(
size, alignment);
467 return reinterpret_cast<void *
>(
reinterpret_cast<std::uintptr_t
>(data) -
574 template <
bool Zero_initialized>
575 static inline void *
alloc(std::size_t
size, std::size_t alignment,
584 const auto total_len =
size + metadata_len;
586 Aligned_alloc_impl::alloc<Zero_initialized>(total_len, alignment);
587 if (
unlikely(!ret.first))
return nullptr;
596#ifdef HAVE_PSI_MEMORY_INTERFACE
602 const auto datalen = total_len + ret.second;
617 return static_cast<uint8_t *
>(ret.first) + metadata_len;
629#ifdef HAVE_PSI_MEMORY_INTERFACE
669 return reinterpret_cast<void *
>(
reinterpret_cast<std::uintptr_t
>(pfs_meta) -
677template <
bool Pfs_memory_instrumentation_on>
689template <
bool Pfs_memory_instrumentation_on>
696template <
typename Impl>
698 template <
bool Zero_initialized,
typename T = Impl>
701 return Impl::template alloc<Zero_initialized>(
size, alignment,
key);
703 template <
bool Zero_initialized,
typename T = Impl>
706 return Impl::template alloc<Zero_initialized>(
size, alignment);
709 static inline size_t datalen(
void *ptr) {
return Impl::datalen(ptr); }
#define PSI_MEMORY_CALL(M)
Definition: psi_memory.h:36
static char buf[MAX_BUF]
Definition: conf_to_src.cc:73
constexpr DWORD buf_size
Definition: create_def.cc:229
unsigned int PSI_memory_key
Instrumented memory key.
Definition: psi_memory_bits.h:49
#define free(A)
Definition: lexyy.cc:915
Header for compiler-dependent features.
constexpr bool likely(bool expr)
Definition: my_compiler.h:57
constexpr bool unlikely(bool expr)
Definition: my_compiler.h:58
Definition: buf0block_hint.cc:30
Definition: ut0tuple.h:57
size_t size(const char *const c)
Definition: base64.h:46
static PSI_memory_key memory_alloc(PSI_memory_key, size_t, struct PSI_thread **owner)
Definition: psi_memory_v2_empty.cc:35
static void memory_free(PSI_memory_key, size_t, struct PSI_thread *)
Definition: psi_memory_v2_empty.cc:53
constexpr size_t calc_align(size_t n, size_t m)
Calculates the smallest multiple of m that is not smaller than n when m is a power of two.
Definition: helper.h:45
typename select_alloc_impl< Pfs_memory_instrumentation_on >::type select_alloc_impl_t
Just a small helper type which saves us some keystrokes.
Definition: aligned_alloc.h:691
This file contains a set of libraries providing overloads for regular dynamic allocation routines whi...
Definition: aligned_alloc.h:48
required string key
Definition: replication_asynchronous_connection_failover.proto:60
required string type
Definition: replication_group_member_actions.proto:34
static MEM_ROOT mem
Definition: sql_servers.cc:100
Implementation bits and pieces for PFS metadata handling.
Small wrapper which utilizes SFINAE to dispatch the call to appropriate aligned allocator implementat...
Definition: aligned_alloc.h:697
static void free(void *ptr)
Definition: aligned_alloc.h:708
static size_t datalen(void *ptr)
Definition: aligned_alloc.h:709
static std::enable_if< T::is_pfs_instrumented_v, void * >::type alloc(size_t size, size_t alignment, PSI_memory_key key)
Definition: aligned_alloc.h:700
static std::enable_if<!T::is_pfs_instrumented_v, void * >::type alloc(size_t size, size_t alignment, PSI_memory_key)
Definition: aligned_alloc.h:705
Definition: aligned_alloc.h:51
static constexpr uint32_t metadata_size
Block of memory returned by this functor will have an additional (metadata) segment (at no additional...
Definition: aligned_alloc.h:58
static void free(void *ptr) noexcept
Releases storage allocated through alloc().
Definition: aligned_alloc.h:236
static std::pair< data_segment_ptr, std::size_t > alloc(std::size_t size, std::size_t alignment) noexcept
Dynamically allocates storage of given size and at the address aligned to the requested alignment.
Definition: aligned_alloc.h:114
void * data_segment_ptr
Alias that we will be using to denote ptr to DATA segment.
Definition: aligned_alloc.h:61
Aligned allocation routines which are instrumented through PFS (performance-schema).
Definition: aligned_alloc.h:561
static void * alloc(std::size_t size, std::size_t alignment, pfs_metadata::pfs_memory_key_t key)
Dynamically allocates storage of given size at the address aligned to the requested alignment.
Definition: aligned_alloc.h:575
static void free(PFS_metadata::data_segment_ptr data) noexcept
Releases storage dynamically allocated through Aligned_alloc_pfs::alloc().
Definition: aligned_alloc.h:626
static void * deduce(PFS_metadata::data_segment_ptr data) noexcept
Helper function which deduces the original pointer returned by Aligned_alloc_impl from a pointer whic...
Definition: aligned_alloc.h:662
static allocator_metadata::meta_2_t datalen(PFS_metadata::data_segment_ptr data)
Returns the number of bytes requested to be allocated.
Definition: aligned_alloc.h:651
Aligned allocation routines.
Definition: aligned_alloc.h:394
static void * alloc(std::size_t size, std::size_t alignment)
Dynamically allocates storage of given size and at the address aligned to the requested alignment.
Definition: aligned_alloc.h:406
static void * deduce(Aligned_alloc_impl::data_segment_ptr data) noexcept
Helper function which deduces the original pointer returned by Aligned_alloc_impl from a pointer whic...
Definition: aligned_alloc.h:462
static allocator_metadata::meta_2_t datalen(Aligned_alloc_impl::data_segment_ptr data)
Returns the number of bytes requested to be allocated.
Definition: aligned_alloc.h:451
static void free(Aligned_alloc_impl::data_segment_ptr data) noexcept
Releases storage dynamically allocated through Aligned_alloc::alloc().
Definition: aligned_alloc.h:437
static void free(void *ptr)
Definition: allocator_traits.h:105
Simple allocator traits.
Definition: allocator_traits.h:82
Simple utility metafunction which selects appropriate allocator variant (implementation) depending on...
Definition: aligned_alloc.h:678