mirror of
https://github.com/MariaDB/server.git
synced 2025-01-18 21:12:26 +01:00
branches/zip: Reduce internal memory fragmentation.
mem_alloc2(): New macro. This is a variant of mem_alloc() that returns the allocated size, which is equal to or greater than the requested size. mem_alloc_func(): Add the output parameter *size for the allocated size. When it is set, adjust the parameter passed to mem_heap_alloc(). rec_copy_prefix_to_buf_old(), rec_copy_prefix_to_buf(): Use mem_alloc2() instead of mem_alloc().
This commit is contained in:
parent
7a0a4df586
commit
4bf90e5355
3 changed files with 21 additions and 6 deletions
|
@ -199,7 +199,8 @@ Macro for memory buffer allocation */
|
|||
|
||||
#define mem_zalloc(N) memset(mem_alloc(N), 0, (N));
|
||||
|
||||
#define mem_alloc(N) mem_alloc_func((N), __FILE__, __LINE__)
|
||||
#define mem_alloc(N) mem_alloc_func((N), NULL, __FILE__, __LINE__)
|
||||
#define mem_alloc2(N,S) mem_alloc_func((N), (S), __FILE__, __LINE__)
|
||||
/*******************************************************************
|
||||
NOTE: Use the corresponding macro instead of this function.
|
||||
Allocates a single buffer of memory from the dynamic memory of
|
||||
|
@ -210,7 +211,9 @@ void*
|
|||
mem_alloc_func(
|
||||
/*===========*/
|
||||
/* out, own: free storage */
|
||||
ulint n, /* in: desired number of bytes */
|
||||
ulint n, /* in: requested size in bytes */
|
||||
ulint* size, /* out: allocated size in bytes,
|
||||
or NULL */
|
||||
const char* file_name, /* in: file name where created */
|
||||
ulint line); /* in: line where created */
|
||||
|
||||
|
|
|
@ -496,6 +496,8 @@ mem_alloc_func(
|
|||
/*===========*/
|
||||
/* out, own: free storage */
|
||||
ulint n, /* in: desired number of bytes */
|
||||
ulint* size, /* out: allocated size in bytes,
|
||||
or NULL */
|
||||
const char* file_name, /* in: file name where created */
|
||||
ulint line) /* in: line where created */
|
||||
{
|
||||
|
@ -509,6 +511,18 @@ mem_alloc_func(
|
|||
first block and thus we can calculate the pointer to the heap from
|
||||
the pointer to the buffer when we free the memory buffer. */
|
||||
|
||||
if (UNIV_LIKELY_NULL(size)) {
|
||||
/* Adjust the allocation to the actual size of the
|
||||
memory block. */
|
||||
ulint m = mem_block_get_len(heap)
|
||||
- mem_block_get_free(heap);
|
||||
#ifdef UNIV_MEM_DEBUG
|
||||
m -= MEM_FIELD_HEADER_SIZE + MEM_FIELD_TRAILER_SIZE;
|
||||
#endif /* UNIV_MEM_DEBUG */
|
||||
ut_ad(m >= n);
|
||||
*size = n = m;
|
||||
}
|
||||
|
||||
buf = mem_heap_alloc(heap, n);
|
||||
|
||||
ut_a((byte*)heap == (byte*)buf - MEM_BLOCK_HEADER_SIZE
|
||||
|
|
|
@ -1260,8 +1260,7 @@ rec_copy_prefix_to_buf_old(
|
|||
mem_free(*buf);
|
||||
}
|
||||
|
||||
*buf = mem_alloc(prefix_len);
|
||||
*buf_size = prefix_len;
|
||||
*buf = mem_alloc2(prefix_len, buf_size);
|
||||
}
|
||||
|
||||
ut_memcpy(*buf, rec - area_start, prefix_len);
|
||||
|
@ -1378,8 +1377,7 @@ rec_copy_prefix_to_buf(
|
|||
mem_free(*buf);
|
||||
}
|
||||
|
||||
*buf = mem_alloc(prefix_len);
|
||||
*buf_size = prefix_len;
|
||||
*buf = mem_alloc2(prefix_len, buf_size);
|
||||
}
|
||||
|
||||
memcpy(*buf, lens + 1, prefix_len);
|
||||
|
|
Loading…
Reference in a new issue