27#ifndef TEMPTABLE_BLOCK_H
28#define TEMPTABLE_BLOCK_H
167 static constexpr size_t ALIGN_TO =
alignof(
void *);
191 bool operator==(const
Block &other) const;
198 bool operator!=(const
Block &other) const;
282 size_t raw_size =
size;
283#ifdef HAVE_PSI_MEMORY_INTERFACE
293#ifdef HAVE_PSI_MEMORY_INTERFACE
296 return reinterpret_cast<uint8_t *
>(ptr);
302 size_t raw_size =
size;
304#ifdef HAVE_PSI_MEMORY_INTERFACE
328 size_t block_size) noexcept
329 :
Header(block_memory, block_memory_type, block_size) {
339 DBUG_PRINT(
"temptable_allocator", (
"block create: size=%zu, new_block=(%s)",
353 assert(can_accommodate(chunk_size));
367 (
"allocate from block: chunk_size=%zu, from_block=(%s); "
369 chunk_size,
to_string().c_str(), chunk.data()));
377 (
"deallocate from block: size=%zu, from_block=(%s), chunk_data=%p",
378 chunk_size,
to_string().c_str(), chunk.data()));
392 (
"destroying the block: (%s)",
to_string().c_str()));
410 std::numeric_limits<
decltype(
block_size)>::max() -
443 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:163
Source type() const
Get the Block Source type (memory where it resides).
Definition: block.h:417
bool is_empty() const
Check if Block is empty (not holding any data).
Definition: block.h:399
std::string to_string() const
A human-readable string that describes a Block.
Definition: block.h:432
void destroy() noexcept
Destroy the whole Block.
Definition: block.h:388
size_t deallocate(Chunk chunk, size_t chunk_size) noexcept
Deallocate a Chunk from a Block.
Definition: block.h:374
bool can_accommodate(size_t chunk_size) const
Check if Block can fit (allocate) a Chunk of given size.
Definition: block.h:403
size_t number_of_used_chunks() const
Get current number of Chunks allocated by the Block.
Definition: block.h:427
static constexpr size_t ALIGN_TO
Block will self-adjust all requested allocation-sizes to the multiple of this value.
Definition: block.h:167
size_t size() const
Get the Block size.
Definition: block.h:422
Block() noexcept=default
Default constructor which creates an empty Block.
bool operator==(const Block &other) const
Equality operator.
Definition: block.h:343
bool operator!=(const Block &other) const
Inequality operator.
Definition: block.h:347
Chunk allocate(size_t chunk_size) noexcept
Allocate a Chunk from a Block.
Definition: block.h:351
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:442
static size_t aligned_size(size_t size)
What is the word-size (ALIGN_TO) aligned size of an input size?
Definition: block.h:452
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:448
Chunk is an abstraction with the purpose of representing a smallest logical memory-unit within the Bl...
Definition: chunk.h:68
size_t offset() const
Get the Chunk offset relative to the start of belonging Block.
Definition: chunk.h:154
static size_t size_hint(size_t n_bytes)
For given size, how much memory will be occupied by the Chunk.
Definition: chunk.h:160
#define USER_TO_HEADER_UINT8_T(P)
Definition: mysql_memory.h:96
#define PSI_HEADER_SIZE
Definition: mysql_memory.h:86
static std::string to_string(const LEX_STRING &str)
Definition: lex_string.h:50
Various macros useful for communicating with memory debuggers, such as Valgrind.
#define MEM_NOACCESS(a, len)
Definition: memory_debugging.h:60
#define MEM_UNDEFINED(a, len)
Definition: memory_debugging.h:58
Memory utilities for temptable-allocator.
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:181
#define HEADER_TO_USER(P)
Definition: my_memory.cc:47
Instrumentation helpers for memory allocation.
size_t size(const char *const c)
Definition: base64.h:46
Definition: gcs_xcom_synode.h:64
Definition: allocator.h:45
static void deallocate_from(Source src, size_t size, uint8_t *block_address)
Definition: block.h:300
void Block_PSI_init()
Initialize the PSI memory engine.
Definition: block.cc:74
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:103
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:126
void Block_PSI_track_physical_ram_deallocation(uint8_t *ptr)
Log physical memory deallocation of a Block located in RAM.
Definition: block.cc:116
static uint8_t * allocate_from(Source src, size_t size)
Definition: block.h:280
Source
Type of memory allocated.
Definition: memutils.h:68
@ 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:139
void Block_PSI_track_logical_deallocation(size_t size)
Log logical (Chunk) memory deallocation.
Definition: block.cc:95
void Block_PSI_track_logical_allocation(size_t size)
Log logical (Chunk) memory allocation.
Definition: block.cc:81
static void deallocate(void *ptr, size_t bytes)
static void * allocate(size_t bytes)