TS-1921: Fix reclaimable freelist stuck in infinite loop The initialization order of static variables is fragile, so let's use ats_pagesize() to replace the page_size static variable in reclaimable freelist, and do some optimization for ats_pagesize().
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/1ca7c1a5 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/1ca7c1a5 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/1ca7c1a5 Branch: refs/heads/3.3.x Commit: 1ca7c1a5e1a51f81d764cd92e86771d9b85c4efb Parents: f9cbfaf Author: Yunkai Zhang <[email protected]> Authored: Thu May 30 13:10:07 2013 +0800 Committer: James Peach <[email protected]> Committed: Thu May 30 10:59:38 2013 -0700 ---------------------------------------------------------------------- CHANGES | 3 +++ lib/ts/ink_memory.h | 16 ++++++++++++---- lib/ts/ink_queue_ext.cc | 19 +++++++++---------- 3 files changed, 24 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1ca7c1a5/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index a7cc143..6301906 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,9 @@ Changes with Apache Traffic Server 3.3.3 + *) [TS-1921] Fix reclaimable freelist getting stuck in infinite loop. + Author: Yunkai Zhang <[email protected]> + *) [TS-1824] TSHttpTxnPushedRespHdrBytesGet() takes an int argument in the implementation, whereas the prototype does not have this. http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1ca7c1a5/lib/ts/ink_memory.h ---------------------------------------------------------------------- diff --git a/lib/ts/ink_memory.h b/lib/ts/ink_memory.h index 89462de..f62a7eb 100644 --- a/lib/ts/ink_memory.h +++ b/lib/ts/ink_memory.h @@ -88,14 +88,22 @@ extern "C" { int ats_madvise(caddr_t addr, size_t len, int flags); int ats_mlock(caddr_t addr, size_t len); - static inline size_t ats_pagesize(void) { + static inline size_t ats_pagesize(void) + { + static size_t page_size; + + if (page_size) + return page_size; + #if defined(HAVE_SYSCONF) && defined(_SC_PAGESIZE) - return (size_t)sysconf(_SC_PAGESIZE); + page_size = (size_t)sysconf(_SC_PAGESIZE); #elif defined(HAVE_GETPAGESIZE) - return (size_t)getpagesize() + page_size = (size_t)getpagesize() #else - return (size_t)8192; + page_size = (size_t)8192; #endif + + return page_size; } #define ats_strdup(p) _xstrdup((p), -1, NULL) http://git-wip-us.apache.org/repos/asf/trafficserver/blob/1ca7c1a5/lib/ts/ink_queue_ext.cc ---------------------------------------------------------------------- diff --git a/lib/ts/ink_queue_ext.cc b/lib/ts/ink_queue_ext.cc index d3f9c41..f9e3f60 100644 --- a/lib/ts/ink_queue_ext.cc +++ b/lib/ts/ink_queue_ext.cc @@ -64,7 +64,6 @@ int64_t cfg_enable_reclaim = 0; */ int64_t cfg_debug_filter; -static const uint32_t page_size = ats_pagesize(); static uint32_t nr_freelist; static uint64_t total_mem_in_byte; static __thread InkThreadCache *ThreadCaches[MAX_NUM_FREELIST]; @@ -75,7 +74,7 @@ static inline pthread_t thread_id(void) return tid?tid:(tid = pthread_self()); } -#define MAX_CHUNK_BYTE_SIZE (page_size << 8) +#define MAX_CHUNK_BYTE_SIZE (ats_pagesize() << 8) /* * For debug @@ -123,17 +122,17 @@ memory_alignment_init(InkFreeList *f, uint32_t type_size, uint32_t chunk_size, * alignment = (2^N * page_size), * alignment should not larger than MAX_CHUNK_BYTE_SIZE */ - alignment = page_size; - chunk_byte_size = ROUND(type_size + sizeof(InkChunkInfo), page_size); + alignment = ats_pagesize(); + chunk_byte_size = ROUND(type_size + sizeof(InkChunkInfo), ats_pagesize()); if (chunk_byte_size <= MAX_CHUNK_BYTE_SIZE) { chunk_byte_size = ROUND(type_size * f->chunk_size_base - + sizeof(InkChunkInfo), page_size); + + sizeof(InkChunkInfo), ats_pagesize()); if (chunk_byte_size > MAX_CHUNK_BYTE_SIZE) { chunk_size = (MAX_CHUNK_BYTE_SIZE - sizeof(InkChunkInfo)) / type_size; chunk_byte_size = ROUND(type_size * chunk_size + sizeof(InkChunkInfo), - page_size); + ats_pagesize()); } else chunk_size = (chunk_byte_size - sizeof(InkChunkInfo)) / type_size; @@ -146,7 +145,7 @@ memory_alignment_init(InkFreeList *f, uint32_t type_size, uint32_t chunk_size, } if (user_alignment > alignment) { - alignment = page_size; + alignment = ats_pagesize(); while (alignment < user_alignment) alignment <<= 1; } @@ -172,11 +171,11 @@ mmap_align(size_t size, size_t alignment) { uintptr_t ptr; size_t adjust, extra = 0; - ink_assert(size % page_size == 0); + ink_assert(size % ats_pagesize() == 0); /* ask for extra memory if alignment > page_size */ - if (alignment > page_size) { - extra = alignment - page_size; + if (alignment > ats_pagesize()) { + extra = alignment - ats_pagesize(); } void* result = mmap(NULL, size + extra, PROT_READ|PROT_WRITE,
