trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sudhe...@apache.org
Subject trafficserver git commit: [TS-1175]: Replace LogBuffer's new/delete buffer alloc with ioBufAllocator
Date Fri, 07 Nov 2014 15:15:36 GMT
Repository: trafficserver
Updated Branches:
  refs/heads/master 20c8ba6cb -> cf0e37b7f


[TS-1175]: Replace LogBuffer's new/delete buffer alloc with ioBufAllocator


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/cf0e37b7
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/cf0e37b7
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/cf0e37b7

Branch: refs/heads/master
Commit: cf0e37b7fd35995e2324c025a6b3c5f44f5f5918
Parents: 20c8ba6
Author: Sudheer Vinukonda <sudheerv@yahoo-inc.com>
Authored: Fri Nov 7 15:13:54 2014 +0000
Committer: Sudheer Vinukonda <sudheerv@yahoo-inc.com>
Committed: Fri Nov 7 15:13:54 2014 +0000

----------------------------------------------------------------------
 proxy/logging/LogBuffer.cc          | 35 ++++++++++++++++++++++++--------
 proxy/logging/LogBuffer.h           |  2 ++
 proxy/logging/LogCollationHostSM.cc | 28 ++++++++++++++++++++-----
 proxy/logging/LogCollationHostSM.h  |  2 ++
 4 files changed, 54 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/cf0e37b7/proxy/logging/LogBuffer.cc
----------------------------------------------------------------------
diff --git a/proxy/logging/LogBuffer.cc b/proxy/logging/LogBuffer.cc
index 349aa77..d3d9d01 100644
--- a/proxy/logging/LogBuffer.cc
+++ b/proxy/logging/LogBuffer.cc
@@ -134,7 +134,14 @@ LogBuffer::LogBuffer(LogObject * owner, size_t size, size_t buf_align,
size_t wr
 
   // create the buffer
   //
-  m_unaligned_buffer = new char [size + buf_align];
+  int64_t alloc_size = size + buf_align; 
+  if (alloc_size <= max_iobuffer_size) {
+    m_buffer_fast_allocator_size = buffer_size_to_index(alloc_size);
+    m_unaligned_buffer = (char *) ioBufAllocator[m_buffer_fast_allocator_size].alloc_void();
+  } else {
+    m_buffer_fast_allocator_size = -1;
+    m_unaligned_buffer = (char *)ats_malloc(alloc_size);
+  }
   m_buffer = (char *)align_pointer_forward(m_unaligned_buffer, buf_align);
 
   // add the header
@@ -157,7 +164,7 @@ LogBuffer::LogBuffer(LogObject * owner, LogBufferHeader * header):
   m_buffer((char *) header),
   m_size(0),
   m_buf_align(LB_DEFAULT_ALIGN),
-  m_write_align(INK_MIN_ALIGN), m_expiration_time(0), m_owner(owner), m_header(header),
+  m_write_align(INK_MIN_ALIGN), m_buffer_fast_allocator_size(-1), m_expiration_time(0), m_owner(owner),
m_header(header),
   m_references(0)
 {
   // This constructor does not allocate a buffer because it gets it as
@@ -173,17 +180,29 @@ LogBuffer::LogBuffer(LogObject * owner, LogBufferHeader * header):
         this_ethread(), m_id, m_owner->get_base_filename(), m_buffer);
 }
 
-LogBuffer::~LogBuffer()
+void
+LogBuffer::freeLogBuffer()
 {
-  Debug("log-logbuffer", "[%p] Deleting buffer %u at address %p",
-        this_ethread(), m_id, m_unaligned_buffer ? m_unaligned_buffer : m_buffer);
-
+  char *log_buffer = NULL;
   if (m_unaligned_buffer) {
-    delete [] m_unaligned_buffer;
+    log_buffer = m_unaligned_buffer;
   } else {
-    delete [] m_buffer;
+    log_buffer = m_buffer;
   }
+  if (log_buffer) {
+    Debug("log-logbuffer", "[%p] Deleting buffer %u at address %p",
+          this_ethread(), m_id, log_buffer);
+    if (m_buffer_fast_allocator_size >= 0) {
+      ioBufAllocator[m_buffer_fast_allocator_size].free_void(log_buffer);
+    } else{
+      ats_free(log_buffer);
+    }
+  }
+}
 
+LogBuffer::~LogBuffer()
+{
+  freeLogBuffer();
   m_buffer = 0;
   m_unaligned_buffer = 0;
 }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/cf0e37b7/proxy/logging/LogBuffer.h
----------------------------------------------------------------------
diff --git a/proxy/logging/LogBuffer.h b/proxy/logging/LogBuffer.h
index 20ab601..648ca08 100644
--- a/proxy/logging/LogBuffer.h
+++ b/proxy/logging/LogBuffer.h
@@ -207,6 +207,7 @@ private:
   size_t m_size;                // the buffer size
   size_t m_buf_align;           // the buffer alignment
   size_t m_write_align;         // the write alignment mask
+  int    m_buffer_fast_allocator_size; // indicates whether the logbuffer is allocated from
ioBuf
 
   long m_expiration_time;       // buffer expiration time
 
@@ -222,6 +223,7 @@ private:
   // private functions
   size_t _add_buffer_header();
   unsigned add_header_str(const char *str, char *buf_ptr, unsigned buf_len);
+  void freeLogBuffer();
 
   // -- member functions that are not allowed --
   LogBuffer();

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/cf0e37b7/proxy/logging/LogCollationHostSM.cc
----------------------------------------------------------------------
diff --git a/proxy/logging/LogCollationHostSM.cc b/proxy/logging/LogCollationHostSM.cc
index 498018c..91ffe5c 100644
--- a/proxy/logging/LogCollationHostSM.cc
+++ b/proxy/logging/LogCollationHostSM.cc
@@ -67,7 +67,7 @@ m_client_vio(NULL),
 m_client_buffer(NULL),
 m_client_reader(NULL),
 m_pending_event(NULL),
-m_read_buffer(NULL), m_read_bytes_wanted(0), m_read_bytes_received(0), m_client_ip(0), m_client_port(0),
m_id(ID++)
+m_read_buffer(NULL), m_read_bytes_wanted(0), m_read_bytes_received(0), m_read_buffer_fast_allocator_size(-1),
m_client_ip(0), m_client_port(0), m_id(ID++)
 {
 
   Debug("log-coll", "[%d]host::constructor", m_id);
@@ -87,6 +87,19 @@ m_read_buffer(NULL), m_read_bytes_wanted(0), m_read_bytes_received(0),
m_client_
 
 }
 
+void
+LogCollationHostSM::freeReadBuffer()
+{
+  if (m_read_buffer) {
+    if (m_read_buffer_fast_allocator_size >= 0) {
+      ioBufAllocator[m_read_buffer_fast_allocator_size].free_void(m_read_buffer);
+    } else{
+      ats_free(m_read_buffer);
+    }
+    m_read_buffer = 0;
+  }
+}
+
 //-------------------------------------------------------------------------
 //-------------------------------------------------------------------------
 //
@@ -171,8 +184,7 @@ LogCollationHostSM::host_auth(int event, void * /* data ATS_UNUSED */)
       ink_assert(m_read_buffer != NULL);
       int diff = strncmp(m_read_buffer, Log::config->collation_secret,
                          m_read_bytes_received);
-      delete[]m_read_buffer;
-      m_read_buffer = 0;
+      freeReadBuffer();
       if (!diff) {
         Debug("log-coll", "[%d]host::host_auth - authenticated!", m_id);
         return host_recv(LOG_COLL_EVENT_SWITCH, NULL);
@@ -304,7 +316,7 @@ LogCollationHostSM::host_recv(int event, void * /* data ATS_UNUSED */)
       if (version != LOG_SEGMENT_VERSION) {
         Note("[log-coll] invalid LogBuffer received; invalid version - "
              "buffer = %u, current = %u", version, LOG_SEGMENT_VERSION);
-        delete[]m_read_buffer;
+        freeReadBuffer();
 
       } else {
         log_object = Log::match_logobject(log_buffer_header);
@@ -455,7 +467,13 @@ LogCollationHostSM::read_body(int event, VIO * vio)
     m_read_bytes_wanted = m_net_msg_header.msg_bytes;
     ink_assert(m_read_bytes_wanted > 0);
     m_read_bytes_received = 0;
-    m_read_buffer = new char[m_read_bytes_wanted];
+    if (m_read_bytes_wanted <= max_iobuffer_size) {
+      m_read_buffer_fast_allocator_size = buffer_size_to_index(m_read_bytes_wanted);
+      m_read_buffer = (char *) ioBufAllocator[m_read_buffer_fast_allocator_size].alloc_void();
+    } else {
+      m_read_buffer_fast_allocator_size = -1; 
+      m_read_buffer = (char *)ats_malloc(m_read_bytes_wanted);
+    }
     ink_assert(m_read_buffer != NULL);
     ink_assert(m_client_vc != NULL);
     Debug("log-coll", "[%d]host:read_body - do_io_read(%" PRId64")", m_id, m_read_bytes_wanted);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/cf0e37b7/proxy/logging/LogCollationHostSM.h
----------------------------------------------------------------------
diff --git a/proxy/logging/LogCollationHostSM.h b/proxy/logging/LogCollationHostSM.h
index e739ec4..31b0e67 100644
--- a/proxy/logging/LogCollationHostSM.h
+++ b/proxy/logging/LogCollationHostSM.h
@@ -84,6 +84,7 @@ private:
   int read_body(int event, VIO * vio);
   int read_done(int event, void *data);
   int read_start();
+  void freeReadBuffer();
   ReadState m_read_state;
 
   // helper for read states
@@ -101,6 +102,7 @@ private:
   char *m_read_buffer;
   int64_t m_read_bytes_wanted;
   int64_t m_read_bytes_received;
+  int64_t m_read_buffer_fast_allocator_size;
 
   // client info
   int m_client_ip;


Mime
View raw message