summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <bell@sanja.is.com.ua>2002-04-13 12:08:12 +0300
committerunknown <bell@sanja.is.com.ua>2002-04-13 12:08:12 +0300
commitf095ef5dc2bac8eebd87919f5106e30d4e21cabf (patch)
treef5d09a2f85ce2f9558ed0aac2b929454e2b29f62
parenta58fbde1d29c8da4e1cb509d0ad9cf2bc86a3839 (diff)
downloadmariadb-git-f095ef5dc2bac8eebd87919f5106e30d4e21cabf.tar.gz
allocated bigger blocks if it needed
include/my_sys.h: memory root structures definition put in one file include/mysql.h: memory root structures definition put in one file
-rw-r--r--include/my_alloc.h39
-rw-r--r--include/my_sys.h21
-rw-r--r--include/mysql.h18
-rw-r--r--mysys/my_alloc.c16
4 files changed, 49 insertions, 45 deletions
diff --git a/include/my_alloc.h b/include/my_alloc.h
new file mode 100644
index 00000000000..0857c8886c5
--- /dev/null
+++ b/include/my_alloc.h
@@ -0,0 +1,39 @@
+/* Copyright (C) 2000 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+/*
+ Data structures for mysys/my_alloc.c (root memory allocator)
+*/
+
+#ifndef ST_USED_MEM_DEFINED
+#define ST_USED_MEM_DEFINED
+typedef struct st_used_mem { /* struct for once_alloc (block) */
+ struct st_used_mem *next; /* Next block in use */
+ unsigned int left; /* memory left in block */
+ unsigned int size; /* size of block */
+} USED_MEM;
+typedef struct st_mem_root {
+ USED_MEM *free; /* blocks with free memory in it */
+ USED_MEM *used; /* blocks almost without free memory */
+ USED_MEM *pre_alloc; /* preallocated block */
+ /* if block have less memory it will be put in 'used' list*/
+ unsigned int min_malloc;
+ unsigned int block_size; /* initial block size */
+ unsigned int block_num; /* allocated blocks counter */
+
+ void (*error_handler)(void);
+} MEM_ROOT;
+#endif
diff --git a/include/my_sys.h b/include/my_sys.h
index 5867368198f..c4ab76a2ee0 100644
--- a/include/my_sys.h
+++ b/include/my_sys.h
@@ -464,26 +464,7 @@ typedef struct st_changeable_var {
} CHANGEABLE_VAR;
-/* structs for alloc_root */
-
-#ifndef ST_USED_MEM_DEFINED
-#define ST_USED_MEM_DEFINED
-typedef struct st_used_mem { /* struct for once_alloc */
- struct st_used_mem *next; /* Next block in use */
- unsigned int left; /* memory left in block */
- unsigned int size; /* Size of block */
-} USED_MEM;
-
-typedef struct st_mem_root {
- USED_MEM *free;
- USED_MEM *used;
- USED_MEM *pre_alloc;
- unsigned int min_malloc;
- unsigned int block_size;
-
- void (*error_handler)(void);
-} MEM_ROOT;
-#endif
+#include "my_alloc.h"
/* Prototypes for mysys and my_func functions */
diff --git a/include/mysql.h b/include/mysql.h
index 7a16cbbe1d2..90deb791dd0 100644
--- a/include/mysql.h
+++ b/include/mysql.h
@@ -100,23 +100,7 @@ typedef struct st_mysql_rows {
typedef MYSQL_ROWS *MYSQL_ROW_OFFSET; /* offset to current row */
-#ifndef ST_USED_MEM_DEFINED
-#define ST_USED_MEM_DEFINED
-typedef struct st_used_mem { /* struct for once_alloc */
- struct st_used_mem *next; /* Next block in use */
- unsigned int left; /* memory left in block */
- unsigned int size; /* size of block */
-} USED_MEM;
-typedef struct st_mem_root {
- USED_MEM *free;
- USED_MEM *used;
- USED_MEM *pre_alloc;
- unsigned int min_malloc;
- unsigned int block_size;
-
- void (*error_handler)(void);
-} MEM_ROOT;
-#endif
+#include "my_alloc.h"
typedef struct st_mysql_data {
my_ulonglong rows;
diff --git a/mysys/my_alloc.c b/mysys/my_alloc.c
index 789e64526a3..5a6afe2fac9 100644
--- a/mysys/my_alloc.c
+++ b/mysys/my_alloc.c
@@ -29,6 +29,7 @@ void init_alloc_root(MEM_ROOT *mem_root, uint block_size,
mem_root->min_malloc=32;
mem_root->block_size=block_size-MALLOC_OVERHEAD-sizeof(USED_MEM)-8;
mem_root->error_handler=0;
+ mem_root->block_num= 0;
#if !(defined(HAVE_purify) && defined(EXTRA_DEBUG))
if (pre_alloc_size)
{
@@ -61,25 +62,20 @@ gptr alloc_root(MEM_ROOT *mem_root,unsigned int Size)
mem_root->used=next;
return (gptr) (((char*) next)+ALIGN_SIZE(sizeof(USED_MEM)));
#else
- uint get_size,max_left;
+ uint get_size, block_size;
gptr point;
reg1 USED_MEM *next;
reg2 USED_MEM **prev;
Size= ALIGN_SIZE(Size);
prev= &mem_root->free;
- max_left=0;
for (next= *prev ; next && next->left < Size ; next= next->next)
- {
- if (next->left > max_left)
- max_left=next->left;
prev= &next->next;
- }
if (! next)
{ /* Time to alloc new block */
+ block_size= mem_root->block_size*((mem_root->block_num>>2)+1);
get_size= Size+ALIGN_SIZE(sizeof(USED_MEM));
- if (max_left*4 < mem_root->block_size && get_size < mem_root->block_size)
- get_size=mem_root->block_size; /* Normal alloc */
+ get_size= max(get_size, block_size);
if (!(next = (USED_MEM*) my_malloc(get_size,MYF(MY_WME))))
{
@@ -87,6 +83,7 @@ gptr alloc_root(MEM_ROOT *mem_root,unsigned int Size)
(*mem_root->error_handler)();
return((gptr) 0); /* purecov: inspected */
}
+ mem_root->block_num++;
next->next= *prev;
next->size= get_size;
next->left= get_size-ALIGN_SIZE(sizeof(USED_MEM));
@@ -165,7 +162,10 @@ void free_root(MEM_ROOT *root, myf MyFlags)
root->free=root->pre_alloc;
root->free->left=root->pre_alloc->size-ALIGN_SIZE(sizeof(USED_MEM));
root->free->next=0;
+ root->block_num= 1;
}
+ else
+ root->block_num= 0;
DBUG_VOID_RETURN;
}