MySQL 9.0.0
Source Code Documentation
ut::detail::Alloc_pfs Struct Reference

Allocation routines for non-extended alignment types, as opposed to Aligned_alloc_pfs for example, but which are instrumented through PFS (performance-schema). More...

#include <alloc.h>

Inheritance diagram for ut::detail::Alloc_pfs:
[legend]

Public Types

using pfs_metadata = PFS_metadata
 

Static Public Member Functions

template<bool Zero_initialized>
static void * alloc (std::size_t size, pfs_metadata::pfs_memory_key_t key)
 Dynamically allocates storage of given size at the address aligned to the requested alignment. More...
 
static void * realloc (PFS_metadata::data_segment_ptr data, std::size_t size, pfs_metadata::pfs_memory_key_t key)
 Reallocates the given area of memory, which if not nullptr, must be previously allocated by Alloc_pfs::alloc() or Alloc_pfs::realloc(). More...
 
static void free (PFS_metadata::data_segment_ptr data) noexcept
 Releases storage dynamically allocated through Alloc_pfs::alloc(). More...
 
static size_t datalen (PFS_metadata::data_segment_ptr data)
 Returns the number of bytes requested to be allocated. More...
 

Static Public Attributes

static constexpr auto metadata_len
 This is how much the metadata (PFS-META | VARLEN | PFS-META-OFFSET) segment will be big. More...
 
- Static Public Attributes inherited from ut::detail::allocator_traits< true >
static constexpr auto is_pfs_instrumented_v
 

Static Private Member Functions

static void * deduce (PFS_metadata::data_segment_ptr data) noexcept
 Helper function which deduces the original pointer returned by Alloc_pfs::alloc() from a pointer which is passed to us by the call-site. More...
 

Detailed Description

Allocation routines for non-extended alignment types, as opposed to Aligned_alloc_pfs for example, but which are instrumented through PFS (performance-schema).

Implemented in terms of PFS_metadata.

Memory layout representation looks like the following:


| PFS-META | VARLEN | PFS-META-OFFSET | DATA |

^ ^ ^ | | | | ------------------------— | | | OWNER | DATALEN | KEY | | | ------------------------— | | | ptr returned by | Alloc_fn | | ptr to be returned to call-site will be pointing here

OWNER field encodes the owning thread. DATALEN field encodes total size of memory consumed and not only the size of the DATA segment. KEY field encodes the PFS/PSI key.

VARLEN is the leftover variable-length segment that specialized implementations can further make use of by deducing its size from the following formulae: abs(alignof(max_align_t) - sizeof(PFS-META-OFFSET) - sizeof(PFS-META)). In code that would be std::abs(alignof(max_align_t) - PFS_metadata::size). Not used by this implementation.

PFS-META-OFFSET, strictly speaking, isn't necessary in this case of non-extended alignments, where alignment is always known in compile-time and thus the offset we will be storing into the PFS-META-OFFSET field is always going to be the same for the given platform. So, rather than serializing this piece of information into the memory as we do right now, we could very well be storing it into the compile-time evaluated constexpr constant. The reason why we don't do it is that there is no advantage (*) of doing so while we would be introducing a disadvantage of having to maintain separate specialization of PFS_metadata and code would be somewhat more fragmented.

(*) Extra space that we need to allocate in order to be able to fit the PFS_metadata is going to be the same regardless if there is PFS-META-OFFSET field or not. This is due to the fact that PFS-META segment alone is larger than alignof(max_align_t) so in order to keep the DATA segment suitably aligned (% alignof(max_align_t) == 0) we must choose the size for the whole PFS segment that is a multiple of alignof(max_align_t).

PFS-META-OFFSET is a field which allows us to recover the pointer to PFS-META segment from a pointer to DATA segment.

DATA is an actual segment which will keep the user data.

Member Typedef Documentation

◆ pfs_metadata

Member Function Documentation

◆ alloc()

template<bool Zero_initialized>
static void * ut::detail::Alloc_pfs::alloc ( std::size_t  size,
pfs_metadata::pfs_memory_key_t  key 
)
inlinestatic

Dynamically allocates storage of given size at the address aligned to the requested alignment.

Parameters
[in]sizeSize of storage (in bytes) requested to be allocated.
[in]keyPSI memory key to be used for PFS memory instrumentation.
Returns
Pointer to the allocated storage. nullptr if dynamic storage allocation failed.

◆ datalen()

static size_t ut::detail::Alloc_pfs::datalen ( PFS_metadata::data_segment_ptr  data)
inlinestatic

Returns the number of bytes requested to be allocated.

Parameters
[in]dataPointer to storage allocated through Alloc_pfs::alloc()
Returns
Number of bytes.

◆ deduce()

static void * ut::detail::Alloc_pfs::deduce ( PFS_metadata::data_segment_ptr  data)
inlinestaticprivatenoexcept

Helper function which deduces the original pointer returned by Alloc_pfs::alloc() from a pointer which is passed to us by the call-site.

◆ free()

static void ut::detail::Alloc_pfs::free ( PFS_metadata::data_segment_ptr  data)
inlinestaticnoexcept

Releases storage dynamically allocated through Alloc_pfs::alloc().

Parameters
[in]dataPointer to storage allocated through Alloc_pfs::alloc()

◆ realloc()

static void * ut::detail::Alloc_pfs::realloc ( PFS_metadata::data_segment_ptr  data,
std::size_t  size,
pfs_metadata::pfs_memory_key_t  key 
)
inlinestatic

Reallocates the given area of memory, which if not nullptr, must be previously allocated by Alloc_pfs::alloc() or Alloc_pfs::realloc().

Mimics unfortunate realloc() design so that: If pointer passed is nullptr, then behavior is as if Alloc_pfs::alloc() had been called. If new size of storage requested is 0, then behavior is as if Alloc_pfs::free() had been called.

Parameters
[in]dataPointer to the memory to be reallocated.
[in]sizeNew size of storage (in bytes) requested to be allocated.
[in]keyPSI memory key to be used for PFS memory instrumentation.
Returns
Pointer to the reallocated storage. nullptr if dynamic storage allocation or reallocation failed or if new size requested was 0.

Member Data Documentation

◆ metadata_len

constexpr auto ut::detail::Alloc_pfs::metadata_len
staticconstexpr
Initial value:
=
calc_align(pfs_metadata::size, alignof(max_align_t))
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
static constexpr auto size
Definition: pfs.h:100

This is how much the metadata (PFS-META | VARLEN | PFS-META-OFFSET) segment will be big.


The documentation for this struct was generated from the following file: