Cliff Woolley wrote:

On Sat, 10 Nov 2001, Brian Pane wrote:

Is anybody working on modifying mmap_setaside so that it doesn't
have to memcpy the file contents?  (I recall this being an issue
a while ago.)  This could yield a small but measurable improvement
on requests that aren't handled using sendfile


I have worked on it in the past but haven't actively looked at in several weeks now. It's a tricky issue... the last time I looked at it, here's what I came up with:

http://marc.theaimsgroup.com/?l=apr-dev&m=100335839408391&w=2


Thanks for the pointer. Here's my attempt to work around the problem that
you noted in that message--the fact that the apr_mmap_t cleanup function
isn't accessible from within mmap_setaside. My solution was to add a pointer
to the cleanup function as an extra field in the apr_mmap_t.


In this patch, I've only tried to optimize for the case where the destination
pool is an ancestor of the current pool. For disjoint pools, it will still
do the big memcpy.


--Brian


Index: srclib/apr/include/apr_mmap.h
===================================================================
RCS file: /home/cvspublic/apr/include/apr_mmap.h,v
retrieving revision 1.25
diff -u -r1.25 apr_mmap.h
--- srclib/apr/include/apr_mmap.h       2001/08/18 15:15:46     1.25
+++ srclib/apr/include/apr_mmap.h       2001/11/14 07:30:05
@@ -111,6 +111,8 @@
     void *mm;
     /** The amount of data in the mmap */
     apr_size_t size;
+    /** Cleanup function */
+    apr_status_t (*cleanup)(void *);
 };
 
 #if APR_HAS_MMAP || defined(DOXYGEN)
Index: srclib/apr/mmap/unix/mmap.c
===================================================================
RCS file: /home/cvspublic/apr/mmap/unix/mmap.c,v
retrieving revision 1.36
diff -u -r1.36 mmap.c
--- srclib/apr/mmap/unix/mmap.c 2001/08/02 04:26:53     1.36
+++ srclib/apr/mmap/unix/mmap.c 2001/11/14 07:30:05
@@ -163,6 +163,7 @@
     /* register the cleanup... */
     apr_pool_cleanup_register((*new)->cntxt, (void*)(*new), mmap_cleanup,
              apr_pool_cleanup_null);
+    (*new)->cleanup = mmap_cleanup;
     return APR_SUCCESS;
 }
 
Index: srclib/apr/mmap/win32/mmap.c
===================================================================
RCS file: /home/cvspublic/apr/mmap/win32/mmap.c,v
retrieving revision 1.6
diff -u -r1.6 mmap.c
--- srclib/apr/mmap/win32/mmap.c        2001/06/27 22:07:24     1.6
+++ srclib/apr/mmap/win32/mmap.c        2001/11/14 07:30:05
@@ -159,6 +159,7 @@
     /* register the cleanup... */
     apr_pool_cleanup_register((*new)->cntxt, (void*)(*new), mmap_cleanup,
                          apr_pool_cleanup_null);
+    (*new)->cleanup = mmap_cleanup;
     return APR_SUCCESS;
 }
 
Index: srclib/apr-util/buckets/apr_buckets_mmap.c
===================================================================
RCS file: /home/cvspublic/apr-util/buckets/apr_buckets_mmap.c,v
retrieving revision 1.43
diff -u -r1.43 apr_buckets_mmap.c
--- srclib/apr-util/buckets/apr_buckets_mmap.c  2001/09/22 22:36:07     1.43
+++ srclib/apr-util/buckets/apr_buckets_mmap.c  2001/11/14 07:30:05
@@ -129,6 +129,19 @@
         return APR_SUCCESS;
     }
 
+    if (apr_pool_is_ancestor(p, mm->cntxt)) {
+        /* Special case: moving this mmap into a parent of
+         * the current pool
+         */
+        m->mmap = (apr_mmap_t *)apr_palloc(p, sizeof(apr_mmap_t));
+        memcpy(m->mmap, mm, sizeof(apr_mmap_t));
+        m->mmap->cntxt = p;
+        apr_pool_cleanup_kill(mm->cntxt, mm, mm->cleanup);
+        apr_pool_cleanup_register(p, m->mmap, m->mmap->cleanup,
+                                  apr_pool_cleanup_null);
+        return APR_SUCCESS;
+    }
+
     ok = apr_mmap_offset(&addr, m->mmap, data->start);
     if (ok != APR_SUCCESS) {
         return ok;

Reply via email to