diff options
author | unknown <knielsen@knielsen-hq.org> | 2009-11-13 22:26:08 +0100 |
---|---|---|
committer | unknown <knielsen@knielsen-hq.org> | 2009-11-13 22:26:08 +0100 |
commit | 898f6f48b79d1f2c334fb559225b2b0fade5ea93 (patch) | |
tree | 84df8eecd942b650f172cbd67050ee8984c0d52b /storage/xtradb/mem | |
parent | 275c0a7f96502b33f763fb9388dcc1c289e4792b (diff) | |
parent | 2bde0c5e6d31583e5197e3b513f572a693161f62 (diff) | |
download | mariadb-git-898f6f48b79d1f2c334fb559225b2b0fade5ea93.tar.gz |
Merge XtraDB 8 into MariaDB.
Diffstat (limited to 'storage/xtradb/mem')
-rw-r--r-- | storage/xtradb/mem/mem0dbg.c | 136 | ||||
-rw-r--r-- | storage/xtradb/mem/mem0mem.c | 148 | ||||
-rw-r--r-- | storage/xtradb/mem/mem0pool.c | 125 |
3 files changed, 207 insertions, 202 deletions
diff --git a/storage/xtradb/mem/mem0dbg.c b/storage/xtradb/mem/mem0dbg.c index a1647462922..a20eb2ad7d2 100644 --- a/storage/xtradb/mem/mem0dbg.c +++ b/storage/xtradb/mem/mem0dbg.c @@ -16,7 +16,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA *****************************************************************************/ -/************************************************************************ +/********************************************************************//** +@file mem/mem0dbg.c The memory management: the debug code. This is not a compilation module, but is included in mem0mem.* ! @@ -24,10 +25,12 @@ Created 6/9/1994 Heikki Tuuri *************************************************************************/ #ifdef UNIV_MEM_DEBUG +# ifndef UNIV_HOTBACKUP /* The mutex which protects in the debug version the hash table containing the list of live memory heaps, and also the global variables below. */ UNIV_INTERN mutex_t mem_hash_mutex; +# endif /* !UNIV_HOTBACKUP */ /* The following variables contain information about the extent of memory allocations. Only used in the debug version. @@ -38,7 +41,10 @@ static ulint mem_n_allocations = 0; static ulint mem_total_allocated_memory = 0; UNIV_INTERN ulint mem_current_allocated_memory = 0; static ulint mem_max_allocated_memory = 0; +# ifndef UNIV_HOTBACKUP static ulint mem_last_print_info = 0; +static ibool mem_hash_initialized = FALSE; +# endif /* !UNIV_HOTBACKUP */ /* Size of the hash table for memory management tracking */ #define MEM_HASH_SIZE 997 @@ -48,10 +54,10 @@ static ulint mem_last_print_info = 0; typedef struct mem_hash_node_struct mem_hash_node_t; struct mem_hash_node_struct { UT_LIST_NODE_T(mem_hash_node_t) - list; /* hash list node */ - mem_heap_t* heap; /* memory heap */ + list; /*!< hash list node */ + mem_heap_t* heap; /*!< memory heap */ const char* file_name;/* file where heap was created*/ - ulint line; /* file line of creation */ + ulint line; /*!< file line of creation */ ulint nth_heap;/* this is the nth heap created */ UT_LIST_NODE_T(mem_hash_node_t) all_list;/* list of all created heaps */ @@ -65,7 +71,6 @@ static mem_hash_cell_t mem_hash_table[MEM_HASH_SIZE]; /* The base node of the list of all allocated heaps */ static mem_hash_cell_t mem_all_list_base; -static ibool mem_hash_initialized = FALSE; UNIV_INLINE @@ -128,13 +133,14 @@ mem_field_trailer_get_check(byte* field) } #endif /* UNIV_MEM_DEBUG */ -/********************************************************************** +#ifndef UNIV_HOTBACKUP +/******************************************************************//** Initializes the memory system. */ UNIV_INTERN void mem_init( /*=====*/ - ulint size) /* in: common pool size in bytes */ + ulint size) /*!< in: common pool size in bytes */ { #ifdef UNIV_MEM_DEBUG @@ -164,16 +170,17 @@ mem_init( mem_comm_pool = mem_pool_create(size); } +#endif /* !UNIV_HOTBACKUP */ #ifdef UNIV_MEM_DEBUG -/********************************************************************** +/******************************************************************//** Initializes an allocated memory field in the debug version. */ UNIV_INTERN void mem_field_init( /*===========*/ - byte* buf, /* in: memory field */ - ulint n) /* in: how many bytes the user requested */ + byte* buf, /*!< in: memory field */ + ulint n) /*!< in: how many bytes the user requested */ { ulint rnd; byte* usr_buf; @@ -213,15 +220,15 @@ mem_field_init( mem_init_buf(usr_buf, n); } -/********************************************************************** +/******************************************************************//** Erases an allocated memory field in the debug version. */ UNIV_INTERN void mem_field_erase( /*============*/ - byte* buf, /* in: memory field */ + byte* buf, /*!< in: memory field */ ulint n __attribute__((unused))) - /* in: how many bytes the user requested */ + /*!< in: how many bytes the user requested */ { byte* usr_buf; @@ -240,15 +247,15 @@ mem_field_erase( mem_erase_buf(buf, MEM_SPACE_NEEDED(n)); } -/******************************************************************* +/***************************************************************//** Initializes a buffer to a random combination of hex BA and BE. Used to initialize allocated memory. */ UNIV_INTERN void mem_init_buf( /*=========*/ - byte* buf, /* in: pointer to buffer */ - ulint n) /* in: length of buffer */ + byte* buf, /*!< in: pointer to buffer */ + ulint n) /*!< in: length of buffer */ { byte* ptr; @@ -266,15 +273,15 @@ mem_init_buf( UNIV_MEM_INVALID(buf, n); } -/******************************************************************* +/***************************************************************//** Initializes a buffer to a random combination of hex DE and AD. -Used to erase freed memory.*/ +Used to erase freed memory. */ UNIV_INTERN void mem_erase_buf( /*==========*/ - byte* buf, /* in: pointer to buffer */ - ulint n) /* in: length of buffer */ + byte* buf, /*!< in: pointer to buffer */ + ulint n) /*!< in: length of buffer */ { byte* ptr; @@ -291,16 +298,16 @@ mem_erase_buf( UNIV_MEM_FREE(buf, n); } -/******************************************************************* +/***************************************************************//** Inserts a created memory heap to the hash table of current allocated memory heaps. */ UNIV_INTERN void mem_hash_insert( /*============*/ - mem_heap_t* heap, /* in: the created heap */ - const char* file_name, /* in: file name of creation */ - ulint line) /* in: line where created */ + mem_heap_t* heap, /*!< in: the created heap */ + const char* file_name, /*!< in: file name of creation */ + ulint line) /*!< in: line where created */ { mem_hash_node_t* new_node; ulint cell_no ; @@ -329,7 +336,7 @@ mem_hash_insert( mutex_exit(&mem_hash_mutex); } -/******************************************************************* +/***************************************************************//** Removes a memory heap (which is going to be freed by the caller) from the list of live memory heaps. Returns the size of the heap in terms of how much memory in bytes was allocated for the user of @@ -341,9 +348,9 @@ UNIV_INTERN void mem_hash_remove( /*============*/ - mem_heap_t* heap, /* in: the heap to be freed */ - const char* file_name, /* in: file name of freeing */ - ulint line) /* in: line where freed */ + mem_heap_t* heap, /*!< in: the heap to be freed */ + const char* file_name, /*!< in: file name of freeing */ + ulint line) /*!< in: line where freed */ { mem_hash_node_t* node; ulint cell_no; @@ -410,7 +417,7 @@ mem_hash_remove( #endif /* UNIV_MEM_DEBUG */ #if defined UNIV_MEM_DEBUG || defined UNIV_DEBUG -/******************************************************************* +/***************************************************************//** Checks a memory heap for consistency and prints the contents if requested. Outputs the sum of sizes of buffers given to the user (only in the debug version), the physical size of the heap and the number of @@ -420,24 +427,24 @@ UNIV_INTERN void mem_heap_validate_or_print( /*=======================*/ - mem_heap_t* heap, /* in: memory heap */ + mem_heap_t* heap, /*!< in: memory heap */ byte* top __attribute__((unused)), - /* in: calculate and validate only until + /*!< in: calculate and validate only until this top pointer in the heap is reached, if this pointer is NULL, ignored */ - ibool print, /* in: if TRUE, prints the contents + ibool print, /*!< in: if TRUE, prints the contents of the heap; works only in the debug version */ - ibool* error, /* out: TRUE if error */ - ulint* us_size,/* out: allocated memory + ibool* error, /*!< out: TRUE if error */ + ulint* us_size,/*!< out: allocated memory (for the user) in the heap, if a NULL pointer is passed as this argument, it is ignored; in the non-debug version this is always -1 */ - ulint* ph_size,/* out: physical size of the heap, + ulint* ph_size,/*!< out: physical size of the heap, if a NULL pointer is passed as this argument, it is ignored */ - ulint* n_blocks) /* out: number of blocks in the heap, + ulint* n_blocks) /*!< out: number of blocks in the heap, if a NULL pointer is passed as this argument, it is ignored */ { @@ -585,13 +592,13 @@ completed: *error = FALSE; } -/****************************************************************** +/**************************************************************//** Prints the contents of a memory heap. */ static void mem_heap_print( /*===========*/ - mem_heap_t* heap) /* in: memory heap */ + mem_heap_t* heap) /*!< in: memory heap */ { ibool error; ulint us_size; @@ -610,14 +617,14 @@ mem_heap_print( ut_a(!error); } -/****************************************************************** -Validates the contents of a memory heap. */ +/**************************************************************//** +Validates the contents of a memory heap. +@return TRUE if ok */ UNIV_INTERN ibool mem_heap_validate( /*==============*/ - /* out: TRUE if ok */ - mem_heap_t* heap) /* in: memory heap */ + mem_heap_t* heap) /*!< in: memory heap */ { ibool error; ulint us_size; @@ -639,14 +646,14 @@ mem_heap_validate( #endif /* UNIV_MEM_DEBUG || UNIV_DEBUG */ #ifdef UNIV_DEBUG -/****************************************************************** -Checks that an object is a memory heap (or a block of it). */ +/**************************************************************//** +Checks that an object is a memory heap (or a block of it). +@return TRUE if ok */ UNIV_INTERN ibool mem_heap_check( /*===========*/ - /* out: TRUE if ok */ - mem_heap_t* heap) /* in: memory heap */ + mem_heap_t* heap) /*!< in: memory heap */ { ut_a(heap->magic_n == MEM_BLOCK_MAGIC_N); @@ -655,13 +662,13 @@ mem_heap_check( #endif /* UNIV_DEBUG */ #ifdef UNIV_MEM_DEBUG -/********************************************************************* -TRUE if no memory is currently allocated. */ +/*****************************************************************//** +TRUE if no memory is currently allocated. +@return TRUE if no heaps exist */ UNIV_INTERN ibool mem_all_freed(void) /*===============*/ - /* out: TRUE if no heaps exist */ { mem_hash_node_t* node; ulint heap_count = 0; @@ -683,8 +690,9 @@ mem_all_freed(void) mutex_exit(&mem_hash_mutex); if (heap_count == 0) { - +# ifndef UNIV_HOTBACKUP ut_a(mem_pool_get_reserved(mem_comm_pool) == 0); +# endif /* !UNIV_HOTBACKUP */ return(TRUE); } else { @@ -692,13 +700,13 @@ mem_all_freed(void) } } -/********************************************************************* -Validates the dynamic memory allocation system. */ +/*****************************************************************//** +Validates the dynamic memory allocation system. +@return TRUE if error */ UNIV_INTERN ibool mem_validate_no_assert(void) /*========================*/ - /* out: TRUE if error */ { mem_hash_node_t* node; ulint n_heaps = 0; @@ -709,7 +717,9 @@ mem_validate_no_assert(void) ulint n_blocks; ulint i; +# ifndef UNIV_HOTBACKUP mem_pool_validate(mem_comm_pool); +# endif /* !UNIV_HOTBACKUP */ mutex_enter(&mem_hash_mutex); @@ -765,13 +775,13 @@ mem_validate_no_assert(void) return(error); } -/**************************************************************** -Validates the dynamic memory */ +/************************************************************//** +Validates the dynamic memory +@return TRUE if ok */ UNIV_INTERN ibool mem_validate(void) /*==============*/ - /* out: TRUE if ok */ { ut_a(!mem_validate_no_assert()); @@ -779,14 +789,14 @@ mem_validate(void) } #endif /* UNIV_MEM_DEBUG */ -/**************************************************************** +/************************************************************//** Tries to find neigboring memory allocation blocks and dumps to stderr the neighborhood of a given pointer. */ UNIV_INTERN void mem_analyze_corruption( /*===================*/ - void* ptr) /* in: pointer to place of possible corruption */ + void* ptr) /*!< in: pointer to place of possible corruption */ { byte* p; ulint i; @@ -887,14 +897,15 @@ mem_analyze_corruption( } } -/********************************************************************* +#ifndef UNIV_HOTBACKUP +/*****************************************************************//** Prints information of dynamic memory usage and currently allocated memory heaps or buffers. Can only be used in the debug version. */ static void mem_print_info_low( /*===============*/ - ibool print_all) /* in: if TRUE, all heaps are printed, + ibool print_all) /*!< in: if TRUE, all heaps are printed, else only the heaps allocated after the previous call of this function */ { @@ -991,7 +1002,7 @@ next_heap: #endif } -/********************************************************************* +/*****************************************************************//** Prints information of dynamic memory usage and currently allocated memory heaps or buffers. Can only be used in the debug version. */ UNIV_INTERN @@ -1002,7 +1013,7 @@ mem_print_info(void) mem_print_info_low(TRUE); } -/********************************************************************* +/*****************************************************************//** Prints information of dynamic memory usage and currently allocated memory heaps or buffers since the last ..._print_info or..._print_new_info. */ UNIV_INTERN @@ -1012,3 +1023,4 @@ mem_print_new_info(void) { mem_print_info_low(FALSE); } +#endif /* !UNIV_HOTBACKUP */ diff --git a/storage/xtradb/mem/mem0mem.c b/storage/xtradb/mem/mem0mem.c index b7345f5846b..e0dc8716f13 100644 --- a/storage/xtradb/mem/mem0mem.c +++ b/storage/xtradb/mem/mem0mem.c @@ -16,7 +16,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA *****************************************************************************/ -/************************************************************************ +/********************************************************************//** +@file mem/mem0mem.c The memory management Created 6/9/1994 Heikki Tuuri @@ -97,64 +98,43 @@ UT_LIST_BASE_NODE_T(mem_block_t) mem_block_list; #endif -/************************************************************************** -Duplicates a NUL-terminated string, allocated from a memory heap. */ +/**********************************************************************//** +Duplicates a NUL-terminated string, allocated from a memory heap. +@return own: a copy of the string */ UNIV_INTERN char* mem_heap_strdup( /*============*/ - /* out, own: a copy of the string */ - mem_heap_t* heap, /* in: memory heap where string is allocated */ - const char* str) /* in: string to be copied */ + mem_heap_t* heap, /*!< in: memory heap where string is allocated */ + const char* str) /*!< in: string to be copied */ { return(mem_heap_dup(heap, str, strlen(str) + 1)); } -/************************************************************************** -Duplicate a block of data, allocated from a memory heap. */ +/**********************************************************************//** +Duplicate a block of data, allocated from a memory heap. +@return own: a copy of the data */ UNIV_INTERN void* mem_heap_dup( /*=========*/ - /* out, own: a copy of the data */ - mem_heap_t* heap, /* in: memory heap where copy is allocated */ - const void* data, /* in: data to be copied */ - ulint len) /* in: length of data, in bytes */ + mem_heap_t* heap, /*!< in: memory heap where copy is allocated */ + const void* data, /*!< in: data to be copied */ + ulint len) /*!< in: length of data, in bytes */ { return(memcpy(mem_heap_alloc(heap, len), data, len)); } -/************************************************************************** -Concatenate two memory blocks and return the result, using a memory heap. */ -UNIV_INTERN -void* -mem_heap_cat( -/*=========*/ - /* out, own: the result */ - mem_heap_t* heap, /* in: memory heap where result is allocated */ - const void* b1, /* in: block 1 */ - ulint len1, /* in: length of b1, in bytes */ - const void* b2, /* in: block 2 */ - ulint len2) /* in: length of b2, in bytes */ -{ - void* res = mem_heap_alloc(heap, len1 + len2); - - memcpy(res, b1, len1); - memcpy((char*)res + len1, b2, len2); - - return(res); -} - -/************************************************************************** -Concatenate two strings and return the result, using a memory heap. */ +/**********************************************************************//** +Concatenate two strings and return the result, using a memory heap. +@return own: the result */ UNIV_INTERN char* mem_heap_strcat( /*============*/ - /* out, own: the result */ - mem_heap_t* heap, /* in: memory heap where string is allocated */ - const char* s1, /* in: string 1 */ - const char* s2) /* in: string 2 */ + mem_heap_t* heap, /*!< in: memory heap where string is allocated */ + const char* s1, /*!< in: string 1 */ + const char* s2) /*!< in: string 2 */ { char* s; ulint s1_len = strlen(s1); @@ -171,18 +151,17 @@ mem_heap_strcat( } -/******************************************************************** -Helper function for mem_heap_printf. */ +/****************************************************************//** +Helper function for mem_heap_printf. +@return length of formatted string, including terminating NUL */ static ulint mem_heap_printf_low( /*================*/ - /* out: length of formatted string, - including terminating NUL */ - char* buf, /* in/out: buffer to store formatted string + char* buf, /*!< in/out: buffer to store formatted string in, or NULL to just calculate length */ - const char* format, /* in: format string */ - va_list ap) /* in: arguments */ + const char* format, /*!< in: format string */ + va_list ap) /*!< in: arguments */ { ulint len = 0; @@ -281,18 +260,18 @@ mem_heap_printf_low( return(len); } -/******************************************************************** +/****************************************************************//** A simple (s)printf replacement that dynamically allocates the space for the formatted string from the given heap. This supports a very limited set of the printf syntax: types 's' and 'u' and length modifier 'l' (which is -required for the 'u' type). */ +required for the 'u' type). +@return heap-allocated formatted string */ UNIV_INTERN char* mem_heap_printf( /*============*/ - /* out: heap-allocated formatted string */ - mem_heap_t* heap, /* in: memory heap */ - const char* format, /* in: format string */ + mem_heap_t* heap, /*!< in: memory heap */ + const char* format, /*!< in: format string */ ...) { va_list ap; @@ -314,24 +293,25 @@ mem_heap_printf( return(str); } -/******************************************************************* -Creates a memory heap block where data can be allocated. */ +/***************************************************************//** +Creates a memory heap block where data can be allocated. +@return own: memory heap block, NULL if did not succeed (only possible +for MEM_HEAP_BTR_SEARCH type heaps) */ UNIV_INTERN mem_block_t* mem_heap_create_block( /*==================*/ - /* out, own: memory heap block, NULL if - did not succeed (only possible for - MEM_HEAP_BTR_SEARCH type heaps) */ - mem_heap_t* heap, /* in: memory heap or NULL if first block + mem_heap_t* heap, /*!< in: memory heap or NULL if first block should be created */ - ulint n, /* in: number of bytes needed for user data */ - ulint type, /* in: type of heap: MEM_HEAP_DYNAMIC or + ulint n, /*!< in: number of bytes needed for user data */ + ulint type, /*!< in: type of heap: MEM_HEAP_DYNAMIC or MEM_HEAP_BUFFER */ - const char* file_name,/* in: file name where created */ - ulint line) /* in: line where created */ + const char* file_name,/*!< in: file name where created */ + ulint line) /*!< in: line where created */ { +#ifndef UNIV_HOTBACKUP buf_block_t* buf_block = NULL; +#endif /* !UNIV_HOTBACKUP */ mem_block_t* block; ulint len; @@ -345,6 +325,7 @@ mem_heap_create_block( /* In dynamic allocation, calculate the size: block header + data. */ len = MEM_BLOCK_HEADER_SIZE + MEM_SPACE_NEEDED(n); +#ifndef UNIV_HOTBACKUP if (type == MEM_HEAP_DYNAMIC || len < UNIV_PAGE_SIZE / 2) { ut_ad(type == MEM_HEAP_DYNAMIC || n <= MEM_MAX_ALLOC_IN_BUF); @@ -374,6 +355,13 @@ mem_heap_create_block( ut_ad(block); block->buf_block = buf_block; + block->free_block = NULL; +#else /* !UNIV_HOTBACKUP */ + len = MEM_BLOCK_HEADER_SIZE + MEM_SPACE_NEEDED(n); + block = ut_malloc(len); + ut_ad(block); +#endif /* !UNIV_HOTBACKUP */ + block->magic_n = MEM_BLOCK_MAGIC_N; ut_strlcpy_rev(block->file_name, file_name, sizeof(block->file_name)); block->line = line; @@ -395,24 +383,21 @@ mem_heap_create_block( mem_block_set_free(block, MEM_BLOCK_HEADER_SIZE); mem_block_set_start(block, MEM_BLOCK_HEADER_SIZE); - block->free_block = NULL; - ut_ad((ulint)MEM_BLOCK_HEADER_SIZE < len); return(block); } -/******************************************************************* -Adds a new block to a memory heap. */ +/***************************************************************//** +Adds a new block to a memory heap. +@return created block, NULL if did not succeed (only possible for +MEM_HEAP_BTR_SEARCH type heaps) */ UNIV_INTERN mem_block_t* mem_heap_add_block( /*===============*/ - /* out: created block, NULL if did not - succeed (only possible for - MEM_HEAP_BTR_SEARCH type heaps)*/ - mem_heap_t* heap, /* in: memory heap */ - ulint n) /* in: number of bytes user needs */ + mem_heap_t* heap, /*!< in: memory heap */ + ulint n) /*!< in: number of bytes user needs */ { mem_block_t* block; mem_block_t* new_block; @@ -458,18 +443,20 @@ mem_heap_add_block( return(new_block); } -/********************************************************************** +/******************************************************************//** Frees a block from a memory heap. */ UNIV_INTERN void mem_heap_block_free( /*================*/ - mem_heap_t* heap, /* in: heap */ - mem_block_t* block) /* in: block to free */ + mem_heap_t* heap, /*!< in: heap */ + mem_block_t* block) /*!< in: block to free */ { ulint type; ulint len; - buf_block_t* buf_block; +#ifndef UNIV_HOTBACKUP + buf_block_t* buf_block = block->buf_block; +#endif /* !UNIV_HOTBACKUP */ if (block->magic_n != MEM_BLOCK_MAGIC_N) { mem_analyze_corruption(block); @@ -486,7 +473,6 @@ mem_heap_block_free( #endif type = heap->type; len = block->len; - buf_block = block->buf_block; block->magic_n = MEM_FREED_BLOCK_MAGIC_N; #ifdef UNIV_MEM_DEBUG @@ -498,6 +484,7 @@ mem_heap_block_free( UNIV_MEM_ASSERT_AND_FREE(block, len); #endif /* UNIV_MEM_DEBUG */ +#ifndef UNIV_HOTBACKUP if (type == MEM_HEAP_DYNAMIC || len < UNIV_PAGE_SIZE / 2) { ut_ad(!buf_block); @@ -507,15 +494,19 @@ mem_heap_block_free( buf_block_free(buf_block); } +#else /* !UNIV_HOTBACKUP */ + ut_free(block); +#endif /* !UNIV_HOTBACKUP */ } -/********************************************************************** +#ifndef UNIV_HOTBACKUP +/******************************************************************//** Frees the free_block field from a memory heap. */ UNIV_INTERN void mem_heap_free_block_free( /*=====================*/ - mem_heap_t* heap) /* in: heap */ + mem_heap_t* heap) /*!< in: heap */ { if (UNIV_LIKELY_NULL(heap->free_block)) { @@ -524,9 +515,10 @@ mem_heap_free_block_free( heap->free_block = NULL; } } +#endif /* !UNIV_HOTBACKUP */ #ifdef MEM_PERIODIC_CHECK -/********************************************************************** +/******************************************************************//** Goes through the list of all allocated mem blocks, checks their magic numbers, and reports possible corruption. */ UNIV_INTERN diff --git a/storage/xtradb/mem/mem0pool.c b/storage/xtradb/mem/mem0pool.c index 34de6b2a706..c8fea97a6a3 100644 --- a/storage/xtradb/mem/mem0pool.c +++ b/storage/xtradb/mem/mem0pool.c @@ -16,7 +16,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA *****************************************************************************/ -/************************************************************************ +/********************************************************************//** +@file mem/mem0pool.c The lowest-level memory management Created 5/12/1997 Heikki Tuuri @@ -89,28 +90,28 @@ and for the adaptive index. Thus, for each individual transaction, its locks can occupy at most about the size of the buffer frame of memory in the common pool, and after that its locks will grow into the buffer pool. */ -/* Mask used to extract the free bit from area->size */ +/** Mask used to extract the free bit from area->size */ #define MEM_AREA_FREE 1 -/* The smallest memory area total size */ +/** The smallest memory area total size */ #define MEM_AREA_MIN_SIZE (2 * MEM_AREA_EXTRA_SIZE) -/* Data structure for a memory pool. The space is allocated using the buddy +/** Data structure for a memory pool. The space is allocated using the buddy algorithm, where free list i contains areas of size 2 to power i. */ struct mem_pool_struct{ - byte* buf; /* memory pool */ - ulint size; /* memory common pool size */ - ulint reserved; /* amount of currently allocated + byte* buf; /*!< memory pool */ + ulint size; /*!< memory common pool size */ + ulint reserved; /*!< amount of currently allocated memory */ - mutex_t mutex; /* mutex protecting this struct */ + mutex_t mutex; /*!< mutex protecting this struct */ UT_LIST_BASE_NODE_T(mem_area_t) - free_list[64]; /* lists of free memory areas: an + free_list[64]; /*!< lists of free memory areas: an area is put to the list whose number is the 2-logarithm of the area size */ }; -/* The common memory pool */ +/** The common memory pool */ UNIV_INTERN mem_pool_t* mem_comm_pool = NULL; /* We use this counter to check that the mem pool mutex does not leak; @@ -119,7 +120,7 @@ mysql@lists.mysql.com */ UNIV_INTERN ulint mem_n_threads_inside = 0; -/************************************************************************ +/********************************************************************//** Reserves the mem pool mutex. */ UNIV_INTERN void @@ -129,7 +130,7 @@ mem_pool_mutex_enter(void) mutex_enter(&(mem_comm_pool->mutex)); } -/************************************************************************ +/********************************************************************//** Releases the mem pool mutex. */ UNIV_INTERN void @@ -139,39 +140,39 @@ mem_pool_mutex_exit(void) mutex_exit(&(mem_comm_pool->mutex)); } -/************************************************************************ -Returns memory area size. */ +/********************************************************************//** +Returns memory area size. +@return size */ UNIV_INLINE ulint mem_area_get_size( /*==============*/ - /* out: size */ - mem_area_t* area) /* in: area */ + mem_area_t* area) /*!< in: area */ { return(area->size_and_free & ~MEM_AREA_FREE); } -/************************************************************************ +/********************************************************************//** Sets memory area size. */ UNIV_INLINE void mem_area_set_size( /*==============*/ - mem_area_t* area, /* in: area */ - ulint size) /* in: size */ + mem_area_t* area, /*!< in: area */ + ulint size) /*!< in: size */ { area->size_and_free = (area->size_and_free & MEM_AREA_FREE) | size; } -/************************************************************************ -Returns memory area free bit. */ +/********************************************************************//** +Returns memory area free bit. +@return TRUE if free */ UNIV_INLINE ibool mem_area_get_free( /*==============*/ - /* out: TRUE if free */ - mem_area_t* area) /* in: area */ + mem_area_t* area) /*!< in: area */ { #if TRUE != MEM_AREA_FREE # error "TRUE != MEM_AREA_FREE" @@ -179,14 +180,14 @@ mem_area_get_free( return(area->size_and_free & MEM_AREA_FREE); } -/************************************************************************ +/********************************************************************//** Sets memory area free bit. */ UNIV_INLINE void mem_area_set_free( /*==============*/ - mem_area_t* area, /* in: area */ - ibool free) /* in: free bit value */ + mem_area_t* area, /*!< in: area */ + ibool free) /*!< in: free bit value */ { #if TRUE != MEM_AREA_FREE # error "TRUE != MEM_AREA_FREE" @@ -195,14 +196,14 @@ mem_area_set_free( | free; } -/************************************************************************ -Creates a memory pool. */ +/********************************************************************//** +Creates a memory pool. +@return memory pool */ UNIV_INTERN mem_pool_t* mem_pool_create( /*============*/ - /* out: memory pool */ - ulint size) /* in: pool size in bytes */ + ulint size) /*!< in: pool size in bytes */ { mem_pool_t* pool; mem_area_t* area; @@ -259,16 +260,15 @@ mem_pool_create( return(pool); } -/************************************************************************ -Fills the specified free list. */ +/********************************************************************//** +Fills the specified free list. +@return TRUE if we were able to insert a block to the free list */ static ibool mem_pool_fill_free_list( /*====================*/ - /* out: TRUE if we were able to insert a - block to the free list */ - ulint i, /* in: free list index */ - mem_pool_t* pool) /* in: memory pool */ + ulint i, /*!< in: free list index */ + mem_pool_t* pool) /*!< in: memory pool */ { mem_area_t* area; mem_area_t* area2; @@ -331,20 +331,20 @@ mem_pool_fill_free_list( return(TRUE); } -/************************************************************************ +/********************************************************************//** Allocates memory from a pool. NOTE: This low-level function should only be -used in mem0mem.*! */ +used in mem0mem.*! +@return own: allocated memory buffer */ UNIV_INTERN void* mem_area_alloc( /*===========*/ - /* out, own: allocated memory buffer */ - ulint* psize, /* in: requested size in bytes; for optimum + ulint* psize, /*!< in: requested size in bytes; for optimum space usage, the size should be a power of 2 minus MEM_AREA_EXTRA_SIZE; out: allocated size in bytes (greater than or equal to the requested size) */ - mem_pool_t* pool) /* in: memory pool */ + mem_pool_t* pool) /*!< in: memory pool */ { mem_area_t* area; ulint size; @@ -435,16 +435,16 @@ mem_area_alloc( return((void*)(MEM_AREA_EXTRA_SIZE + ((byte*)area))); } -/************************************************************************ -Gets the buddy of an area, if it exists in pool. */ +/********************************************************************//** +Gets the buddy of an area, if it exists in pool. +@return the buddy, NULL if no buddy in pool */ UNIV_INLINE mem_area_t* mem_area_get_buddy( /*===============*/ - /* out: the buddy, NULL if no buddy in pool */ - mem_area_t* area, /* in: memory area */ - ulint size, /* in: memory area size */ - mem_pool_t* pool) /* in: memory pool */ + mem_area_t* area, /*!< in: memory area */ + ulint size, /*!< in: memory area size */ + mem_pool_t* pool) /*!< in: memory pool */ { mem_area_t* buddy; @@ -475,15 +475,15 @@ mem_area_get_buddy( return(buddy); } -/************************************************************************ +/********************************************************************//** Frees memory to a pool. */ UNIV_INTERN void mem_area_free( /*==========*/ - void* ptr, /* in, own: pointer to allocated memory + void* ptr, /*!< in, own: pointer to allocated memory buffer */ - mem_pool_t* pool) /* in: memory pool */ + mem_pool_t* pool) /*!< in: memory pool */ { mem_area_t* area; mem_area_t* buddy; @@ -604,14 +604,14 @@ mem_area_free( ut_ad(mem_pool_validate(pool)); } -/************************************************************************ -Validates a memory pool. */ +/********************************************************************//** +Validates a memory pool. +@return TRUE if ok */ UNIV_INTERN ibool mem_pool_validate( /*==============*/ - /* out: TRUE if ok */ - mem_pool_t* pool) /* in: memory pool */ + mem_pool_t* pool) /*!< in: memory pool */ { mem_area_t* area; mem_area_t* buddy; @@ -624,7 +624,8 @@ mem_pool_validate( for (i = 0; i < 64; i++) { - UT_LIST_VALIDATE(free_list, mem_area_t, pool->free_list[i]); + UT_LIST_VALIDATE(free_list, mem_area_t, pool->free_list[i], + (void) 0); area = UT_LIST_GET_FIRST(pool->free_list[i]); @@ -650,14 +651,14 @@ mem_pool_validate( return(TRUE); } -/************************************************************************ +/********************************************************************//** Prints info of a memory pool. */ UNIV_INTERN void mem_pool_print_info( /*================*/ - FILE* outfile,/* in: output file to write to */ - mem_pool_t* pool) /* in: memory pool */ + FILE* outfile,/*!< in: output file to write to */ + mem_pool_t* pool) /*!< in: memory pool */ { ulint i; @@ -683,14 +684,14 @@ mem_pool_print_info( mutex_exit(&(pool->mutex)); } -/************************************************************************ -Returns the amount of reserved memory. */ +/********************************************************************//** +Returns the amount of reserved memory. +@return reserved memory in bytes */ UNIV_INTERN ulint mem_pool_get_reserved( /*==================*/ - /* out: reserved memory in bytes */ - mem_pool_t* pool) /* in: memory pool */ + mem_pool_t* pool) /*!< in: memory pool */ { ulint reserved; |