26#ifndef TEMPTABLE_BLOCK_H
27#define TEMPTABLE_BLOCK_H
166 static constexpr size_t ALIGN_TO =
alignof(
void *);
190 bool operator==(const
Block &other) const;
197 bool operator!=(const
Block &other) const;
281 size_t raw_size =
size;
282#ifdef HAVE_PSI_MEMORY_INTERFACE
292#ifdef HAVE_PSI_MEMORY_INTERFACE
295 return reinterpret_cast<uint8_t *
>(ptr);
301 size_t raw_size =
size;
303#ifdef HAVE_PSI_MEMORY_INTERFACE
327 size_t block_size) noexcept
328 :
Header(block_memory, block_memory_type, block_size) {
338 DBUG_PRINT(
"temptable_allocator", (
"block create: size=%zu, new_block=(%s)",
352 assert(can_accommodate(chunk_size));
366 (
"allocate from block: chunk_size=%zu, from_block=(%s); "
368 chunk_size,
to_string().c_str(), chunk.data()));
376 (
"deallocate from block: size=%zu, from_block=(%s), chunk_data=%p",
377 chunk_size,
to_string().c_str(), chunk.data()));
391 (
"destroying the block: (%s)",
to_string().c_str()));
409 std::numeric_limits<
decltype(
block_size)>::max() -
442 size_t size_bytes)
const {
Chunk abstraction for temptable Block allocator.
Memory-block abstraction whose purpose is to serve as a building block for custom memory-allocator im...
Definition: block.h:162
Source type() const
Get the Block Source type (memory where it resides).
Definition: block.h:416
bool is_empty() const
Check if Block is empty (not holding any data).
Definition: block.h:398
std::string to_string() const
A human-readable string that describes a Block.
Definition: block.h:431
void destroy() noexcept
Destroy the whole Block.
Definition: block.h:387
size_t deallocate(Chunk chunk, size_t chunk_size) noexcept
Deallocate a Chunk from a Block.
Definition: block.h:373
bool can_accommodate(size_t chunk_size) const
Check if Block can fit (allocate) a Chunk of given size.
Definition: block.h:402
size_t number_of_used_chunks() const
Get current number of Chunks allocated by the Block.
Definition: block.h:426
static constexpr size_t ALIGN_TO
Block will self-adjust all requested allocation-sizes to the multiple of this value.
Definition: block.h:166
size_t size() const
Get the Block size.
Definition: block.h:421
Block() noexcept=default
Default constructor which creates an empty Block.
bool operator==(const Block &other) const
Equality operator.
Definition: block.h:342
bool operator!=(const Block &other) const
Inequality operator.
Definition: block.h:346
Chunk allocate(size_t chunk_size) noexcept
Allocate a Chunk from a Block.
Definition: block.h:350
bool is_rightmost_chunk(const Chunk &chunk, size_t chunk_size) const
Are we looking at the last (rightmost) chunk in a Block.
Definition: block.h:441
static size_t aligned_size(size_t size)
What is the word-size (ALIGN_TO) aligned size of an input size?
Definition: block.h:451
static size_t size_hint(size_t n_bytes)
For given size, how much memory will Block with single Chunk actually occupy.
Definition: block.h:447
Chunk is an abstraction with the purpose of representing a smallest logical memory-unit within the Bl...
Definition: chunk.h:67
size_t offset() const
Get the Chunk offset relative to the start of belonging Block.
Definition: chunk.h:153
static size_t size_hint(size_t n_bytes)
For given size, how much memory will be occupied by the Chunk.
Definition: chunk.h:159
#define USER_TO_HEADER_UINT8_T(P)
Definition: mysql_memory.h:95
#define PSI_HEADER_SIZE
Definition: mysql_memory.h:85
static std::string to_string(const LEX_STRING &str)
Definition: lex_string.h:49
Various macros useful for communicating with memory debuggers, such as Valgrind.
#define MEM_NOACCESS(a, len)
Definition: memory_debugging.h:59
#define MEM_UNDEFINED(a, len)
Definition: memory_debugging.h:57
Memory utilities for temptable-allocator.
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:180
#define HEADER_TO_USER(P)
Definition: my_memory.cc:46
Instrumentation helpers for memory allocation.
Definition: varlen_sort.h:183
Definition: allocator.h:44
static void deallocate_from(Source src, size_t size, uint8_t *block_address)
Definition: block.h:299
void Block_PSI_init()
Initialize the PSI memory engine.
Definition: block.cc:73
void Block_PSI_track_physical_ram_allocation(void *ptr, size_t size)
Log physical memory allocation of a Block located in RAM.
Definition: block.cc:102
void Block_PSI_track_physical_disk_allocation(void *ptr, size_t size)
Log physical memory allocation of a Block located in MMAP-ed file.
Definition: block.cc:125
void Block_PSI_track_physical_ram_deallocation(uint8_t *ptr)
Log physical memory deallocation of a Block located in RAM.
Definition: block.cc:115
static uint8_t * allocate_from(Source src, size_t size)
Definition: block.h:279
Source
Type of memory allocated.
Definition: memutils.h:67
@ MMAP_FILE
Memory is allocated on disk, using mmap()'ed file.
@ RAM
Memory is allocated from RAM, using malloc() for example.
void Block_PSI_track_physical_disk_deallocation(uint8_t *ptr)
Log physical memory deallocation of a Block located in MMAP-ed file.
Definition: block.cc:138
void Block_PSI_track_logical_deallocation(size_t size)
Log logical (Chunk) memory deallocation.
Definition: block.cc:94
void Block_PSI_track_logical_allocation(size_t size)
Log logical (Chunk) memory allocation.
Definition: block.cc:80
static void deallocate(void *ptr, size_t bytes)
static void * allocate(size_t bytes)