]> source.dussan.org Git - rspamd.git/commitdiff
* Use glib slice allocator for memory pool allocator, optimize chunk size
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Tue, 16 Jun 2009 11:02:37 +0000 (15:02 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Tue, 16 Jun 2009 11:02:37 +0000 (15:02 +0400)
src/mem_pool.c
src/mem_pool.h

index 9ea86103cf010e1fe8f29076fd10a7b824e3fb8e..4261e9f8d534a48e540f524d69de7706b1ad34a1 100644 (file)
@@ -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
 }
 
index 29cd3b9d7e92a9e9cc1c4bff0948ae739b55db0c..b55670c9537b5cbd60adf4bfa411ddfbd7b96987 100644 (file)
@@ -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                                                         */
 };