You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2012/04/25 19:32:28 UTC
git commit: TS-1150 Improve performance for the hdr_heap protection,
reducing the protection refcnt increments / decrements by 100x, give or take.
Updated Branches:
refs/heads/master 4a4c89388 -> 6a262b229
TS-1150 Improve performance for the hdr_heap protection, reducing the protection refcnt increments / decrements by 100x, give or take.
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/6a262b22
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/6a262b22
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/6a262b22
Branch: refs/heads/master
Commit: 6a262b229abc9f1dbe565179f9ece44e2789a1a3
Parents: 4a4c893
Author: Leif Hedstrom <le...@ogre.com>
Authored: Thu Mar 29 14:50:12 2012 -0600
Committer: Leif Hedstrom <zw...@apache.org>
Committed: Wed Apr 25 11:28:49 2012 -0600
----------------------------------------------------------------------
proxy/CoreUtils.cc | 1 -
proxy/hdrs/HdrHeap.cc | 20 ++--------------
proxy/hdrs/HdrHeap.h | 53 ++++++++++++++++++++++++++++---------------
proxy/hdrs/MIME.cc | 3 +-
4 files changed, 39 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/6a262b22/proxy/CoreUtils.cc
----------------------------------------------------------------------
diff --git a/proxy/CoreUtils.cc b/proxy/CoreUtils.cc
index 9c79af4..3b74d6f 100644
--- a/proxy/CoreUtils.cc
+++ b/proxy/CoreUtils.cc
@@ -151,7 +151,6 @@ FILE *fp;
memTable default_memTable = { 0, 0, 0 };
DynArray<struct memTable>arrayMem(&default_memTable, 0);
-const int HDR_HEAP_HDR_SIZE = ROUND(sizeof(HdrHeap), HDR_PTR_SIZE);
HTTPHdrImpl *global_http;
HttpSM *last_seen_http_sm = NULL;
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/6a262b22/proxy/hdrs/HdrHeap.cc
----------------------------------------------------------------------
diff --git a/proxy/hdrs/HdrHeap.cc b/proxy/hdrs/HdrHeap.cc
index 9392290..aced42d 100644
--- a/proxy/hdrs/HdrHeap.cc
+++ b/proxy/hdrs/HdrHeap.cc
@@ -36,9 +36,6 @@
#include "MIME.h"
#include "HTTP.h"
-#define HDR_MAX_ALLOC_SIZE (HDR_HEAP_DEFAULT_SIZE - sizeof(HdrHeap))
-#define HDR_HEAP_HDR_SIZE ROUND(sizeof(HdrHeap), HDR_PTR_SIZE)
-#define STR_HEAP_HDR_SIZE sizeof(HdrStrHeap)
#define MAX_LOST_STR_SPACE 1024
Allocator hdrHeapAllocator("hdrHeap", HDR_HEAP_DEFAULT_SIZE);
@@ -303,19 +300,8 @@ FAILED:
char *
HdrHeap::expand_str(const char *old_str, int old_len, int new_len)
{
- char *rw_ptr = (char *) m_read_write_heap.m_ptr;
-
- if (rw_ptr) {
- // First check to see the old string is in this read-write string
- // heap
- if (old_str >= rw_ptr + STR_HEAP_HDR_SIZE && old_str < rw_ptr + m_read_write_heap->m_heap_size) {
- // We're in the heap. Try to grow the string
- char *r = m_read_write_heap->expand((char *) old_str, old_len, new_len);
- if (r) {
- return r;
- }
- }
- }
+ if (m_read_write_heap && m_read_write_heap->contains(old_str))
+ return m_read_write_heap->expand((char *)old_str, old_len, new_len);
return NULL;
}
@@ -328,7 +314,7 @@ HdrHeap::expand_str(const char *old_str, int old_len, int new_len)
char *
HdrHeap::duplicate_str(const char *str, int nbytes)
{
- ProtectHeaps protect(this); // Don't let the source get de-allocated.
+ HeapGuard guard(this, str); // Don't let the source get de-allocated.
char *new_str = allocate_str(nbytes);
memcpy(new_str, str, nbytes);
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/6a262b22/proxy/hdrs/HdrHeap.h
----------------------------------------------------------------------
diff --git a/proxy/hdrs/HdrHeap.h b/proxy/hdrs/HdrHeap.h
index 4d76f6b..90d1bb0 100644
--- a/proxy/hdrs/HdrHeap.h
+++ b/proxy/hdrs/HdrHeap.h
@@ -58,6 +58,10 @@
#define HDR_HEAP_DEFAULT_SIZE 2048
#define HDR_STR_HEAP_DEFAULT_SIZE 2048
+#define HDR_MAX_ALLOC_SIZE (HDR_HEAP_DEFAULT_SIZE - sizeof(HdrHeap))
+#define HDR_HEAP_HDR_SIZE ROUND(sizeof(HdrHeap), HDR_PTR_SIZE)
+#define STR_HEAP_HDR_SIZE sizeof(HdrStrHeap)
+
enum
{
HDR_HEAP_OBJ_EMPTY = 0,
@@ -143,6 +147,11 @@ struct StrHeapDesc
char *m_heap_start;
int32_t m_heap_len;
bool m_locked;
+
+ bool contains(const char *str) const
+ {
+ return (str >= m_heap_start && str < (m_heap_start + m_heap_len));
+ }
};
@@ -161,6 +170,11 @@ public:
uint32_t m_heap_size;
char *m_free_start;
uint32_t m_free_size;
+
+ bool contains(const char *str) const
+ {
+ return (str >= ((const char*)this + STR_HEAP_HDR_SIZE) && str < ((const char*)this + m_heap_size));
+ }
};
class CoreUtils;
@@ -252,31 +266,32 @@ public:
int attach_str_heap(char *h_start, int h_len, RefCountObj * h_ref_obj, int *index);
/** Struct to prevent garbage collection on heaps.
- This bumps the reference count to the heaps while the
- instance of this class exists. When it goes out of scope
- the references are dropped. This is useful inside a method or
- block to keep all the heap data around until leaving the scope.
+ This bumps the reference count to the heap containing the pointer
+ while the instance of this class exists. When it goes out of scope
+ the reference is dropped. This is useful inside a method or block
+ to keep the required heap data around until leaving the scope.
*/
- struct ProtectHeaps {
+ struct HeapGuard {
/// Construct the protection.
- ProtectHeaps(HdrHeap* heap)
- : m_read_write_heap(heap->m_read_write_heap)
+ HeapGuard(HdrHeap* heap, const char *str)
{
- for (int i=0; i < HDR_BUF_RONLY_HEAPS; ++i)
- m_ronly_heap[i] = heap->m_ronly_heap[i].m_ref_count_ptr;
+ if (heap->m_read_write_heap && heap->m_read_write_heap->contains(str)) {
+ m_ptr = heap->m_read_write_heap;
+ } else {
+ for (int i=0; i < HDR_BUF_RONLY_HEAPS; ++i) {
+ if (heap->m_ronly_heap[i].contains(str)) {
+ m_ptr = heap->m_ronly_heap[i].m_ref_count_ptr;
+ break;
+ }
+ }
+ }
}
- /// Drop the protection.
- ~ProtectHeaps()
- {
- // The default destructor takes care of the rw-heap
- for (int i=0; i < HDR_BUF_RONLY_HEAPS; ++i)
- m_ronly_heap[i] = NULL;
- }
+ // There's no need to have a destructor here, the default dtor will take care of
+ // releaseing the (potentially) locked heap.
- Ptr<HdrStrHeap> m_read_write_heap; ///< Reference to RW heap.
- /// References to string heaps.
- Ptr<RefCountObj> m_ronly_heap[HDR_BUF_RONLY_HEAPS];
+ /// The heap we protect (if any)
+ Ptr<RefCountObj> m_ptr;
};
// String Heap access
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/6a262b22/proxy/hdrs/MIME.cc
----------------------------------------------------------------------
diff --git a/proxy/hdrs/MIME.cc b/proxy/hdrs/MIME.cc
index c82da56..b175ff6 100644
--- a/proxy/hdrs/MIME.cc
+++ b/proxy/hdrs/MIME.cc
@@ -1763,7 +1763,8 @@ mime_field_value_str_from_strlist(HdrHeap *heap, int *new_str_len_return, StrLis
Str *cell;
char *new_value, *dest;
int i, new_value_len;
- HdrHeap::ProtectHeaps protect(heap);
+ // This works, because all strings are from the same heap when it is "split" into the list.
+ HdrHeap::HeapGuard guard(heap, list->head->str);
new_value_len = 0;