MySQL 8.0.40
Source Code Documentation
temptable::Header Class Reference

Header is an abstraction with the purpose of holding and maintaining the Block metadata. More...

#include <header.h>

Inheritance diagram for temptable::Header:
[legend]

Public Types

using metadata_type = uintptr_t
 Type that we will be using for storing metadata information. More...
 

Public Member Functions

Source memory_source_type () const
 Get the Block Source type (memory where it resides). More...
 
size_t block_size () const
 Get the Block size. More...
 
size_t number_of_used_chunks () const
 Get current number of Chunks allocated by the Block. More...
 
size_t first_pristine_offset () const
 Get current first-pristine-offset. More...
 

Static Public Attributes

static constexpr size_t SIZE = 4 * sizeof(Header::metadata_type)
 Block header (metadata) size. More...
 

Protected Member Functions

 Header () noexcept
 Default constructor which creates an empty Header. More...
 
 Header (uint8_t *block_memory, Source block_memory_type, size_t block_size) noexcept
 Constructor which initializes the Header metadata when constructing fresh Blocks. More...
 
 Header (uint8_t *block_memory) noexcept
 Constructor which initializes the Header metadata from already existing Blocks in memory (e.g. More...
 
uint8_t * next_available_slot () const
 Enable Block to get the next available slot that it can use for next Chunk allocation. More...
 
uint8_t * block_address () const
 Enable Block to get its memory address. More...
 
size_t increment_number_of_used_chunks (size_t chunk_size)
 Enable Block to increment the reference-count when (logically) allocating new Chunks. More...
 
size_t decrement_number_of_used_chunks (size_t chunk_size, bool rightmost_chunk)
 Enable Block to decrement the reference-count when (logically) deallocating existing Chunks. More...
 
void reset ()
 Enable Block to reset the Header metadata upon Block destruction. More...
 

Static Private Member Functions

static Header::metadata_typeblock_memory_type_ptr (uint8_t *block)
 Deduce a pointer to the memory type of given Block. More...
 
static Header::metadata_typeblock_size_ptr (uint8_t *block)
 Deduce a pointer to the size of given Block. More...
 
static Header::metadata_typeblock_number_of_used_chunks_ptr (uint8_t *block)
 Deduce a pointer to the number of used/allocated Chunks of given Block. More...
 
static Header::metadata_typeblock_first_pristine_offset_ptr (uint8_t *block)
 Deduce a pointer to the first-pristine-offset of given Block. More...
 

Private Attributes

uint8_t * m_offset
 A pointer to the allocated Block memory which is used to deduce all of the other remaining metadata structure. More...
 

Detailed Description

Header is an abstraction with the purpose of holding and maintaining the Block metadata.

Block metadata has the following structure:

  • N bytes for the block type which indicates where the block memory was allocated from.
  • N bytes for the block size (set at block creation and never changed later).
  • N bytes for the number of used/allocated chunks from this block (set to 0 at block creation).
  • N bytes for the offset of the first byte relative to the block start that is free and can be used by the next allocation request (set to 4 * N at block creation). We call this first pristine offset.

That implies Chunks occupy the following range in memory:

  • bytes [4 * N, block size) a sequence of chunks appended to each other.

1st byte of [0, N) region is an actual pointer returned by memory allocation functions (e.g. malloc/new/mmap/etc.). Given that we are working with contiguous memory, storing that byte (offset) is just enough to be able to build-up and deduce Header metadata structure.

Part of the Header contract is to have its metadata properly aligned in memory. Given that this memory is provided by the Block, Header implements debug-asserts to actually check if this condition has been met. If that was not the case, then accessing unaligned memory addresses would:

  1. Incur performance penalty cost on architectures which can handle misaligned memory access (e.g. x86).
  2. Result with a CPU trap (exception) on architectures which cannot handle misaligned memory access (e.g. SPARC).

In order to maintain proper memory alignment of the whole metadata structure, CPU word-size data-type is used. Our N is defined by the size of that type (Header::metadata_type).

Member Typedef Documentation

◆ metadata_type

Type that we will be using for storing metadata information.

Constructor & Destructor Documentation

◆ Header() [1/3]

temptable::Header::Header ( )
inlineprotectednoexcept

Default constructor which creates an empty Header.

◆ Header() [2/3]

temptable::Header::Header ( uint8_t *  block_memory,
Source  block_memory_type,
size_t  block_size 
)
inlineprotectednoexcept

Constructor which initializes the Header metadata when constructing fresh Blocks.

[in] Pointer to the allocated Block memory. [in] Source where Block has allocated actual memory from. [in] Size of the Block

◆ Header() [3/3]

temptable::Header::Header ( uint8_t *  block_memory)
inlineexplicitprotectednoexcept

Constructor which initializes the Header metadata from already existing Blocks in memory (e.g.

ones that are deduced from Chunks).

[in] Pointer to the existing Block.

Member Function Documentation

◆ block_address()

uint8_t * temptable::Header::block_address ( ) const
inlineprotected

Enable Block to get its memory address.

Returns
An address where Block was allocated from.

◆ block_first_pristine_offset_ptr()

Header::metadata_type * temptable::Header::block_first_pristine_offset_ptr ( uint8_t *  block)
inlinestaticprivate

Deduce a pointer to the first-pristine-offset of given Block.

◆ block_memory_type_ptr()

Header::metadata_type * temptable::Header::block_memory_type_ptr ( uint8_t *  block)
inlinestaticprivate

Deduce a pointer to the memory type of given Block.

◆ block_number_of_used_chunks_ptr()

Header::metadata_type * temptable::Header::block_number_of_used_chunks_ptr ( uint8_t *  block)
inlinestaticprivate

Deduce a pointer to the number of used/allocated Chunks of given Block.

◆ block_size()

size_t temptable::Header::block_size ( ) const
inline

Get the Block size.

Returns
Size of the Block

◆ block_size_ptr()

Header::metadata_type * temptable::Header::block_size_ptr ( uint8_t *  block)
inlinestaticprivate

Deduce a pointer to the size of given Block.

◆ decrement_number_of_used_chunks()

size_t temptable::Header::decrement_number_of_used_chunks ( size_t  chunk_size,
bool  rightmost_chunk 
)
inlineprotected

Enable Block to decrement the reference-count when (logically) deallocating existing Chunks.

[in] Size of the Chunk. [in] Boolean which denotes if Chunk being deallocated is the last (rightmost) one.

Returns
New number of Chunks used/allocated by the Block after this operation.

◆ first_pristine_offset()

size_t temptable::Header::first_pristine_offset ( ) const
inline

Get current first-pristine-offset.

This offset is always relative to the block start (block-address).

Returns
Offset relative to the block start

◆ increment_number_of_used_chunks()

size_t temptable::Header::increment_number_of_used_chunks ( size_t  chunk_size)
inlineprotected

Enable Block to increment the reference-count when (logically) allocating new Chunks.

[in] Size of the Chunk.

Returns
New number of Chunks used/allocated by the Block after this operation.

◆ memory_source_type()

Source temptable::Header::memory_source_type ( ) const
inline

Get the Block Source type (memory where it resides).

Returns
One of Source values

◆ next_available_slot()

uint8_t * temptable::Header::next_available_slot ( ) const
inlineprotected

Enable Block to get the next available slot that it can use for next Chunk allocation.

Returns
An absolute memory-location offset

◆ number_of_used_chunks()

size_t temptable::Header::number_of_used_chunks ( ) const
inline

Get current number of Chunks allocated by the Block.

Returns
Number of Chunks allocated by this Block

◆ reset()

void temptable::Header::reset ( void  )
inlineprotected

Enable Block to reset the Header metadata upon Block destruction.

Member Data Documentation

◆ m_offset

uint8_t* temptable::Header::m_offset
private

A pointer to the allocated Block memory which is used to deduce all of the other remaining metadata structure.

◆ SIZE

constexpr size_t temptable::Header::SIZE = 4 * sizeof(Header::metadata_type)
staticconstexpr

Block header (metadata) size.

As described, there are 4 elements.


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