MySQL 9.0.0
Source Code Documentation
|
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>
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... | |
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:
^ ^ ^ | | | | ------------------------— | | | 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.
|
inlinestatic |
Dynamically allocates storage of given size at the address aligned to the requested alignment.
[in] | size | Size of storage (in bytes) requested to be allocated. |
[in] | key | PSI memory key to be used for PFS memory instrumentation. |
|
inlinestatic |
Returns the number of bytes requested to be allocated.
[in] | data | Pointer to storage allocated through Alloc_pfs::alloc() |
|
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.
|
inlinestaticnoexcept |
Releases storage dynamically allocated through Alloc_pfs::alloc().
[in] | data | Pointer to storage allocated through Alloc_pfs::alloc() |
|
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.
[in] | data | Pointer to the memory to be reallocated. |
[in] | size | New size of storage (in bytes) requested to be allocated. |
[in] | key | PSI memory key to be used for PFS memory instrumentation. |
|
staticconstexpr |
This is how much the metadata (PFS-META | VARLEN | PFS-META-OFFSET) segment will be big.