about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-06-26 20:18:34 +0000
committerEric Wong <normalperson@yhbt.net>2013-07-10 00:55:52 +0000
commitd9486d154f69be2bbe44dbc8ea74efce1d0195ad (patch)
tree0a1b3c9e490575900e678307f9223ada09f32cd7
parentbb27afc702459d683a6b6ca5822b746142047acc (diff)
downloadcmogstored-d9486d154f69be2bbe44dbc8ea74efce1d0195ad.tar.gz
Some setups use clients which pass large headers (User-Agent, or
even cookies(!)) to cmogstored, so large rbufs may be used often
and repeatedly in those cases.

We limit rbuf sizes to 64K anyways, so keeping "larger" buffers
around should not be much of an issue for modern systems.

This prepares us for reusing/recycling large rbufs as TLS buffers.
-rw-r--r--alloc.c27
1 files changed, 6 insertions, 21 deletions
diff --git a/alloc.c b/alloc.c
index a51407f..bddad4d 100644
--- a/alloc.c
+++ b/alloc.c
@@ -92,15 +92,7 @@ struct mog_rbuf *mog_rbuf_new(size_t size)
 
         assert(size > 0 && "tried to allocate a zero-byte mog_rbuf");
 
-        /*
-         * only cache-align for common allocation sizes, for larger
-         * allocations it'll lead to fragmentation and we'll only
-         * end up touching later sections of memory...
-         */
-        if (size == MOG_RBUF_BASE_SIZE)
-                rbuf = mog_cachealign(bytes);
-        else
-                rbuf = xmalloc(bytes);
+        rbuf = mog_cachealign(bytes);
         rbuf->rcapa = size;
         /*
          * do not initialize rsize here, we only need rsize when we detach
@@ -146,7 +138,7 @@ struct mog_rbuf *mog_rbuf_detach(struct mog_rbuf *rbuf)
 }
 
 /*
- * Behaves similarly to realloc(), but is safe for posix_memalign()
+ * Behaves similarly to realloc(), but uses posix_memalign()
  * Returns a detached rbuf with the contents of +cur+
  * (which may be cur itself)
  * Releases memory and returns NULL if rbuf is too big.
@@ -166,17 +158,10 @@ struct mog_rbuf *mog_rbuf_grow(struct mog_rbuf *cur)
         if (new_size > MOG_RBUF_MAX_SIZE)
                 new_size = MOG_RBUF_MAX_SIZE;
         if (cur->rcapa < new_size) {
-                if (cur->rcapa == MOG_RBUF_BASE_SIZE) {
-                        /* can't safely realloc posix_memalign'ed memory */
-                        ret = mog_rbuf_new(new_size);
-                        memcpy(ret->rptr, cur->rptr, cur->rsize);
-                        if (cur != tls_rbuf)
-                                mog_rbuf_free(cur);
-                } else {
-                        assert(cur != tls_rbuf && "bug rbuf found in TLS");
-                        ret = xrealloc(cur, new_size + sizeof(struct mog_rbuf));
-                        ret->rcapa = new_size;
-                }
+                ret = mog_rbuf_new(new_size);
+                memcpy(ret->rptr, cur->rptr, cur->rsize);
+                if (cur != tls_rbuf)
+                        mog_rbuf_free(cur);
         } else {
                 /* this may not even happen, just in case: */
                 ret = mog_rbuf_detach(cur);