You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by sf...@apache.org on 2011/03/20 23:16:27 UTC

svn commit: r1083599 - in /apr/apr/branches/1.4.x: ./ CHANGES configure.in memory/unix/apr_pools.c

Author: sf
Date: Sun Mar 20 22:16:26 2011
New Revision: 1083599

URL: http://svn.apache.org/viewvc?rev=1083599&view=rev
Log:
Backport r1072165, but mark as experimental in CHANGES and "configure --help"
for now:

    Add new configure option --enable-allocator-uses-mmap to use mmap
    instead of malloc in apr_allocator_alloc(). This greatly reduces
    memory fragmentation with malloc implementations (e.g. glibc) that
    don't handle allocationss of a page-size-multiples in an efficient way.
    It also makes apr_allocator_max_free_set() actually have some effect
    on such platforms.
    
    The handling of page sizes other than 4k seems like a lot of trouble for a
    very small number of platforms, but there does not seem to be a reasonable
    way to check this at compile time.


Modified:
    apr/apr/branches/1.4.x/   (props changed)
    apr/apr/branches/1.4.x/CHANGES
    apr/apr/branches/1.4.x/configure.in
    apr/apr/branches/1.4.x/memory/unix/apr_pools.c

Propchange: apr/apr/branches/1.4.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Mar 20 22:16:26 2011
@@ -1 +1,2 @@
-/apr/apr/trunk:733052,747990,748361,748371,748565,748888,748902,748988,749810,760443,782838,783398,783958,784633,784773,788588,793192-793193,794118,794485,795267,799497,800627,809745,809854,810472,811455,813063,821306,829490,831641,835607,905040,908427,910419,917837-917838,983618,990435,1078845
+/apr/apr/branches/1.5.x:1083592
+/apr/apr/trunk:733052,747990,748361,748371,748565,748888,748902,748988,749810,760443,782838,783398,783958,784633,784773,788588,793192-793193,794118,794485,795267,799497,800627,809745,809854,810472,811455,813063,821306,829490,831641,835607,905040,908427,910419,917837-917838,983618,990435,1072165,1078845

Modified: apr/apr/branches/1.4.x/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.4.x/CHANGES?rev=1083599&r1=1083598&r2=1083599&view=diff
==============================================================================
--- apr/apr/branches/1.4.x/CHANGES [utf-8] (original)
+++ apr/apr/branches/1.4.x/CHANGES [utf-8] Sun Mar 20 22:16:26 2011
@@ -1,6 +1,13 @@
                                                      -*- coding: utf-8 -*-
 Changes for APR 1.4.3
 
+  *) Add new experimental configure option --enable-allocator-uses-mmap to
+     use mmap instead of malloc in apr_allocator_alloc(). This greatly reduces
+     memory fragmentation with malloc implementations (e.g. glibc) that
+     don't handle allocationss of a page-size-multiples in an efficient way.
+     It also makes apr_allocator_max_free_set() actually have some effect
+     on such platforms. [Stefan Fritsch]
+
   *) configure: Support 64 and 32 bit universal builds for Darwin/
      OS X 10.6+. [Jim Jagielski]
 

Modified: apr/apr/branches/1.4.x/configure.in
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.4.x/configure.in?rev=1083599&r1=1083598&r2=1083599&view=diff
==============================================================================
--- apr/apr/branches/1.4.x/configure.in (original)
+++ apr/apr/branches/1.4.x/configure.in Sun Mar 20 22:16:26 2011
@@ -1544,6 +1544,18 @@ if test "$netdbh" = "1"; then
   fi
 fi
 
+AC_ARG_ENABLE(allocator-uses-mmap,
+  [  --enable-allocator-uses-mmap    Use mmap in apr_allocator instead of malloc (experimental)],
+  [ if test "$enableval" = "yes"; then
+        APR_IFALLYES(header:sys/mman.h func:mmap func:munmap define:MAP_ANON,
+                     [AC_DEFINE(APR_ALLOCATOR_USES_MMAP, 1,
+                                [Define if apr_allocator should use mmap]) ],
+		     [AC_MSG_ERROR([mmap()/MAP_ANON not supported]) ]
+		    )
+    fi ],
+  [ ]
+)
+
 dnl ----------------------------- Checks for standard typedefs
 AC_TYPE_OFF_T
 AC_TYPE_PID_T

Modified: apr/apr/branches/1.4.x/memory/unix/apr_pools.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.4.x/memory/unix/apr_pools.c?rev=1083599&r1=1083598&r2=1083599&view=diff
==============================================================================
--- apr/apr/branches/1.4.x/memory/unix/apr_pools.c (original)
+++ apr/apr/branches/1.4.x/memory/unix/apr_pools.c Sun Mar 20 22:16:26 2011
@@ -36,9 +36,12 @@
 #endif
 
 #if APR_HAVE_UNISTD_H
-#include <unistd.h>     /* for getpid */
+#include <unistd.h>     /* for getpid and sysconf */
 #endif
 
+#if APR_ALLOCATOR_USES_MMAP
+#include <sys/mman.h>
+#endif
 
 /*
  * Magic numbers
@@ -47,8 +50,15 @@
 #define MIN_ALLOC 8192
 #define MAX_INDEX   20
 
+#if APR_ALLOCATOR_USES_MMAP && defined(_SC_PAGESIZE)
+static unsigned int boundary_index;
+static unsigned int boundary_size;
+#define BOUNDARY_INDEX  boundary_index
+#define BOUNDARY_SIZE   boundary_size
+#else
 #define BOUNDARY_INDEX 12
 #define BOUNDARY_SIZE (1 << BOUNDARY_INDEX)
+#endif
 
 /* 
  * Timing constants for killing subprocesses
@@ -131,7 +141,11 @@ APR_DECLARE(void) apr_allocator_destroy(
         ref = &allocator->free[index];
         while ((node = *ref) != NULL) {
             *ref = node->next;
+#if APR_ALLOCATOR_USES_MMAP
+            munmap(node, (node->index+1) << BOUNDARY_INDEX);
+#else
             free(node);
+#endif
         }
     }
 
@@ -323,7 +337,12 @@ apr_memnode_t *allocator_alloc(apr_alloc
     /* If we haven't got a suitable node, malloc a new one
      * and initialize it.
      */
+#if APR_ALLOCATOR_USES_MMAP
+    if ((node = mmap(NULL, size, PROT_READ|PROT_WRITE,
+                     MAP_PRIVATE|MAP_ANON, -1, 0)) == MAP_FAILED)
+#else
     if ((node = malloc(size)) == NULL)
+#endif
         return NULL;
 
     node->next = NULL;
@@ -400,7 +419,11 @@ void allocator_free(apr_allocator_t *all
     while (freelist != NULL) {
         node = freelist;
         freelist = node->next;
+#if APR_ALLOCATOR_USES_MMAP
+        munmap(node, (node->index+1) << BOUNDARY_INDEX);
+#else
         free(node);
+#endif
     }
 }
 
@@ -549,6 +572,14 @@ APR_DECLARE(apr_status_t) apr_pool_initi
     if (apr_pools_initialized++)
         return APR_SUCCESS;
 
+#if APR_ALLOCATOR_USES_MMAP && defined(_SC_PAGESIZE)
+    boundary_size = sysconf(_SC_PAGESIZE);
+    boundary_index = 12;
+    while ( (1 << boundary_index) < boundary_size)
+        boundary_index++;
+    boundary_size = (1 << boundary_index);
+#endif
+
     if ((rv = apr_allocator_create(&global_allocator)) != APR_SUCCESS) {
         apr_pools_initialized = 0;
         return rv;
@@ -1336,6 +1367,14 @@ APR_DECLARE(apr_status_t) apr_pool_initi
     if (apr_pools_initialized++)
         return APR_SUCCESS;
 
+#if APR_ALLOCATOR_USES_MMAP && defined(_SC_PAGESIZE)
+    boundary_size = sysconf(_SC_PAGESIZE);
+    boundary_index = 12;
+    while ( (1 << boundary_index) < boundary_size)
+        boundary_index++;
+    boundary_size = (1 << boundary_index);
+#endif
+
     /* Since the debug code works a bit differently then the
      * regular pools code, we ask for a lock here.  The regular
      * pools code has got this lock embedded in the global



Re: svn commit: r1083599 - in /apr/apr/branches/1.4.x: ./ CHANGES configure.in memory/unix/apr_pools.c

Posted by Stefan Fritsch <sf...@sfritsch.de>.
On Monday 21 March 2011, Jeff Trawick wrote:
> This last ",\n[]" causes a shell script error for me on MinGW using
> autoconf 2.67 and bash 3.1.  Perhaps it is a system problem (no
> issues for me in my normal env), but the argument is not in apr
> trunk and I can't fathom why an empty action-if-option-not-given
> is useful, so I will yank.

Thanks. I overlooked that fix when backporting.

Re: svn commit: r1083599 - in /apr/apr/branches/1.4.x: ./ CHANGES configure.in memory/unix/apr_pools.c

Posted by Jeff Trawick <tr...@gmail.com>.
On Sun, Mar 20, 2011 at 6:16 PM,  <sf...@apache.org> wrote:
> Author: sf
> Date: Sun Mar 20 22:16:26 2011
> New Revision: 1083599
>
> URL: http://svn.apache.org/viewvc?rev=1083599&view=rev
> Log:
> Backport r1072165, but mark as experimental in CHANGES and "configure --help"
> for now:
>
>    Add new configure option --enable-allocator-uses-mmap to use mmap
>    instead of malloc in apr_allocator_alloc(). This greatly reduces
>    memory fragmentation with malloc implementations (e.g. glibc) that
>    don't handle allocationss of a page-size-multiples in an efficient way.
>    It also makes apr_allocator_max_free_set() actually have some effect
>    on such platforms.
>
>    The handling of page sizes other than 4k seems like a lot of trouble for a
>    very small number of platforms, but there does not seem to be a reasonable
>    way to check this at compile time.
>
>
> Modified:
>    apr/apr/branches/1.4.x/   (props changed)
>    apr/apr/branches/1.4.x/CHANGES
>    apr/apr/branches/1.4.x/configure.in
>    apr/apr/branches/1.4.x/memory/unix/apr_pools.c
>
> Modified: apr/apr/branches/1.4.x/configure.in
> URL: http://svn.apache.org/viewvc/apr/apr/branches/1.4.x/configure.in?rev=1083599&r1=1083598&r2=1083599&view=diff
> ==============================================================================
> --- apr/apr/branches/1.4.x/configure.in (original)
> +++ apr/apr/branches/1.4.x/configure.in Sun Mar 20 22:16:26 2011
> @@ -1544,6 +1544,18 @@ if test "$netdbh" = "1"; then
>   fi
>  fi
>
> +AC_ARG_ENABLE(allocator-uses-mmap,
> +  [  --enable-allocator-uses-mmap    Use mmap in apr_allocator instead of malloc (experimental)],
> +  [ if test "$enableval" = "yes"; then
> +        APR_IFALLYES(header:sys/mman.h func:mmap func:munmap define:MAP_ANON,
> +                     [AC_DEFINE(APR_ALLOCATOR_USES_MMAP, 1,
> +                                [Define if apr_allocator should use mmap]) ],
> +                    [AC_MSG_ERROR([mmap()/MAP_ANON not supported]) ]
> +                   )
> +    fi ],
> +  [ ]

This last ",\n[]" causes a shell script error for me on MinGW using
autoconf 2.67 and bash 3.1.  Perhaps it is a system problem (no issues
for me in my normal env), but the argument is not in apr trunk and I
can't fathom why an empty action-if-option-not-given is useful, so I
will yank.