31#ifndef detail_ut_page_alloc_h
32#define detail_ut_page_alloc_h
52#include "mysqld_error.h"
72 VirtualAlloc(
nullptr, n_bytes, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
74 ib::log_warn(ER_IB_MSG_856) <<
"page_aligned_alloc VirtualAlloc(" << n_bytes
83 void *ptr = mmap(
nullptr, n_bytes, PROT_READ | PROT_WRITE,
84 MAP_PRIVATE | MAP_ANON, -1, 0);
86 ib::log_warn(ER_IB_MSG_856) <<
"page_aligned_alloc mmap(" << n_bytes
91 return (ptr != (
void *)-1) ? ptr :
nullptr;
104 auto ret = VirtualFree(ptr, 0, MEM_RELEASE);
107 <<
"large_page_aligned_free VirtualFree(" << ptr
115 auto ret = munmap(ptr, n_bytes);
118 <<
"page_aligned_free munmap(" << ptr <<
", " << n_bytes
197 static inline bool free(
void *data)
noexcept {
241 static inline void *
deduce(
void *data)
noexcept {
243 const auto res =
reinterpret_cast<void *
>(
static_cast<uint8_t *
>(data) -
317#ifdef HAVE_PSI_MEMORY_INTERFACE
348#ifdef HAVE_PSI_MEMORY_INTERFACE
356 (
key, total_len, owner);
415template <
bool Pfs_memory_instrumentation_on>
426template <
bool Pfs_memory_instrumentation_on>
433template <
typename Impl>
435 template <
typename T = Impl>
440 template <
typename T = Impl>
443 return Impl::alloc(
size);
446 static inline size_t datalen(
void *ptr) {
return Impl::datalen(ptr); }
449 return Impl::low_level_info(ptr);
#define PSI_MEMORY_CALL(M)
Definition: psi_memory.h:36
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 unlikely(bool expr)
Definition: my_compiler.h:58
#define CPU_PAGE_SIZE
Definition: my_config.h:311
Definition: ut0tuple.h:57
static auto log_warn()
Definition: ut0log.h:452
static auto log_error()
Definition: ut0log.h:453
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
Page_type
Types of pages currently supported by ut:: library functions.
Definition: page_metadata.h:43
constexpr size_t round_to_next_multiple(size_t n, size_t m)
Calculates the next multiple of m that is bigger or equal to n.
Definition: helper.h:68
typename select_page_alloc_impl< Pfs_memory_instrumentation_on >::type select_page_alloc_impl_t
Just a small helper type which saves us some keystrokes.
Definition: page_alloc.h:428
void * page_aligned_alloc(size_t n_bytes)
Allocates system page-aligned memory.
Definition: page_alloc.h:67
bool page_aligned_free(void *ptr, size_t n_bytes)
Releases system page-aligned storage.
Definition: page_alloc.h:101
This file contains a set of libraries providing overloads for regular dynamic allocation routines whi...
Definition: aligned_alloc.h:48
Implementation bits and pieces for metadata for normal and large (huge) page allocations.
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.
Can be used to extract pointer and size of the allocation provided by the OS.
Definition: ut0new.h:140
Small wrapper which utilizes SFINAE to dispatch the call to appropriate aligned allocator implementat...
Definition: page_alloc.h:434
static std::enable_if<!T::is_pfs_instrumented_v, void * >::type alloc(size_t size, PSI_memory_key)
Definition: page_alloc.h:442
static std::enable_if< T::is_pfs_instrumented_v, void * >::type alloc(size_t size, PSI_memory_key key)
Definition: page_alloc.h:437
static Page_type page_type(void *ptr)
Definition: page_alloc.h:447
static size_t datalen(void *ptr)
Definition: page_alloc.h:446
static bool free(void *ptr)
Definition: page_alloc.h:445
static allocation_low_level_info low_level_info(void *ptr)
Definition: page_alloc.h:448
Helper struct implementing the type which represents the metadata for all types of PFS-aware page-ali...
Definition: page_metadata.h:198
static constexpr auto len
This is how much this metadata segment will be big.
Definition: page_metadata.h:203
static Page_type page_type(void *data)
Sanity check so that we can be sure that the size of our metadata segment is such so that the pointer...
Definition: page_metadata.h:221
Helper struct implementing the type which represents the metadata for all types of page-aligned alloc...
Definition: page_metadata.h:75
static constexpr auto len
This is how much tise metadata segment will be big.
Definition: page_metadata.h:77
static Page_type page_type(void *data)
Accessor to the page_type_t field.
Definition: page_metadata.h:110
static datalen_t datalen(void *data)
Sanity check so that we can be sure that the size of our metadata segment is such so that the next se...
Definition: page_metadata.h:101
size_t datalen_t
These are the types representing our memory fields.
Definition: page_metadata.h:80
Allocation routines which are purposed for allocating system page-aligned memory.
Definition: page_alloc.h:300
static bool free(PFS_metadata::data_segment_ptr data) noexcept
Releases storage allocated through Page_alloc_pfs::alloc().
Definition: page_alloc.h:343
static allocation_low_level_info low_level_info(void *data)
Retrieves the pointer and size of the allocation provided by the OS.
Definition: page_alloc.h:393
static size_t datalen(PFS_metadata::data_segment_ptr data)
Returns the number of bytes that have been allocated.
Definition: page_alloc.h:368
static void * alloc(std::size_t size, page_allocation_metadata::pfs_metadata::pfs_memory_key_t key)
Allocates system page-aligned memory.
Definition: page_alloc.h:309
static Page_type page_type(PFS_metadata::data_segment_ptr data)
Returns the Page_type.
Definition: page_alloc.h:380
static void * deduce(PFS_metadata::data_segment_ptr data) noexcept
Helper function which deduces the original pointer returned by Page_alloc_pfs from a pointer which is...
Definition: page_alloc.h:403
Allocation routines which are purposed for allocating system page-aligned memory.
Definition: page_alloc.h:174
static void * alloc(std::size_t size)
Allocates memory through large-page support.
Definition: page_alloc.h:182
static allocation_low_level_info low_level_info(void *data)
Retrieves the pointer and size of the allocation provided by the OS.
Definition: page_alloc.h:232
static void * deduce(void *data) noexcept
Helper function which deduces the original pointer returned by Page_alloc from a pointer which is pas...
Definition: page_alloc.h:241
static bool free(void *data) noexcept
Releases storage allocated through Page_alloc::alloc().
Definition: page_alloc.h:197
static Page_type page_type(void *data)
Returns the the type of the page.
Definition: page_alloc.h:220
static page_allocation_metadata::datalen_t datalen(void *data)
Returns the number of bytes that have been allocated.
Definition: page_alloc.h:209
Simple allocator traits.
Definition: allocator_traits.h:82
Simple utility meta-function which selects appropriate allocator variant (implementation) depending o...
Definition: page_alloc.h:416
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:105
Base of InnoDB utilities.