TS-2256: Mem stats info is bad when enable reclaimable-freelist 1) Rename InkFreeList->count to InkFreeList->used, which could make it more readable.
2) Fix mem stats in reclaimable freelist -- I misunderstood the meaning of InkFreelist->count before. 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/134b8a6f Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/134b8a6f Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/134b8a6f Branch: refs/heads/5.0.x Commit: 134b8a6f91fcea12f41f3459c4f7a652159099f3 Parents: 6aa87ff Author: Yunkai Zhang <[email protected]> Authored: Sun Sep 29 16:04:10 2013 +0800 Committer: Yunkai Zhang <[email protected]> Committed: Mon Sep 30 10:14:34 2013 +0800 ---------------------------------------------------------------------- CHANGES | 2 ++ lib/ts/ink_queue.cc | 18 +++++++++--------- lib/ts/ink_queue.h | 4 ++-- lib/ts/ink_queue_ext.cc | 15 +++++++-------- lib/ts/ink_queue_ext.h | 4 ++-- 5 files changed, 22 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/134b8a6f/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index b14b9c3..0a630b9 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ -*- coding: utf-8 -*- Changes with Apache Traffic Server 4.1.0 + *) [TS-2256] Mem stats info is bad when enable reclaimable-freelist. + *) [TS-2255] TS should not flood printing after log space reach the limit. *) [TS-2245] cancel the trigger of CacheVC in openWriteCloseDataDone. http://git-wip-us.apache.org/repos/asf/trafficserver/blob/134b8a6f/lib/ts/ink_queue.cc ---------------------------------------------------------------------- diff --git a/lib/ts/ink_queue.cc b/lib/ts/ink_queue.cc index 2bf1ee3..9b2f8ab 100644 --- a/lib/ts/ink_queue.cc +++ b/lib/ts/ink_queue.cc @@ -107,10 +107,10 @@ ink_freelist_init(InkFreeList **fl, const char *name, uint32_t type_size, f->type_size = type_size; SET_FREELIST_POINTER_VERSION(f->head, FROM_PTR(0), 0); - f->count = 0; + f->used = 0; f->allocated = 0; f->allocated_base = 0; - f->count_base = 0; + f->used_base = 0; *fl = f; #endif } @@ -195,7 +195,7 @@ ink_freelist_new(InkFreeList * f) #endif /* MEMPROTECT */ } - ink_atomic_increment((int *) &f->count, f->chunk_size); + ink_atomic_increment((int *) &f->used, f->chunk_size); ink_atomic_increment(&fastalloc_mem_in_use, (int64_t) f->chunk_size * f->type_size); } else { @@ -223,7 +223,7 @@ ink_freelist_new(InkFreeList * f) while (result == 0); ink_assert(!((uintptr_t)TO_PTR(FREELIST_POINTER(item))&(((uintptr_t)f->alignment)-1))); - ink_atomic_increment((int *) &f->count, 1); + ink_atomic_increment((int *) &f->used, 1); ink_atomic_increment(&fastalloc_mem_in_use, (int64_t) f->type_size); return TO_PTR(FREELIST_POINTER(item)); @@ -287,7 +287,7 @@ ink_freelist_free(InkFreeList * f, void *item) } while (result == 0); - ink_atomic_increment((int *) &f->count, -1); + ink_atomic_increment((int *) &f->used, -1); ink_atomic_increment(&fastalloc_mem_in_use, -(int64_t) f->type_size); #endif /* TS_USE_RECLAIMABLE_FREELIST */ #else @@ -306,7 +306,7 @@ ink_freelists_snap_baseline() fll = freelists; while (fll) { fll->fl->allocated_base = fll->fl->allocated; - fll->fl->count_base = fll->fl->count; + fll->fl->used_base = fll->fl->used; fll = fll->next; } #else // ! TS_USE_FREELIST @@ -332,8 +332,8 @@ ink_freelists_dump_baselinerel(FILE * f) if (a != 0) { fprintf(f, " %18" PRIu64 " | %18" PRIu64 " | %7u | %10u | memory/%s\n", (uint64_t)(fll->fl->allocated - fll->fl->allocated_base) * (uint64_t)fll->fl->type_size, - (uint64_t)(fll->fl->count - fll->fl->count_base) * (uint64_t)fll->fl->type_size, - fll->fl->count - fll->fl->count_base, fll->fl->type_size, fll->fl->name ? fll->fl->name : "<unknown>"); + (uint64_t)(fll->fl->used- fll->fl->used_base) * (uint64_t)fll->fl->type_size, + fll->fl->used - fll->fl->used_base, fll->fl->type_size, fll->fl->name ? fll->fl->name : "<unknown>"); } fll = fll->next; } @@ -357,7 +357,7 @@ ink_freelists_dump(FILE * f) while (fll) { fprintf(f, " %18" PRIu64 " | %18" PRIu64 " | %10u | memory/%s\n", (uint64_t)fll->fl->allocated * (uint64_t)fll->fl->type_size, - (uint64_t)fll->fl->count * (uint64_t)fll->fl->type_size, fll->fl->type_size, fll->fl->name ? fll->fl->name : "<unknown>"); + (uint64_t)fll->fl->used * (uint64_t)fll->fl->type_size, fll->fl->type_size, fll->fl->name ? fll->fl->name : "<unknown>"); fll = fll->next; } #else // ! TS_USE_FREELIST http://git-wip-us.apache.org/repos/asf/trafficserver/blob/134b8a6f/lib/ts/ink_queue.h ---------------------------------------------------------------------- diff --git a/lib/ts/ink_queue.h b/lib/ts/ink_queue.h index 6004575..41195c6 100644 --- a/lib/ts/ink_queue.h +++ b/lib/ts/ink_queue.h @@ -156,8 +156,8 @@ extern "C" { volatile head_p head; const char *name; - uint32_t type_size, chunk_size, count, allocated, alignment; - uint32_t allocated_base, count_base; + uint32_t type_size, chunk_size, used, allocated, alignment; + uint32_t allocated_base, used_base; }; inkcoreapi extern volatile int64_t fastalloc_mem_in_use; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/134b8a6f/lib/ts/ink_queue_ext.cc ---------------------------------------------------------------------- diff --git a/lib/ts/ink_queue_ext.cc b/lib/ts/ink_queue_ext.cc index fb7c657..aff1eb4 100644 --- a/lib/ts/ink_queue_ext.cc +++ b/lib/ts/ink_queue_ext.cc @@ -326,7 +326,7 @@ ink_chunk_create(InkFreeList *f, InkThreadCache *pCache) } *(void **)curr = NULL; - ink_atomic_increment(&f->count, chunk_size); + ink_atomic_increment(&f->allocated, chunk_size); ink_atomic_increment(&total_mem_in_byte, f->chunk_byte_size); pCache->free_chunk_list.push(pChunk); @@ -349,7 +349,7 @@ ink_chunk_delete(InkFreeList *f, InkThreadCache *pCache, InkChunkInfo *pChunk) ink_fatal(1, "Failed to munmap %u bytes, %s", f->chunk_byte_size, strerror(errno)); } - ink_atomic_increment((int *)&f->count, -f->chunk_size); + ink_atomic_increment((int *)&f->allocated, -f->chunk_size); /* * TODO: I had used ink_atomic_increment() here, but it would @@ -385,8 +385,6 @@ malloc_whole_chunk(InkFreeList *f, InkThreadCache *pCache, InkChunkInfo *pChunk) pChunk->inner_free_list = NULL; pCache->nr_total += chunk_size; - ink_atomic_increment(&f->allocated, chunk_size); - return item; } @@ -399,7 +397,6 @@ malloc_from_chunk(InkFreeList *f, InkThreadCache *pCache, InkChunkInfo *pChunk) pChunk->inner_free_list = *(void **)item; pChunk->allocated++; pCache->nr_total++; - ink_atomic_increment(&f->allocated, 1); } return item; @@ -412,7 +409,6 @@ free_to_chunk(InkFreeList *f, InkThreadCache *pCache, void *item) pChunk = get_chunk_info_addr(f, item); pChunk->allocated--; - ink_atomic_increment((int *)&f->allocated, -1); pCache->nr_total--; *(void **)item = pChunk->inner_free_list; @@ -537,10 +533,10 @@ reclaimable_freelist_init(InkFreeList **fl, const char *name, freelists = fll; f->name = name; - f->count = 0; + f->used = 0; f->allocated = 0; f->allocated_base = 0; - f->count_base = 0; + f->used_base = 0; memory_alignment_init(f, type_size, chunk_size, alignment); @@ -564,6 +560,8 @@ reclaimable_freelist_new(InkFreeList *f) InkChunkInfo *pChunk = NULL; InkThreadCache *pCache, *pNextCache; + ink_atomic_increment(&f->used, 1); + /* no thread cache, create it */ if (unlikely((pCache = ThreadCaches[f->thread_cache_idx]) == NULL)) { pCache = (InkThreadCache *) ats_calloc(1, sizeof(InkThreadCache)); @@ -683,5 +681,6 @@ reclaimable_freelist_free(InkFreeList *f, void *item) ink_atomic_increment(&pCache->nr_free, 1); ink_atomiclist_push(&pCache->outer_free_list, item); + ink_atomic_increment(&f->used, -1); } #endif http://git-wip-us.apache.org/repos/asf/trafficserver/blob/134b8a6f/lib/ts/ink_queue_ext.h ---------------------------------------------------------------------- diff --git a/lib/ts/ink_queue_ext.h b/lib/ts/ink_queue_ext.h index cfe91fa..3a80260 100644 --- a/lib/ts/ink_queue_ext.h +++ b/lib/ts/ink_queue_ext.h @@ -118,10 +118,10 @@ extern "C" /* chunk_addr = (uintptr_t)ptr & chunk_addr_mask */ uintptr_t chunk_addr_mask; - uint32_t count; + uint32_t used; uint32_t allocated; uint32_t allocated_base; - uint32_t count_base; + uint32_t used_base; uint32_t chunk_size_base; uint32_t nr_thread_cache;
