apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s.@apache.org
Subject svn commit: r1594729 - in /apr/apr/trunk: CHANGES memory/unix/apr_pools.c
Date Wed, 14 May 2014 21:30:49 GMT
Author: sf
Date: Wed May 14 21:30:48 2014
New Revision: 1594729

URL: http://svn.apache.org/r1594729
Log:
Don't waste memory when creating or allocating from small, long-lived
APR pools after clearing or destroying pools that allocated larger
nodes.

When allocating nodes from the bucket allocator (<= 80k or 20 pages),
we would eagerly reuse *any* free node that is at least the minimum
size.  Depending on the pool usage scheme, that extra memory would
never be used.  This patch limits the node to approximate twice the
minimum.

* memory/unix/apr_pools.c
  (allocator_alloc): When searching the buckets for free nodes, limit
                     the range to twice the starting index. 


Submitted by: Stefan Fuhrmann <stefan fuhrmann wandisco com>



Modified:
    apr/apr/trunk/CHANGES
    apr/apr/trunk/memory/unix/apr_pools.c

Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/trunk/CHANGES?rev=1594729&r1=1594728&r2=1594729&view=diff
==============================================================================
--- apr/apr/trunk/CHANGES [utf-8] (original)
+++ apr/apr/trunk/CHANGES [utf-8] Wed May 14 21:30:48 2014
@@ -1,6 +1,10 @@
                                                      -*- coding: utf-8 -*-
 Changes for APR 2.0.0
 
+  *) apr_allocator: Be less wasteful and don't return a memnode that is
+     much larger than what was requested. [Stefan Fuhrmann
+     <stefan fuhrmann wandisco com>]
+
   *) Windows platform: Remove support for Windows 9x.
 
   *) Added signed apr_intptr_t.  Changed ODBC dbd driver to use this.

Modified: apr/apr/trunk/memory/unix/apr_pools.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/memory/unix/apr_pools.c?rev=1594729&r1=1594728&r2=1594729&view=diff
==============================================================================
--- apr/apr/trunk/memory/unix/apr_pools.c (original)
+++ apr/apr/trunk/memory/unix/apr_pools.c Wed May 14 21:30:48 2014
@@ -239,7 +239,7 @@ static APR_INLINE
 apr_memnode_t *allocator_alloc(apr_allocator_t *allocator, apr_size_t in_size)
 {
     apr_memnode_t *node, **ref;
-    apr_uint32_t max_index;
+    apr_uint32_t max_index, upper_index;
     apr_size_t size, i, index;
 
     /* Round up the block size to the next boundary, but always
@@ -273,6 +273,11 @@ apr_memnode_t *allocator_alloc(apr_alloc
         /* Walk the free list to see if there are
          * any nodes on it of the requested size
          *
+         * If there is no exact match, look for nodes
+         * of up to twice the requested size, so we
+         * won't unnecessarily allocate more memory
+         * nor waste too much of what we have.
+         *
          * NOTE: an optimization would be to check
          * allocator->free[index] first and if no
          * node is present, directly use
@@ -281,9 +286,10 @@ apr_memnode_t *allocator_alloc(apr_alloc
          * memory waste.
          */
         max_index = allocator->max_index;
+        upper_index = 2 * index < max_index ? 2 * index : max_index;
         ref = &allocator->free[index];
         i = index;
-        while (*ref == NULL && i < max_index) {
+        while (*ref == NULL && i < upper_index) {
            ref++;
            i++;
         }



Mime
View raw message