MySQL 8.0.39
Source Code Documentation
ut::detail::Large_page_alloc Struct Reference

Allocation routines which are purposed for allocating memory through the means of what is known as large (huge) pages. More...

#include <large_page_alloc.h>

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

Public Types

using page_allocation_metadata = Page_alloc_metadata
 

Static Public Member Functions

static void * alloc (std::size_t size)
 Allocates memory through large-page support. More...
 
static bool free (void *data) noexcept
 Releases storage allocated through Large_page_alloc::alloc(). More...
 
static page_allocation_metadata::datalen_t datalen (void *data)
 Returns the number of bytes that have been allocated. More...
 
static Page_type page_type (void *data)
 Returns the type of the page. 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 (void *data) noexcept
 Helper function which deduces the original pointer returned by Large_page_alloc 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< false >
static constexpr auto is_pfs_instrumented_v
 

Detailed Description

Allocation routines which are purposed for allocating memory through the means of what is known as large (huge) pages.

large_page_aligned_alloc() and large_page_aligned_free() are taking care of OS specific details and Large_page_alloc is a convenience wrapper which only makes the use of large pages more ergonomic so that it serializes the actual size being allocated into the raw memory. This size is then automagically deduced when large page memory is being freed. Otherwise, client code would have been responsible to store and keep that value somewhere until it frees the large page memory segment. 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 huge-page sized allocation request, application code will get to use CPU_PAGE_SIZE bytes less. In other words, for a request that is backed up by three 2MiB huge-pages, application code will get to use 3 * 2MiB - CPU_PAGE_SIZE of total bytes. CPU_PAGE_SIZE is normally 4K but some architectures such as SPARC have it set to 8K. ARM64 can be set to 4K, 8K or 64K.

Memory layout representation looks like the following:


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

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

|

| DATALEN | PAGE-TYPE | VARLEN |

\ \ 0 \ CPU_PAGE_SIZE - 1

For details on DATALEN, PAGE-TYPE and VARLEN fields see Page_alloc_metadata.

DATA is an actual page-aligned (!) segment backed by large (huge) page memory 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::Large_page_alloc::alloc ( std::size_t  size)
inlinestatic

Allocates memory through large-page support.

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

◆ datalen()

static page_allocation_metadata::datalen_t ut::detail::Large_page_alloc::datalen ( void *  data)
inlinestatic

Returns the number of bytes that have been allocated.

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

◆ deduce()

static void * ut::detail::Large_page_alloc::deduce ( void *  data)
inlinestaticprivatenoexcept

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

◆ free()

static bool ut::detail::Large_page_alloc::free ( void *  data)
inlinestaticnoexcept

Releases storage allocated through Large_page_alloc::alloc().

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

◆ low_level_info()

static allocation_low_level_info ut::detail::Large_page_alloc::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 Large_page_alloc::alloc()
Returns
Low level allocation info.

◆ page_type()

static Page_type ut::detail::Large_page_alloc::page_type ( void *  data)
inlinestatic

Returns the type of the page.

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

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