MySQL 8.3.0
Source Code Documentation
ut::detail Namespace Reference

Classes

struct  Aligned_alloc
 Aligned allocation routines. More...
 
struct  Aligned_alloc_
 Small wrapper which utilizes SFINAE to dispatch the call to appropriate aligned allocator implementation. More...
 
struct  Aligned_alloc_impl
 
struct  Aligned_alloc_metadata
 Memory layout representation of metadata segment guaranteed by the inner workings of Aligned_alloc_impl. More...
 
struct  Aligned_alloc_pfs
 Aligned allocation routines which are instrumented through PFS (performance-schema). More...
 
struct  Aligned_array_deleter
 
struct  Aligned_deleter
 
struct  Alloc
 Allocation routines for non-extended alignment types, as opposed to Aligned_alloc for example. More...
 
struct  Alloc_
 Small wrapper which utilizes SFINAE to dispatch the call to appropriate allocator implementation. More...
 
struct  Alloc_arr
 Specialization of allocation routines for non-extended alignment types but which in comparison to Alloc are providing support for arrays. More...
 
struct  Alloc_fn
 Simple wrapping type around malloc, calloc and friends. More...
 
struct  Alloc_pfs
 Allocation routines for non-extended alignment types, as opposed to Aligned_alloc_pfs for example, but which are instrumented through PFS (performance-schema). More...
 
struct  allocator_base
 
struct  allocator_base_pfs
 
struct  allocator_traits
 Simple allocator traits. More...
 
struct  Array_deleter
 
struct  Deleter
 
struct  Large_alloc_
 Small wrapper which utilizes SFINAE to dispatch the call to appropriate aligned allocator implementation. More...
 
struct  Large_page_alloc
 Allocation routines which are purposed for allocating memory through the means of what is known as large (huge) pages. More...
 
struct  Large_page_alloc_pfs
 Allocation routines which are purposed for allocating memory through the means of what is known as large (huge) pages. More...
 
struct  Page_alloc
 Allocation routines which are purposed for allocating system page-aligned memory. More...
 
struct  Page_alloc_
 Small wrapper which utilizes SFINAE to dispatch the call to appropriate aligned allocator implementation. More...
 
struct  Page_alloc_metadata
 Helper struct implementing the type which represents the metadata for all types of page-aligned allocations, be it regular pages or huge-pages. More...
 
struct  Page_alloc_metadata_pfs
 Helper struct implementing the type which represents the metadata for all types of PFS-aware page-aligned allocations, be it regular pages or huge-pages. More...
 
struct  Page_alloc_pfs
 Allocation routines which are purposed for allocating system page-aligned memory. More...
 
struct  PFS_metadata
 Memory layout representation of PFS metadata segment that is used by the allocator variants which also want to trace the memory consumption through PFS (PSI) interface. More...
 
struct  select_alloc_impl
 Simple utility metafunction which selects appropriate allocator variant (implementation) depending on the input parameter(s). More...
 
struct  select_alloc_impl< true >
 
struct  select_large_page_alloc_impl
 Simple utility metafunction which selects appropriate allocator variant (implementation) depending on the input parameter(s). More...
 
struct  select_large_page_alloc_impl< true >
 
struct  select_malloc_impl
 Simple utility metafunction which selects appropriate allocator variant (implementation) depending on the input parameter(s). More...
 
struct  select_malloc_impl< false, false >
 
struct  select_malloc_impl< false, true >
 
struct  select_malloc_impl< true, Array_specialization >
 
struct  select_page_alloc_impl
 Simple utility meta-function which selects appropriate allocator variant (implementation) depending on the input parameter(s). More...
 
struct  select_page_alloc_impl< true >
 

Typedefs

template<bool Pfs_memory_instrumentation_on>
using select_alloc_impl_t = typename select_alloc_impl< Pfs_memory_instrumentation_on >::type
 Just a small helper type which saves us some keystrokes. More...
 
template<bool Pfs_memory_instrumentation_on, bool Array_specialization>
using select_malloc_impl_t = typename select_malloc_impl< Pfs_memory_instrumentation_on, Array_specialization >::type
 Just a small helper type which saves us some keystrokes. More...
 
template<bool Pfs_memory_instrumentation_on>
using select_large_page_alloc_impl_t = typename select_large_page_alloc_impl< Pfs_memory_instrumentation_on >::type
 Just a small helper type which saves us some keystrokes. More...
 
template<bool Pfs_memory_instrumentation_on>
using select_page_alloc_impl_t = typename select_page_alloc_impl< Pfs_memory_instrumentation_on >::type
 Just a small helper type which saves us some keystrokes. More...
 

Enumerations

enum class  Page_type { system_page = 0x10 , large_page = 0x20 }
 Types of pages currently supported by ut:: library functions. More...
 

Functions

void * malloc (size_t nbytes)
 
void * calloc (size_t nbytes)
 
void * realloc (void *ptr, size_t nbytes)
 
void free (void *ptr)
 
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. More...
 
constexpr size_t pow2_round (size_t n, size_t m)
 Calculates the biggest multiple of m that is not bigger than n when m is a power of two. More...
 
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. More...
 
void * large_page_aligned_alloc (size_t n_bytes)
 Allocates memory backed by large (huge) pages. More...
 
bool large_page_aligned_free (void *ptr, size_t n_bytes)
 Releases memory backed by large (huge) pages. More...
 
size_t large_page_size ()
 Queries the current size of large (huge) pages on running system. More...
 
std::vector< size_t > large_page_all_supported_sizes ()
 Queries all possible page-sizes. More...
 
void * page_aligned_alloc (size_t n_bytes)
 Allocates system page-aligned memory. More...
 
bool page_aligned_free (void *ptr, size_t n_bytes)
 Releases system page-aligned storage. More...
 
template<typename T , typename Tuple , size_t... Args_index_seq>
void construct_impl (void *mem, size_t offset, Tuple &&tuple, std::index_sequence< Args_index_seq... >)
 
template<typename T , typename Tuple >
void construct (void *mem, size_t offset, Tuple &&tuple)
 
constexpr uint64_t multiply_uint64_portable (uint64_t x, uint64_t y, uint64_t &hi)
 Calculates the 128bit result of multiplication of the two specified 64bit integers. More...
 
constexpr uint32_t hash_uint32_pair_ib (uint32_t n1, uint32_t n2)
 A helper method, it is used by hash_binary_ib for backward compatibility. More...
 
static int64_t read_from_1 (const byte *addr)
 
static int64_t read_from_2 (const byte *addr)
 
static int64_t read_from_4 (const byte *addr)
 
static int64_t read_from_8 (const byte *addr)
 

Variables

static constexpr auto SUPER_PAGE_SIZE = VM_FLAGS_SUPERPAGE_SIZE_2MB
 Superpage size to be used (2MB). More...
 
template<typename >
constexpr bool is_unbounded_array_v = false
 
template<typename T >
constexpr bool is_unbounded_array_v< T[]> = true
 
template<typename >
constexpr bool is_bounded_array_v = false
 
template<typename T , std::size_t N>
constexpr bool is_bounded_array_v< T[N]> = true
 
template<typename >
constexpr size_t bounded_array_size_v = 0
 
template<typename T , std::size_t N>
constexpr size_t bounded_array_size_v< T[N]> = N
 
thread_local uint64_t random_seed = ut::this_thread_hash + my_timer_cycles()
 Seed value of ut::random_64() More...
 
std::array< std::array< uint64_t, 8 >, 256 > tab_hash_lookup_table
 Table for Tabulation Hashing, precomputed hash values for all byte values. More...
 

Typedef Documentation

◆ select_alloc_impl_t

template<bool Pfs_memory_instrumentation_on>
using ut::detail::select_alloc_impl_t = typedef typename select_alloc_impl<Pfs_memory_instrumentation_on>::type

Just a small helper type which saves us some keystrokes.

◆ select_large_page_alloc_impl_t

template<bool Pfs_memory_instrumentation_on>
using ut::detail::select_large_page_alloc_impl_t = typedef typename select_large_page_alloc_impl<Pfs_memory_instrumentation_on>::type

Just a small helper type which saves us some keystrokes.

◆ select_malloc_impl_t

template<bool Pfs_memory_instrumentation_on, bool Array_specialization>
using ut::detail::select_malloc_impl_t = typedef typename select_malloc_impl<Pfs_memory_instrumentation_on, Array_specialization>::type

Just a small helper type which saves us some keystrokes.

◆ select_page_alloc_impl_t

template<bool Pfs_memory_instrumentation_on>
using ut::detail::select_page_alloc_impl_t = typedef typename select_page_alloc_impl<Pfs_memory_instrumentation_on>::type

Just a small helper type which saves us some keystrokes.

Enumeration Type Documentation

◆ Page_type

enum class ut::detail::Page_type
strong

Types of pages currently supported by ut:: library functions.

Enumerator
system_page 
large_page 

Function Documentation

◆ calc_align()

constexpr size_t ut::detail::calc_align ( size_t  n,
size_t  m 
)
constexpr

Calculates the smallest multiple of m that is not smaller than n when m is a power of two.

In other words, rounds n up to m * k.

Parameters
nin: number to round up
min: alignment, must be a power of two
Returns
n rounded up to the smallest possible integer multiple of m

◆ calloc()

void * ut::detail::calloc ( size_t  nbytes)
inline

◆ construct()

template<typename T , typename Tuple >
void ut::detail::construct ( void *  mem,
size_t  offset,
Tuple &&  tuple 
)
inline

◆ construct_impl()

template<typename T , typename Tuple , size_t... Args_index_seq>
void ut::detail::construct_impl ( void *  mem,
size_t  offset,
Tuple &&  tuple,
std::index_sequence< Args_index_seq... >   
)
inline

◆ free()

void ut::detail::free ( void *  ptr)
inline

◆ hash_uint32_pair_ib()

constexpr uint32_t ut::detail::hash_uint32_pair_ib ( uint32_t  n1,
uint32_t  n2 
)
constexpr

A helper method, it is used by hash_binary_ib for backward compatibility.

NOTE: Do not use this method, it produces results that are not hashed well. Especially for sequences of pairs of <i+n, j+n> over n.

◆ large_page_aligned_alloc()

void * ut::detail::large_page_aligned_alloc ( size_t  n_bytes)
inline

Allocates memory backed by large (huge) pages.

Parameters
[in]n_bytesSize of storage (in bytes) requested to be allocated.
Returns
Pointer to the allocated storage. nullptr if allocation failed.

◆ large_page_aligned_free()

bool ut::detail::large_page_aligned_free ( void *  ptr,
size_t  n_bytes 
)
inline

Releases memory backed by large (huge) pages.

Parameters
[in]ptrPointer to large (huge) page aligned storage.
[in]n_bytesSize of the storage.
Returns
Returns true if releasing the large (huge) page succeeded.

◆ large_page_all_supported_sizes()

std::vector< size_t > ut::detail::large_page_all_supported_sizes ( )
inline

Queries all possible page-sizes.

Solaris allows picking one at runtime which is contrary to how Linux, Windows and OSX does.

Returns
std::vector of supported page sizes (in bytes).

◆ large_page_size()

size_t ut::detail::large_page_size ( )
inline

Queries the current size of large (huge) pages on running system.

Queries the page-size that is next to the minimum supported page-size Lowest supported page size is usually 4K on x86_64 whereas it's 8K on SPARC.

Returns
Large (huge) page size in bytes.
Minimum supported large (huge) page size in bytes.

◆ malloc()

void * ut::detail::malloc ( size_t  nbytes)
inline

◆ multiply_uint64_portable()

constexpr uint64_t ut::detail::multiply_uint64_portable ( uint64_t  x,
uint64_t  y,
uint64_t &  hi 
)
constexpr

Calculates the 128bit result of multiplication of the two specified 64bit integers.

Parameters
[in]xFirst number to multiply.
[in]ySecond number to multiply.
[out]hiA reference to 64bit integer that will store higher 64bits of the result.
Returns
The lower 64bit of the result.

◆ page_aligned_alloc()

void * ut::detail::page_aligned_alloc ( size_t  n_bytes)
inline

Allocates system page-aligned memory.

Parameters
[in]n_bytesSize of storage (in bytes) requested to be allocated.
Returns
Pointer to the allocated storage. nullptr if allocation failed.

◆ page_aligned_free()

bool ut::detail::page_aligned_free ( void *  ptr,
size_t  n_bytes 
)
inline

Releases system page-aligned storage.

Parameters
[in]ptrPointer to system page-aligned storage.
[in]n_bytesSize of the storage.
Returns
True if releasing the page-aligned memory was successful.

◆ pow2_round()

constexpr size_t ut::detail::pow2_round ( size_t  n,
size_t  m 
)
constexpr

Calculates the biggest multiple of m that is not bigger than n when m is a power of two.

In other words, rounds n down to m * k.

Parameters
nin: number to round down
min: alignment, must be a power of two
Returns
n rounded down to the biggest possible integer multiple of m

◆ read_from_1()

static int64_t ut::detail::read_from_1 ( const byte addr)
inlinestatic

◆ read_from_2()

static int64_t ut::detail::read_from_2 ( const byte addr)
inlinestatic

◆ read_from_4()

static int64_t ut::detail::read_from_4 ( const byte addr)
inlinestatic

◆ read_from_8()

static int64_t ut::detail::read_from_8 ( const byte addr)
inlinestatic

◆ realloc()

void * ut::detail::realloc ( void *  ptr,
size_t  nbytes 
)
inline

◆ round_to_next_multiple()

constexpr size_t ut::detail::round_to_next_multiple ( size_t  n,
size_t  m 
)
constexpr

Calculates the next multiple of m that is bigger or equal to n.

Parameters
nin: number to find the next multiple of in terms of m
min: alignment, must be a power of two
Returns
next next multiple of m bigger or equal than n

Variable Documentation

◆ bounded_array_size_v

template<typename >
constexpr size_t ut::detail::bounded_array_size_v = 0
constexpr

◆ bounded_array_size_v< T[N]>

template<typename T , std::size_t N>
constexpr size_t ut::detail::bounded_array_size_v< T[N]> = N
constexpr

◆ is_bounded_array_v

template<typename >
constexpr bool ut::detail::is_bounded_array_v = false
constexpr

◆ is_bounded_array_v< T[N]>

template<typename T , std::size_t N>
constexpr bool ut::detail::is_bounded_array_v< T[N]> = true
constexpr

◆ is_unbounded_array_v

template<typename >
constexpr bool ut::detail::is_unbounded_array_v = false
constexpr

◆ is_unbounded_array_v< T[]>

template<typename T >
constexpr bool ut::detail::is_unbounded_array_v< T[]> = true
constexpr

◆ random_seed

thread_local uint64_t ut::detail::random_seed = ut::this_thread_hash + my_timer_cycles()

Seed value of ut::random_64()

◆ SUPER_PAGE_SIZE

constexpr auto ut::detail::SUPER_PAGE_SIZE = VM_FLAGS_SUPERPAGE_SIZE_2MB
staticconstexpr

Superpage size to be used (2MB).

◆ tab_hash_lookup_table

std::array< std::array< uint64_t, 8 >, 256 > ut::detail::tab_hash_lookup_table

Table for Tabulation Hashing, precomputed hash values for all byte values.

The table could be for different amount of bits per chunk than 8, but 8 seems to yield faster hash calculation than 4 or 16bits - 4bits require 16 XOR operations and sets of bit manipulations, while 16bit require bigger tables that slow down caches. The indexes are set such that hash values for a specific byte value are stored in the same cache line (8 values * 8 bytes = 64B). This way it should be much faster and less demanding on CPU caches to calculate results for small integers (where most bytes are 0).