From: Vsevolod Stakhov Date: Tue, 16 Jun 2009 11:02:37 +0000 (+0400) Subject: * Use glib slice allocator for memory pool allocator, optimize chunk size X-Git-Tag: 0.2.7~121 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=53b1f011a3b34a40b08882e34083db820a815bab;p=rspamd.git * Use glib slice allocator for memory pool allocator, optimize chunk size --- diff --git a/src/mem_pool.c b/src/mem_pool.c index 9ea86103c..4261e9f8d 100644 --- a/src/mem_pool.c +++ b/src/mem_pool.c @@ -59,8 +59,8 @@ pool_chain_new (memory_pool_ssize_t size) g_assert (size > 0); - chain = g_malloc (sizeof (struct _pool_chain)); - chain->begin = g_malloc (size); + chain = g_slice_alloc (sizeof (struct _pool_chain)); + chain->begin = g_slice_alloc (size); chain->len = size; chain->pos = chain->begin; chain->next = NULL; @@ -137,7 +137,7 @@ memory_pool_new (memory_pool_ssize_t size) #endif } - new = g_malloc (sizeof (memory_pool_t)); + new = g_slice_alloc (sizeof (memory_pool_t)); new->cur_pool = pool_chain_new (size); new->shared_pool = NULL; new->first_pool = new->cur_pool; @@ -438,8 +438,8 @@ memory_pool_delete (memory_pool_t *pool) while (cur) { tmp = cur; cur = cur->next; - g_free (tmp->begin); - g_free (tmp); + g_slice_free1 (tmp->len, tmp->begin); + g_slice_free (struct _pool_chain, tmp); STAT_LOCK (); mem_pool_stat->chunks_freed ++; STAT_UNLOCK (); @@ -455,7 +455,7 @@ memory_pool_delete (memory_pool_t *pool) } mem_pool_stat->pools_freed ++; - g_free (pool); + g_slice_free (memory_pool_t, pool); } void @@ -471,14 +471,15 @@ memory_pool_stat (memory_pool_stat_t *st) st->oversized_chunks = mem_pool_stat->oversized_chunks; } -#define FIXED_POOL_SIZE 4095 +/* By default allocate 8Kb chunks of memory */ +#define FIXED_POOL_SIZE 8192 memory_pool_ssize_t memory_pool_get_size () { #ifdef HAVE_GETPAGESIZE - return getpagesize () - 1; + return MAX (getpagesize (), FIXED_POOL_SIZE); #else - return FIXED_POOL_SIZE; + return MAX (sysconf (_SC_PAGESIZE), FIXED_POOL_SIZE); #endif } diff --git a/src/mem_pool.h b/src/mem_pool.h index 29cd3b9d7..b55670c95 100644 --- a/src/mem_pool.h +++ b/src/mem_pool.h @@ -42,7 +42,7 @@ typedef struct memory_pool_mutex_s { struct _pool_chain { u_char *begin; /**< begin of pool chain block */ u_char *pos; /**< current start of free space in block */ - memory_pool_ssize_t len; /**< length of block */ + memory_pool_ssize_t len; /**< length of block */ struct _pool_chain *next; /**< chain link */ };