Hi,
If my tests are correct the following patch makes the pool allocation tree times faster on WIN32 (at least for 1 million 32 bytes allocations).
Not sure what's the total httpd's time spent for palloc, but I suppose it's quite a large value.
Regards, MT.
Index: apr_pools.c =================================================================== RCS file: /home/cvspublic/apr/memory/unix/apr_pools.c,v retrieving revision 1.206 diff -u -r1.206 apr_pools.c --- apr_pools.c 17 Jun 2004 14:13:58 -0000 1.206 +++ apr_pools.c 1 Sep 2004 17:25:44 -0000 @@ -58,6 +58,14 @@ #define TIMEOUT_USECS 3000000 #define TIMEOUT_INTERVAL 46875
+#if APR_POOL_DEBUG
+#define APR_HAS_WIN32_HEAP 0
+#else
+#ifdef _WIN32
+#define APR_HAS_WIN32_HEAP 1
+#endif
+#endif
+
/*
* Allocator
*/
@@ -71,6 +79,9 @@
#endif /* APR_HAS_THREADS */
apr_pool_t *owner;
apr_memnode_t *free[MAX_INDEX];
+#if APR_HAS_WIN32_HEAP
+ HANDLE heap;
+#endif
}; #define SIZEOF_ALLOCATOR_T APR_ALIGN_DEFAULT(sizeof(apr_allocator_t))
@@ -84,12 +95,22 @@
{
apr_allocator_t *new_allocator;+#if APR_HAS_WIN32_HEAP
+ HANDLE heap;
+
+ heap = HeapCreate(HEAP_NO_SERIALIZE, 64 * 1024, 0);
+ if ((new_allocator = HeapAlloc(heap, HEAP_ZERO_MEMORY,
+ SIZEOF_ALLOCATOR_T)) == NULL)
+ return APR_ENOMEM;
+ new_allocator->heap = heap;
+#else
*allocator = NULL; if ((new_allocator = malloc(SIZEOF_ALLOCATOR_T)) == NULL)
return APR_ENOMEM; memset(new_allocator, 0, SIZEOF_ALLOCATOR_T);
+#endif
new_allocator->max_free_index = APR_ALLOCATOR_MAX_FREE_UNLIMITED;*allocator = new_allocator; @@ -99,6 +120,9 @@
APR_DECLARE(void) apr_allocator_destroy(apr_allocator_t *allocator)
{
+#if APR_HAS_WIN32_HEAP
+ HeapDestroy(allocator->heap);
+#else
apr_uint32_t index;
apr_memnode_t *node, **ref;@@ -111,6 +135,7 @@
}free(allocator); +#endif }
#if APR_HAS_THREADS
@@ -289,8 +314,13 @@
/* If we haven't got a suitable node, malloc a new one
* and initialize it.
*/
+#if APR_HAS_WIN32_HEAP
+ if ((node = HeapAlloc(allocator->heap, HEAP_NO_SERIALIZE, size)) == NULL)
+ return NULL;
+#else
if ((node = malloc(size)) == NULL)
return NULL;
+#endif
node->next = NULL;
node->index = index;
@@ -360,7 +390,11 @@
while (freelist != NULL) {
node = freelist;
freelist = node->next;
+#if APR_HAS_WIN32_HEAP
+ HeapFree(allocator->heap, HEAP_NO_SERIALIZE, node);
+#else
free(node);
+#endif
}
}
smime.p7s
Description: S/MIME Cryptographic Signature
