43 #if !defined (SERVER_MODE) 47 #if !defined (SERVER_MODE) 48 #define pthread_mutex_init(a, b) 49 #define pthread_mutex_destroy(a) 50 #define pthread_mutex_lock(a) 0 51 #define pthread_mutex_unlock(a) 59 #define AREA_PREFIX_SIZE sizeof(double) 72 #if defined (SERVER_MODE) 73 pthread_mutex_t area_List_lock = PTHREAD_MUTEX_INITIALIZER;
76 #if defined (SERVER_MODE) 77 #define LF_AREA_BITMAP_USAGE_RATIO LF_BITMAP_95PERCENTILE_USAGE_RATIO 79 #define LF_AREA_BITMAP_USAGE_RATIO LF_BITMAP_FULL_USAGE_RATIO 85 #define VOLATILE_ACCESS(v,t) (*((t volatile *) &(v))) 102 #define ER_AREA_ALREADY_STARTED ER_GENERIC_ERROR 103 if (area_List !=
NULL)
123 for (area = area_List, next =
NULL; area !=
NULL; area = next)
146 area_create (
const char *name,
size_t element_size,
size_t alloc_count)
150 #if defined (SERVER_MODE) 154 area = (
AREA *) malloc (
sizeof (
AREA));
176 #if !defined (NDEBUG) 182 adjust = element_size % 8;
185 element_size += 8 - adjust;
195 #if defined (SERVER_MODE) 250 #if defined(SERVER_MODE) 258 for (prev =
NULL, a = area_List; a !=
NULL && a != area; a = a->
next)
301 if (new_block ==
NULL)
332 if (new_blockset ==
NULL)
364 int used_count,
i, entry_idx;
366 #if defined(SERVER_MODE) 369 #if !defined (NDEBUG) 389 for (i = 0; i < used_count; i++)
400 ATOMIC_CAS_ADDR (&area->
hint_block, hint_block, block);
454 #if defined(SERVER_MODE) 463 #if !defined (NDEBUG) 464 prefix = (
int *) entry_ptr;
472 return ((
void *) entry_ptr);
520 #if !defined (NDEBUG) 533 #if !defined (NDEBUG) 536 entry_ptr = (
char *) ptr;
547 offset = (int) (entry_ptr - block->
data);
548 if (offset < 0 || offset % area->element_size != 0)
555 #if !defined (NDEBUG) 556 prefix = (
int *) entry_ptr;
576 ATOMIC_CAS_ADDR (&area->
hint_block, hint_block, block);
579 #if defined(SERVER_MODE) 607 next_blockset = blockset->
next;
611 block = blockset->
items[
i];
653 last_blockset_p = &blockset->
next;
666 if (blockset->
items[used_count - 1] < new_block)
679 if (new_blockset ==
NULL)
693 *last_blockset_p = new_blockset;
712 int middle, left, right, pos;
723 first_block = blockset->
items[0];
724 if ((
char *) ptr < first_block->data)
735 assert ((first_block->
data <= (
char *) ptr) && ((
char *) ptr < last_block->data + area->
block_size));
738 right = used_count - 1;
741 while (left <= right)
743 middle = (left + right) / 2;
746 if (block->
data > (
char *) ptr)
766 if ((block->
data <= (
char *) ptr) && ((
char *) ptr < block->data + area->
block_size))
787 size_t nblocksets, nblocks, bytes, elements, used, unused;
788 size_t min_blocks_in_set, avg_blocks_in_set, max_blocks_in_set;
789 size_t nallocs = 0, nfrees = 0;
794 nblocksets = nblocks = bytes = elements = used = unused = 0;
796 max_blocks_in_set = 0;
804 block = blockset->
items[
i];
811 if ((
size_t) blockset->
used_count < min_blocks_in_set)
815 if ((
size_t) blockset->
used_count > max_blocks_in_set)
820 avg_blocks_in_set = nblocks / nblocksets;
823 unused = elements - used;
828 fprintf (fp,
"Area: %s\n", area->
name);
829 #if !defined (NDEBUG) 833 fprintf (fp,
" %lld bytes/element, ", (
long long) area->
element_size);
835 fprintf (fp,
"%lld elements/block, %lld blocks/blockset\n", (
long long) area->
alloc_count,
838 fprintf (fp,
" %lld blocksets, usage stats:" " MIN %lld, AVG %lld, MAX %lld\n", (
long long) nblocksets,
839 (
long long) min_blocks_in_set, (
long long) avg_blocks_in_set, (
long long) max_blocks_in_set);
841 fprintf (fp,
" %lld blocks, %lld bytes, %lld elements," " %lld unused, %lld in use\n", (
long long) nblocks,
842 (
long long) bytes, (
long long) elements, (
long long) unused, (
long long) used);
844 fprintf (fp,
" %lld total allocs, %lld total frees\n", (
long long) nallocs, (
long long) nfrees);
856 #if defined(SERVER_MODE) 867 for (area = area_List; area !=
NULL; area = area->
next)
#define ER_AREA_ALREADY_STARTED
void area_destroy(AREA *area)
#define pthread_mutex_init(a, b)
static AREA_BLOCK * area_find_block(AREA *area, const void *ptr)
#define pthread_mutex_unlock(a)
void free_entry(int entry_idx)
static AREA_BLOCK * area_alloc_block(AREA *area)
static int area_insert_block(AREA *area, AREA_BLOCK *new_block)
static AREA_BLOCKSET_LIST * area_alloc_blockset(AREA *area)
#define LF_BITMAP_IS_FULL(bitmap)
struct area_block AREA_BLOCK
AREA_BLOCKSET_LIST * next
AREA * area_create(const char *name, size_t element_size, size_t alloc_count)
#define LF_BITMAP_COUNT_ALIGN(count)
static void area_info(AREA *area, FILE *fp)
void er_set(int severity, const char *file_name, const int line_no, int err_id, int num_args,...)
int area_validate(AREA *area, const void *address)
#define ER_AREA_ILLEGAL_POINTER
AREA_BLOCKSET_LIST * blockset_list
void(* failure_function)(void)
#define ER_OUT_OF_VIRTUAL_MEMORY
std::atomic< int > entry_count_in_use
static const LF_BITMAP_STYLE LF_BITMAP_LIST_OF_CHUNKS
pthread_mutex_t area_mutex
static void error(const char *msg)
static DB_VALUE * new_block(long n)
#define AREA_BLOCKSET_SIZE
#define free_and_init(ptr)
void * area_alloc(AREA *area)
#define ER_AREA_FREE_TWICE
int area_free(AREA *area, void *ptr)
AREA_BLOCK * items[AREA_BLOCKSET_SIZE]
char * strdup(const char *str)
#define pthread_mutex_lock(a)
#define VOLATILE_ACCESS(v, t)
#define LF_AREA_BITMAP_USAGE_RATIO
void area_flush(AREA *area)
void ws_abort_transaction(void)
void init(chunking_style style, int entries_count, float usage_ratio)
#define pthread_mutex_destroy(a)