From d9486d154f69be2bbe44dbc8ea74efce1d0195ad Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 26 Jun 2013 20:18:34 +0000 Subject: alloc: cache-align all rbuf memory allocations 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. --- alloc.c | 27 ++++++--------------------- 1 file 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); -- cgit v1.2.3-24-ge0c7