MySQL 8.0.40
Source Code Documentation
|
Custom memory allocator. More...
#include <allocator.h>
Classes | |
struct | rebind |
Public Types | |
typedef T * | pointer |
typedef const T * | const_pointer |
typedef T & | reference |
typedef const T & | const_reference |
typedef T | value_type |
typedef size_t | size_type |
typedef ptrdiff_t | difference_type |
Public Member Functions | |
Allocator (Block *shared_block, TableResourceMonitor &table_resource_monitor) | |
Constructor. More... | |
template<class U > | |
Allocator (const Allocator< U > &other) | |
Constructor from allocator of another type. More... | |
template<class U > | |
Allocator (Allocator< U > &&other) noexcept | |
Move constructor from allocator of another type. More... | |
~Allocator () | |
Destructor. More... | |
Allocator (const Allocator &)=default | |
template<class U > | |
void | operator= (const Allocator< U > &)=delete |
Assignment operator, not used, thus disabled. More... | |
template<class U > | |
void | operator= (const Allocator< U > &&)=delete |
Move operator, not used, thus disabled. More... | |
template<class U > | |
bool | operator== (const Allocator< U > &rhs) const |
Equality operator. More... | |
template<class U > | |
bool | operator!= (const Allocator< U > &rhs) const |
Inequality operator. More... | |
T * | allocate (size_t n_elements) |
Allocate memory for storing n_elements number of elements. More... | |
void | deallocate (T *ptr, size_t n_elements) |
Free a memory allocated by allocate(). More... | |
template<class U , class... Args> | |
void | construct (U *mem, Args &&...args) |
Construct one object of type U on an already allocated chunk of memory, which must be large enough to store it. More... | |
template<class U > | |
void | destroy (U *p) |
Destroy an object of type U . More... | |
Static Public Member Functions | |
static void | init () |
Initialize necessary structures. More... | |
Public Attributes | |
std::shared_ptr< AllocatorState< AllocationScheme > > | m_state |
Shared state between all the copies and rebinds of this allocator. More... | |
Block * | m_shared_block |
A block of memory which is a state external to this allocator and can be shared among different instances of the allocator (not simultaneously). More... | |
TableResourceMonitor & | m_table_resource_monitor |
Table resource monitor control mechanism that limits the amount of resources that can be consumed at the per-table level. More... | |
Custom memory allocator.
All dynamic memory used by the TempTable engine is allocated through this allocator.
The purpose of this allocator is to minimize the number of calls to the OS for allocating new memory (e.g. malloc()) and to improve the spatial locality of reference. It is able to do so quite easily thanks to the Block/Chunk entities it is implemented in terms of. Due to the design of these entities, it is also able to feed allocations and deallocations in (amortized) constant-time and keep being CPU memory-access friendly because of the internal self-adjustment to word-size memory alignment. To learn even more about specifics and more properties please have a look at the respective header files of Header/Block/Chunk class declarations.
The most common use case, for which it is optimized, is to have the following performed by a single thread:
The allocator allocates memory from the OS in large blocks (e.g. a few MiB) whose size also increases progressively by the increasing number of allocation requests. Exact block-size increase progress is defined by the block allocation scheme which, by default, is set to AllocationScheme::Exponential.
Allocator does not store a list of all allocated blocks but only keeps track of the current block which has not yet been entirely filled up and the overall number of allocated blocks. When current block gets filled up, new one is created and immediately made current.
Furthermore, it always keeps the last block alive. It cannot be deallocated by the user. Last block is automatically deallocated at the thread exit.
Allocator will also keep track of RAM-consumption and in case it reaches the threshold defined by temptable_max_ram, it will switch to MMAP-backed block allocations. It will switch back once RAM consumption is again below the threshold.
typedef const T* temptable::Allocator< T, AllocationScheme >::const_pointer |
typedef const T& temptable::Allocator< T, AllocationScheme >::const_reference |
typedef ptrdiff_t temptable::Allocator< T, AllocationScheme >::difference_type |
typedef T* temptable::Allocator< T, AllocationScheme >::pointer |
typedef T& temptable::Allocator< T, AllocationScheme >::reference |
typedef size_t temptable::Allocator< T, AllocationScheme >::size_type |
typedef T temptable::Allocator< T, AllocationScheme >::value_type |
|
inline |
Constructor.
|
inline |
Constructor from allocator of another type.
The state is copied into the new object.
[in] | other | Source Allocator object. |
|
inlinenoexcept |
Move constructor from allocator of another type.
[in,out] | other | Source Allocator object. |
|
inlinedefault |
Destructor.
|
default |
|
inline |
Allocate memory for storing n_elements
number of elements.
[in] | n_elements | Number of elements that must be allocated. |
|
inline |
Construct one object of type U
on an already allocated chunk of memory, which must be large enough to store it.
[in] | mem | Memory where to create the object. |
args | Arguments to pass to U's constructor. |
|
inline |
Free a memory allocated by allocate().
[in,out] | ptr | Pointer to memory to free. |
[in] | n_elements | Number of elements allocated. |
|
inline |
Destroy an object of type U
.
The memory is not returned to the OS, this is the counterpart of construct()
.
[in,out] | p | Object to destroy. |
|
inlinestatic |
Initialize necessary structures.
Called once in the OS process lifetime, before other methods.
|
inline |
Inequality operator.
[in] | rhs | Object to compare with. |
|
delete |
Move operator, not used, thus disabled.
|
delete |
Assignment operator, not used, thus disabled.
|
inline |
Equality operator.
[in] | rhs | Object to compare with. |
Block* temptable::Allocator< T, AllocationScheme >::m_shared_block |
A block of memory which is a state external to this allocator and can be shared among different instances of the allocator (not simultaneously).
In order to speed up its operations, allocator may decide to consume the memory of this shared block.
std::shared_ptr<AllocatorState<AllocationScheme> > temptable::Allocator< T, AllocationScheme >::m_state |
Shared state between all the copies and rebinds of this allocator.
See AllocatorState for details.
TableResourceMonitor& temptable::Allocator< T, AllocationScheme >::m_table_resource_monitor |
Table resource monitor control mechanism that limits the amount of resources that can be consumed at the per-table level.