MySQL 8.3.0
Source Code Documentation
ut::detail::Page_alloc_pfs Struct Reference

Allocation routines which are purposed for allocating system page-aligned memory. More...

#include <page_alloc.h>

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

Public Types

using page_allocation_metadata = Page_alloc_metadata_pfs
 

Static Public Member Functions

static void * alloc (std::size_t size, page_allocation_metadata::pfs_metadata::pfs_memory_key_t key)
 Allocates system page-aligned memory. More...
 
static bool free (PFS_metadata::data_segment_ptr data) noexcept
 Releases storage allocated through Page_alloc_pfs::alloc(). More...
 
static size_t datalen (PFS_metadata::data_segment_ptr data)
 Returns the number of bytes that have been allocated. More...
 
static Page_type page_type (PFS_metadata::data_segment_ptr data)
 Returns the Page_type. More...
 
static allocation_low_level_info low_level_info (void *data)
 Retrieves the pointer and size of the allocation provided by the OS. More...
 

Static Private Member Functions

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 passed to us by the call-site. More...
 

Additional Inherited Members

- Static Public Attributes inherited from ut::detail::allocator_traits< true >
static constexpr auto is_pfs_instrumented_v
 

Detailed Description

Allocation routines which are purposed for allocating system page-aligned memory.

This is a PFS (performance-schema) variant of Page_alloc. Implemented in terms of Page_alloc_metadata_pfs.

page_aligned_alloc() and page_aligned_free() are taking care of OS specific details and Page_alloc_pfs is a convenience wrapper which only makes the use of system page-aligned memory more ergonomic so that it serializes all the relevant PFS details into the raw memory. Otherwise, client code would have been responsible to store and keep those details somewhere until the memory segment is freed. Additionally, information on type of page used to back up requested allocation is also serialized into the memory allowing to build higher-kinded abstractions more easily. See ut::malloc_large_page with option to fallback to regular pages through ut::malloc_page.

Cost associated with this abstraction is the size of a single CPU page. In terms of virtual memory, especially in 64-bit address space, this cost is negligible. In practice this means that for each N pages allocation request there will be N+1 pages allocated beneath.

Memory layout representation looks like the following:


| PAGE-ALLOC-METADATA-PFS | ... DATA ... |

^ ^ | | | | | ptr (system-page) to be | returned to call-site

|

| PFS-META | PAGE-TYPE | VARLEN | PFS-META-OFFSET |

^ ^ | | | ------------------------— | | OWNER | DATALEN | KEY | | ------------------------— | ptr returned by page_aligned_alloc

For details on PFS-META, PAGE-TYPE, VARLEN and PFS-META-OFFSET fields see Page_alloc_metadata_pfs.

DATA is an actual page-aligned segment that will be returned to the call-site and which the client code will be able to use for the application data.

Member Typedef Documentation

◆ page_allocation_metadata

Member Function Documentation

◆ alloc()

static void * ut::detail::Page_alloc_pfs::alloc ( std::size_t  size,
page_allocation_metadata::pfs_metadata::pfs_memory_key_t  key 
)
inlinestatic

Allocates system page-aligned memory.

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 allocation failed.

◆ datalen()

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

Returns the number of bytes that have been allocated.

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

◆ deduce()

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

Helper function which deduces the original pointer returned by Page_alloc_pfs from a pointer which is passed to us by the call-site.

◆ free()

static bool ut::detail::Page_alloc_pfs::free ( PFS_metadata::data_segment_ptr  data)
inlinestaticnoexcept

Releases storage allocated through Page_alloc_pfs::alloc().

Parameters
[in]dataPointer to storage allocated through Page_alloc_pfs::alloc()
Returns
True if releasing the page-aligned memory was successful.

◆ low_level_info()

static allocation_low_level_info ut::detail::Page_alloc_pfs::low_level_info ( void *  data)
inlinestatic

Retrieves the pointer and size of the allocation provided by the OS.

It is a low level information, and is needed only to call low level memory-related OS functions.

Parameters
[in]dataPointer to storage allocated through Page_alloc_pfs::alloc()
Returns
Low level allocation info.

◆ page_type()

static Page_type ut::detail::Page_alloc_pfs::page_type ( PFS_metadata::data_segment_ptr  data)
inlinestatic

Returns the Page_type.

Parameters
[in]dataPointer to storage allocated through Page_alloc_pfs::alloc()
Returns
Page type.

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