Updated Branches: refs/heads/master 6dc186740 -> de4c7d233
TS-2352: refine THREAD_ALLOC feature 1) Move the definition of "ProxyAllocator xxxx" in EThread class to its parent Thread class, so that all threads can feel free to use THREAD_ALLOC feature. 2) Disable THREAD_ALLOC when enable reclaimable-freelist as reclaimable freelist has implemented thread-local pool. Signed-off-by: Yunkai Zhang <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/de4c7d23 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/de4c7d23 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/de4c7d23 Branch: refs/heads/master Commit: de4c7d233b55b2259e518895f121f68c58bc22ea Parents: 6dc1867 Author: Yunkai Zhang <[email protected]> Authored: Fri Nov 15 17:55:10 2013 +0800 Committer: Yunkai Zhang <[email protected]> Committed: Wed Nov 20 12:11:22 2013 +0800 ---------------------------------------------------------------------- CHANGES | 2 ++ iocore/cache/P_CacheInternal.h | 2 +- iocore/cache/RamCacheCLFUS.cc | 4 +-- iocore/cache/RamCacheLRU.cc | 2 +- iocore/eventsystem/I_EThread.h | 17 ---------- iocore/eventsystem/I_Event.h | 2 +- iocore/eventsystem/I_ProxyAllocator.h | 51 +++++++++++++++++++----------- iocore/eventsystem/I_Thread.h | 21 +++++++++++- iocore/eventsystem/P_IOBuffer.h | 20 ++++++------ iocore/eventsystem/ProxyAllocator.cc | 6 +++- proxy/hdrs/HdrHeap.cc | 4 +-- proxy/http/HttpClientSession.cc | 2 +- proxy/http/HttpServerSession.cc | 2 +- 13 files changed, 79 insertions(+), 56 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/de4c7d23/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index 0e634d6..d2fa182 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ -*- coding: utf-8 -*- Changes with Apache Traffic Server 4.2.0 + *) [TS-2352] refine THREAD_ALLOC feature. + *) [TS-2364] Introduce slice notation to field syntax in log format. *) [TS-2360] Fix usage of TSMimeHdrFieldValueStringGet() IDX in some plugins. http://git-wip-us.apache.org/repos/asf/trafficserver/blob/de4c7d23/iocore/cache/P_CacheInternal.h ---------------------------------------------------------------------- diff --git a/iocore/cache/P_CacheInternal.h b/iocore/cache/P_CacheInternal.h index 3c180ac..f330fbb 100644 --- a/iocore/cache/P_CacheInternal.h +++ b/iocore/cache/P_CacheInternal.h @@ -633,7 +633,7 @@ free_CacheVC(CacheVC *cont) #ifdef DEBUG SET_CONTINUATION_HANDLER(cont, &CacheVC::dead); #endif - THREAD_FREE_TO(cont, cacheVConnectionAllocator, this_ethread(), thread_freelist_size); + THREAD_FREE(cont, cacheVConnectionAllocator, this_thread()); return EVENT_DONE; } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/de4c7d23/iocore/cache/RamCacheCLFUS.cc ---------------------------------------------------------------------- diff --git a/iocore/cache/RamCacheCLFUS.cc b/iocore/cache/RamCacheCLFUS.cc index 5a0854a..80922b5 100644 --- a/iocore/cache/RamCacheCLFUS.cc +++ b/iocore/cache/RamCacheCLFUS.cc @@ -305,7 +305,7 @@ Lfree: uint32_t b = e->key.word(3) % nbuckets; bucket[b].remove(e); DDebug("ram_cache", "put %X %d %d size %d FREED", e->key.word(3), e->auxkey1, e->auxkey2, e->size); - THREAD_FREE(e, ramCacheCLFUSEntryAllocator, this_ethread()); + THREAD_FREE(e, ramCacheCLFUSEntryAllocator, this_thread()); } void @@ -348,7 +348,7 @@ RamCacheCLFUS::destroy(RamCacheCLFUSEntry *e) uint32_t b = e->key.word(3) % nbuckets; bucket[b].remove(e); DDebug("ram_cache", "put %X %d %d DESTROYED", e->key.word(3), e->auxkey1, e->auxkey2); - THREAD_FREE(e, ramCacheCLFUSEntryAllocator, this_ethread()); + THREAD_FREE(e, ramCacheCLFUSEntryAllocator, this_thread()); return ret; } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/de4c7d23/iocore/cache/RamCacheLRU.cc ---------------------------------------------------------------------- diff --git a/iocore/cache/RamCacheLRU.cc b/iocore/cache/RamCacheLRU.cc index 7562b12..ddf7620 100644 --- a/iocore/cache/RamCacheLRU.cc +++ b/iocore/cache/RamCacheLRU.cc @@ -131,7 +131,7 @@ RamCacheLRUEntry * RamCacheLRU::remove(RamCacheLRUEntry *e) { CACHE_SUM_DYN_STAT_THREAD(cache_ram_cache_bytes_stat, -e->data->block_size()); DDebug("ram_cache", "put %X %d %d FREED", e->key.word(3), e->auxkey1, e->auxkey2); e->data = NULL; - THREAD_FREE(e, ramCacheLRUEntryAllocator, this_ethread()); + THREAD_FREE(e, ramCacheLRUEntryAllocator, this_thread()); objects--; return ret; } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/de4c7d23/iocore/eventsystem/I_EThread.h ---------------------------------------------------------------------- diff --git a/iocore/eventsystem/I_EThread.h b/iocore/eventsystem/I_EThread.h index e5f1c56..c1e07ab 100644 --- a/iocore/eventsystem/I_EThread.h +++ b/iocore/eventsystem/I_EThread.h @@ -28,7 +28,6 @@ #include "libts.h" #include "I_Thread.h" #include "I_PriorityEventQueue.h" -#include "I_ProxyAllocator.h" #include "I_ProtectedQueue.h" // TODO: This would be much nicer to have "run-time" configurable (or something), @@ -264,22 +263,6 @@ public: Event *schedule_local(Event *e); InkRand generator; - ProxyAllocator eventAllocator; - ProxyAllocator netVCAllocator; - ProxyAllocator sslNetVCAllocator; - ProxyAllocator httpClientSessionAllocator; - ProxyAllocator httpServerSessionAllocator; - ProxyAllocator hdrHeapAllocator; - ProxyAllocator strHeapAllocator; - ProxyAllocator cacheVConnectionAllocator; - ProxyAllocator openDirEntryAllocator; - ProxyAllocator ramCacheCLFUSEntryAllocator; - ProxyAllocator ramCacheLRUEntryAllocator; - ProxyAllocator evacuationBlockAllocator; - ProxyAllocator ioDataAllocator; - ProxyAllocator ioAllocator; - ProxyAllocator ioBlockAllocator; - ProxyAllocator ioBufAllocator[DEFAULT_BUFFER_SIZES]; private: // prevent unauthorized copies (Not implemented) http://git-wip-us.apache.org/repos/asf/trafficserver/blob/de4c7d23/iocore/eventsystem/I_Event.h ---------------------------------------------------------------------- diff --git a/iocore/eventsystem/I_Event.h b/iocore/eventsystem/I_Event.h index 7a37ea0..797e313 100644 --- a/iocore/eventsystem/I_Event.h +++ b/iocore/eventsystem/I_Event.h @@ -280,6 +280,6 @@ extern ClassAllocator<Event> eventAllocator; if (_p->globally_allocated) \ ::_a.free(_p); \ else \ - THREAD_FREE_TO(_p, _a, _t, thread_freelist_size) + THREAD_FREE(_p, _a, _t) #endif /*_Event_h_*/ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/de4c7d23/iocore/eventsystem/I_ProxyAllocator.h ---------------------------------------------------------------------- diff --git a/iocore/eventsystem/I_ProxyAllocator.h b/iocore/eventsystem/I_ProxyAllocator.h index dc3b965..94415e0 100644 --- a/iocore/eventsystem/I_ProxyAllocator.h +++ b/iocore/eventsystem/I_ProxyAllocator.h @@ -47,6 +47,7 @@ struct ProxyAllocator template<class C> inline C * thread_alloc(ClassAllocator<C> &a, ProxyAllocator & l) { +#if TS_USE_FREELIST && !TS_USE_RECLAIMABLE_FREELIST if (l.freelist) { C *v = (C *) l.freelist; l.freelist = *(C **) l.freelist; @@ -54,11 +55,15 @@ template<class C> inline C * thread_alloc(ClassAllocator<C> &a, ProxyAllocator & *(void **) v = *(void **) &a.proto.typeObject; return v; } +#else + (void)l; +#endif return a.alloc(); } template<class C> inline C * thread_alloc_init(ClassAllocator<C> &a, ProxyAllocator & l) { +#if TS_USE_FREELIST && !TS_USE_RECLAIMABLE_FREELIST if (l.freelist) { C *v = (C *) l.freelist; l.freelist = *(C **) l.freelist; @@ -66,10 +71,25 @@ template<class C> inline C * thread_alloc_init(ClassAllocator<C> &a, ProxyAlloca memcpy((void *) v, (void *) &a.proto.typeObject, sizeof(C)); return v; } +#else + (void)l; +#endif return a.alloc(); } template<class C> inline void +thread_free(ClassAllocator<C> &a, C *p) +{ + a.free(p); +} + +static inline void +thread_free(Allocator &a, void *p) +{ + a.free_void(p); +} + +template<class C> inline void thread_freeup(ClassAllocator<C> &a, ProxyAllocator & l) { while (l.freelist) { @@ -84,26 +104,21 @@ thread_freeup(ClassAllocator<C> &a, ProxyAllocator & l) void* thread_alloc(Allocator &a, ProxyAllocator &l); void thread_freeup(Allocator &a, ProxyAllocator &l); -#if defined(TS_USE_FREELIST) - #define THREAD_ALLOC(_a, _t) thread_alloc(::_a, _t->_a) #define THREAD_ALLOC_INIT(_a, _t) thread_alloc_init(::_a, _t->_a) -#define THREAD_FREE_TO(_p, _a, _t, _m) do { \ - *(char **)_p = (char*)_t->_a.freelist; \ - _t->_a.freelist = _p; \ - _t->_a.allocated++; \ - if (_t->_a.allocated > _m) \ - thread_freeup(::_a, _t->_a); \ +#if TS_USE_FREELIST && !TS_USE_RECLAIMABLE_FREELIST +#define THREAD_FREE(_p, _a, _t) do { \ + *(char **)_p = (char*)_t->_a.freelist; \ + _t->_a.freelist = _p; \ + _t->_a.allocated++; \ + if (_t->_a.allocated > thread_freelist_size) \ + thread_freeup(::_a, _t->_a); \ } while (0) - -#else /* !defined(TS_USE_FREELIST) */ - -#define THREAD_ALLOC(_a, _t) ::_a.alloc() -#define THREAD_ALLOC_INIT(_a, _t) ::_a.alloc() -#define THREAD_FREE_TO(_p, _a, _t, _m) ::_a.free(_p) - -#endif /* defined(TS_USE_FREELIST */ - -#define THREAD_FREE(_p, _a, _t) THREAD_FREE_TO(_p, _a, _t, thread_freelist_size) +#else /* !TS_USE_FREELIST || TS_USE_RECLAIMABLE_FREELIST */ +#define THREAD_FREE(_p, _a, _t) do { \ + (void)_t; \ + thread_free(::_a, _p); \ +} while (0) +#endif #endif /* _ProxyAllocator_h_ */ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/de4c7d23/iocore/eventsystem/I_Thread.h ---------------------------------------------------------------------- diff --git a/iocore/eventsystem/I_Thread.h b/iocore/eventsystem/I_Thread.h index 3a40c52..4916e51 100644 --- a/iocore/eventsystem/I_Thread.h +++ b/iocore/eventsystem/I_Thread.h @@ -64,7 +64,8 @@ -- -include I_Event.h or P_Event.h #endif #include "libts.h" - class Thread; +#include "I_ProxyAllocator.h" +class Thread; class ProxyMutex; #define THREADAPI @@ -125,6 +126,24 @@ public: inkcoreapi static ink_thread_key thread_data_key; Ptr<ProxyMutex> mutex_ptr; + // For THREAD_ALLOC + ProxyAllocator eventAllocator; + ProxyAllocator netVCAllocator; + ProxyAllocator sslNetVCAllocator; + ProxyAllocator httpClientSessionAllocator; + ProxyAllocator httpServerSessionAllocator; + ProxyAllocator hdrHeapAllocator; + ProxyAllocator strHeapAllocator; + ProxyAllocator cacheVConnectionAllocator; + ProxyAllocator openDirEntryAllocator; + ProxyAllocator ramCacheCLFUSEntryAllocator; + ProxyAllocator ramCacheLRUEntryAllocator; + ProxyAllocator evacuationBlockAllocator; + ProxyAllocator ioDataAllocator; + ProxyAllocator ioAllocator; + ProxyAllocator ioBlockAllocator; + ProxyAllocator ioBufAllocator[DEFAULT_BUFFER_SIZES]; + private: // prevent unauthorized copies (Not implemented) Thread(const Thread &); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/de4c7d23/iocore/eventsystem/P_IOBuffer.h ---------------------------------------------------------------------- diff --git a/iocore/eventsystem/P_IOBuffer.h b/iocore/eventsystem/P_IOBuffer.h index 0842aff..c0ad45b 100644 --- a/iocore/eventsystem/P_IOBuffer.h +++ b/iocore/eventsystem/P_IOBuffer.h @@ -203,7 +203,7 @@ new_IOBufferData_internal( void *b, int64_t size, int64_t asize_index) { (void) size; - IOBufferData *d = THREAD_ALLOC(ioDataAllocator, this_ethread()); + IOBufferData *d = THREAD_ALLOC(ioDataAllocator, this_thread()); d->_size_index = asize_index; ink_assert(BUFFER_SIZE_INDEX_IS_CONSTANT(asize_index) || size <= d->block_size()); @@ -263,7 +263,7 @@ new_IOBufferData_internal( #endif int64_t size_index, AllocType type) { - IOBufferData *d = THREAD_ALLOC(ioDataAllocator, this_ethread()); + IOBufferData *d = THREAD_ALLOC(ioDataAllocator, this_thread()); #ifdef TRACK_BUFFER_USER d->_location = loc; #endif @@ -336,7 +336,7 @@ TS_INLINE void IOBufferData::free() { dealloc(); - THREAD_FREE(this, ioDataAllocator, this_ethread()); + THREAD_FREE(this, ioDataAllocator, this_thread()); } ////////////////////////////////////////////////////////////////// @@ -352,7 +352,7 @@ new_IOBufferBlock_internal( #endif ) { - IOBufferBlock *b = THREAD_ALLOC(ioBlockAllocator, this_ethread()); + IOBufferBlock *b = THREAD_ALLOC(ioBlockAllocator, this_thread()); #ifdef TRACK_BUFFER_USER b->_location = location; #endif @@ -366,7 +366,7 @@ new_IOBufferBlock_internal( #endif IOBufferData * d, int64_t len, int64_t offset) { - IOBufferBlock *b = THREAD_ALLOC(ioBlockAllocator, this_ethread()); + IOBufferBlock *b = THREAD_ALLOC(ioBlockAllocator, this_thread()); #ifdef TRACK_BUFFER_USER b->_location = location; #endif @@ -468,7 +468,7 @@ TS_INLINE void IOBufferBlock::free() { dealloc(); - THREAD_FREE(this, ioBlockAllocator, this_ethread()); + THREAD_FREE(this, ioBlockAllocator, this_thread()); } TS_INLINE void @@ -777,7 +777,7 @@ TS_INLINE MIOBuffer * new_MIOBuffer_internal( #endif int64_t size_index) { - MIOBuffer *b = THREAD_ALLOC(ioAllocator, this_ethread()); + MIOBuffer *b = THREAD_ALLOC(ioAllocator, this_thread()); #ifdef TRACK_BUFFER_USER b->_location = location; #endif @@ -790,7 +790,7 @@ free_MIOBuffer(MIOBuffer * mio) { mio->_writer = NULL; mio->dealloc_all_readers(); - THREAD_FREE(mio, ioAllocator, this_ethread()); + THREAD_FREE(mio, ioAllocator, this_thread()); } TS_INLINE MIOBuffer * new_empty_MIOBuffer_internal( @@ -799,7 +799,7 @@ TS_INLINE MIOBuffer * new_empty_MIOBuffer_internal( #endif int64_t size_index) { - MIOBuffer *b = THREAD_ALLOC(ioAllocator, this_ethread()); + MIOBuffer *b = THREAD_ALLOC(ioAllocator, this_thread()); b->size_index = size_index; #ifdef TRACK_BUFFER_USER b->_location = location; @@ -810,7 +810,7 @@ TS_INLINE MIOBuffer * new_empty_MIOBuffer_internal( TS_INLINE void free_empty_MIOBuffer(MIOBuffer * mio) { - THREAD_FREE(mio, ioAllocator, this_ethread()); + THREAD_FREE(mio, ioAllocator, this_thread()); } TS_INLINE IOBufferReader * http://git-wip-us.apache.org/repos/asf/trafficserver/blob/de4c7d23/iocore/eventsystem/ProxyAllocator.cc ---------------------------------------------------------------------- diff --git a/iocore/eventsystem/ProxyAllocator.cc b/iocore/eventsystem/ProxyAllocator.cc index 53a8d60..327b49b 100644 --- a/iocore/eventsystem/ProxyAllocator.cc +++ b/iocore/eventsystem/ProxyAllocator.cc @@ -27,12 +27,16 @@ int thread_freelist_size = 512; void* thread_alloc(Allocator &a, ProxyAllocator &l) { +#if TS_USE_FREELIST && !TS_USE_RECLAIMABLE_FREELIST if (l.freelist) { void *v = (void *) l.freelist; l.freelist = *(void **) l.freelist; l.allocated--; return v; } +#else + (void)l; +#endif return a.alloc_void(); } @@ -46,4 +50,4 @@ thread_freeup(Allocator &a, ProxyAllocator &l) a.free_void(v); // we could use a bulk free here } ink_assert(!l.allocated); - } +} http://git-wip-us.apache.org/repos/asf/trafficserver/blob/de4c7d23/proxy/hdrs/HdrHeap.cc ---------------------------------------------------------------------- diff --git a/proxy/hdrs/HdrHeap.cc b/proxy/hdrs/HdrHeap.cc index 6bcd06b..a70c0ab 100644 --- a/proxy/hdrs/HdrHeap.cc +++ b/proxy/hdrs/HdrHeap.cc @@ -181,7 +181,7 @@ HdrHeap::destroy() m_ronly_heap[i].m_ref_count_ptr = NULL; if (m_size == HDR_HEAP_DEFAULT_SIZE) { - THREAD_FREE(this, hdrHeapAllocator, this_ethread()); + THREAD_FREE(this, hdrHeapAllocator, this_thread()); } else { ats_free(this); } @@ -1105,7 +1105,7 @@ void HdrStrHeap::free() { if (m_heap_size == HDR_STR_HEAP_DEFAULT_SIZE) { - THREAD_FREE(this, strHeapAllocator, this_ethread()); + THREAD_FREE(this, strHeapAllocator, this_thread()); } else { ats_free(this); } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/de4c7d23/proxy/http/HttpClientSession.cc ---------------------------------------------------------------------- diff --git a/proxy/http/HttpClientSession.cc b/proxy/http/HttpClientSession.cc index c4d1965..5db6275 100644 --- a/proxy/http/HttpClientSession.cc +++ b/proxy/http/HttpClientSession.cc @@ -108,7 +108,7 @@ HttpClientSession::destroy() { this->cleanup(); if (proxy_allocated) - THREAD_FREE(this, httpClientSessionAllocator, this_ethread()); + THREAD_FREE(this, httpClientSessionAllocator, this_thread()); else httpClientSessionAllocator.free(this); } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/de4c7d23/proxy/http/HttpServerSession.cc ---------------------------------------------------------------------- diff --git a/proxy/http/HttpServerSession.cc b/proxy/http/HttpServerSession.cc index 7898c09..dd3de61 100644 --- a/proxy/http/HttpServerSession.cc +++ b/proxy/http/HttpServerSession.cc @@ -52,7 +52,7 @@ HttpServerSession::destroy() mutex.clear(); if (2 == share_session) - THREAD_FREE(this, httpServerSessionAllocator, this_ethread()); + THREAD_FREE(this, httpServerSessionAllocator, this_thread()); else httpServerSessionAllocator.free(this); }
