httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r774036 - /httpd/httpd/trunk/modules/mem/mod_sharedmem.c
Date Tue, 12 May 2009 19:15:09 GMT
Author: jim
Date: Tue May 12 19:15:08 2009
New Revision: 774036

URL: http://svn.apache.org/viewvc?rev=774036&view=rev
Log:
Optimization... for large slotmems, it would be useful to know
which ones are actually "in use"... So flag this. Need a way
to de-allocate a slot for completeness I think, but am having
a hard time coming up with a use case...


Modified:
    httpd/httpd/trunk/modules/mem/mod_sharedmem.c

Modified: httpd/httpd/trunk/modules/mem/mod_sharedmem.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/mem/mod_sharedmem.c?rev=774036&r1=774035&r2=774036&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/mem/mod_sharedmem.c (original)
+++ httpd/httpd/trunk/modules/mem/mod_sharedmem.c Tue May 12 19:15:08 2009
@@ -48,6 +48,7 @@
     apr_pool_t           *gpool;      /* per segment global pool */
     apr_global_mutex_t   *smutex;     /* mutex */
     struct ap_slotmem_t  *next;       /* location of next allocated segment */
+    char                 *inuse;      /* is-use flag table*/
 };
 
 
@@ -57,6 +58,11 @@
     unsigned int item_num;
 };
 
+/*
+ * Memory layout:
+ *     sharedslotdesc | slots | isuse array
+ */
+
 /* global pool and list of slotmem we are handling */
 static struct ap_slotmem_t *globallistmem = NULL;
 static apr_pool_t *gpool = NULL;
@@ -152,16 +158,16 @@
     if (rv != APR_SUCCESS) {
         return;
     }
-    nbytes = slotmem->size * slotmem->num;
+    nbytes = (slotmem->size * slotmem->num) + (slotmem->num + sizeof(char));
     apr_file_write(fp, slotmem->base, &nbytes);
     apr_file_close(fp);
 }
 
-static void restore_slotmem(void *ptr, const char *name, apr_size_t item_size, unsigned int
item_num, apr_pool_t *pool)
+static void restore_slotmem(void *ptr, const char *name, apr_size_t size, apr_pool_t *pool)
 {
     const char *storename;
     apr_file_t *fp;
-    apr_size_t nbytes = item_size * item_num;
+    apr_size_t nbytes = size;
     apr_status_t rv;
 
     storename = store_filename(pool, name);
@@ -205,16 +211,20 @@
 {
     unsigned int i;
     void *ptr;
+    char *inuse;
 
     if (!mem) {
         return APR_ENOSHMAVAIL;
     }
 
     ptr = mem->base;
+    inuse = ptr + (mem->size * mem->num);
     SLOTMEM_LOCK(mem->smutex);
-    for (i = 0; i < mem->num; i++) {
-        ptr = ptr + mem->size;
-        func((void *) ptr, data, pool);
+    for (i = 0; i < mem->num; i++, inuse++) {
+        if (*inuse) {
+            func((void *) ptr, data, pool);
+        }
+        ptr += mem->size;
     }
     SLOTMEM_UNLOCK(mem->smutex);
     return APR_SUCCESS;
@@ -229,6 +239,8 @@
     ap_slotmem_t *next = globallistmem;
     const char *fname;
     apr_shm_t *shm;
+    apr_size_t basesize = (item_size * item_num);
+    apr_size_t size = sizeof(struct sharedslotdesc) + (item_num * sizeof(char)) + basesize;
     apr_status_t rv;
 
     if (gpool == NULL)
@@ -269,7 +281,7 @@
     }
     if (rv == APR_SUCCESS) {
         /* check size */
-        if (apr_shm_size_get(shm) != item_size * item_num + sizeof(struct sharedslotdesc))
{
+        if (apr_shm_size_get(shm) != size) {
             apr_shm_detach(shm);
             return APR_EINVAL;
         }
@@ -282,13 +294,14 @@
         ptr = ptr + sizeof(desc);
     }
     else {
+        apr_size_t dsize = size - sizeof(struct sharedslotdesc);
         SLOTMEM_LOCK(smutex);
         if (name && name[0] != ':') {
             apr_shm_remove(fname, gpool);
-            rv = apr_shm_create(&shm, item_size * item_num + sizeof(struct sharedslotdesc),
fname, gpool);
+            rv = apr_shm_create(&shm, size, fname, gpool);
         }
         else {
-            rv = apr_shm_create(&shm, item_size * item_num + sizeof(struct sharedslotdesc),
NULL, gpool);
+            rv = apr_shm_create(&shm, size, NULL, gpool);
         }
         SLOTMEM_UNLOCK(smutex);
         if (rv != APR_SUCCESS) {
@@ -308,9 +321,9 @@
         desc.item_num = item_num;
         memcpy(ptr, &desc, sizeof(desc));
         ptr = ptr + sizeof(desc);
-        memset(ptr, 0, item_size * item_num);
+        memset(ptr, 0, dsize);
         if (type == SLOTMEM_PERSIST)
-            restore_slotmem(ptr, fname, item_size, item_num, pool);
+            restore_slotmem(ptr, fname, dsize, pool);
     }
 
     /* For the chained slotmem stuff */
@@ -323,6 +336,7 @@
     res->gpool = gpool;
     res->smutex = smutex;
     res->next = NULL;
+    res->inuse = ptr + basesize;
     if (globallistmem == NULL) {
         globallistmem = res;
     }
@@ -396,6 +410,7 @@
     res->num = desc.item_num;
     res->gpool = gpool;
     res->smutex = smutex;
+    res->inuse = ptr + (desc.item_size * desc.item_num);
     res->next = NULL;
     if (globallistmem == NULL) {
         globallistmem = res;
@@ -448,6 +463,7 @@
 {
 
     void *ptr;
+    char *inuse;
     apr_status_t ret;
 
     ret = slotmem_mem(slot, id, &ptr);
@@ -455,6 +471,9 @@
         return ret;
     }
     memcpy(ptr, src, src_len); /* bounds check? */
+    /* We know the id fit it */
+    inuse = (slot->base + (slot->size * slot->num);
+    inuse[id] = 1;
     return APR_SUCCESS;
 }
 



Mime
View raw message