 Chromium Code Reviews
 Chromium Code Reviews Issue 7671034:
  doubly-linked free-lists for thread caches and page heaps  (Closed) 
  Base URL: http://git.chromium.org/git/chromium.git@trunk
    
  
    Issue 7671034:
  doubly-linked free-lists for thread caches and page heaps  (Closed) 
  Base URL: http://git.chromium.org/git/chromium.git@trunk| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2005, Google Inc. | 1 // Copyright (c) 2011, Google Inc. | 
| 2 // All rights reserved. | 2 // All rights reserved. | 
| 3 // | 3 // | 
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without | 
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are | 
| 6 // met: | 6 // met: | 
| 7 // | 7 // | 
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright | 
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. | 
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above | 
| 11 // copyright notice, this list of conditions and the following disclaimer | 11 // copyright notice, this list of conditions and the following disclaimer | 
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 // TODO: implement mallinfo/mallopt | 81 // TODO: implement mallinfo/mallopt | 
| 82 // TODO: Better testing | 82 // TODO: Better testing | 
| 83 // | 83 // | 
| 84 // 9/28/2003 (new page-level allocator replaces ptmalloc2): | 84 // 9/28/2003 (new page-level allocator replaces ptmalloc2): | 
| 85 // * malloc/free of small objects goes from ~300 ns to ~50 ns. | 85 // * malloc/free of small objects goes from ~300 ns to ~50 ns. | 
| 86 // * allocation of a reasonably complicated struct | 86 // * allocation of a reasonably complicated struct | 
| 87 // goes from about 1100 ns to about 300 ns. | 87 // goes from about 1100 ns to about 300 ns. | 
| 88 | 88 | 
| 89 #include "config.h" | 89 #include "config.h" | 
| 90 #include <google/tcmalloc.h> | 90 #include <google/tcmalloc.h> | 
| 91 | 91 | 
| 
jar (doing other things)
2011/08/20 02:40:30
nit: don't add extra line.
 
bxx
2011/08/24 00:19:24
Done.
 | |
| 92 | |
| 92 #include <errno.h> // for ENOMEM, EINVAL, errno | 93 #include <errno.h> // for ENOMEM, EINVAL, errno | 
| 93 #ifdef HAVE_SYS_CDEFS_H | 94 #ifdef HAVE_SYS_CDEFS_H | 
| 94 #include <sys/cdefs.h> // for __THROW | 95 #include <sys/cdefs.h> // for __THROW | 
| 95 #endif | 96 #endif | 
| 96 #ifdef HAVE_FEATURES_H | 97 #ifdef HAVE_FEATURES_H | 
| 97 #include <features.h> // for __GLIBC__ | 98 #include <features.h> // for __GLIBC__ | 
| 98 #endif | 99 #endif | 
| 99 #if defined HAVE_STDINT_H | 100 #if defined HAVE_STDINT_H | 
| 100 #include <stdint.h> | 101 #include <stdint.h> | 
| 101 #elif defined HAVE_INTTYPES_H | 102 #elif defined HAVE_INTTYPES_H | 
| (...skipping 13 matching lines...) Expand all Loading... | |
| 115 #include <vector> // for vector | 116 #include <vector> // for vector | 
| 116 | 117 | 
| 117 #include <google/malloc_extension.h> | 118 #include <google/malloc_extension.h> | 
| 118 #include <google/malloc_hook.h> // for MallocHook | 119 #include <google/malloc_hook.h> // for MallocHook | 
| 119 #include "base/basictypes.h" // for int64 | 120 #include "base/basictypes.h" // for int64 | 
| 120 #include "base/commandlineflags.h" // for RegisterFlagValidator, etc | 121 #include "base/commandlineflags.h" // for RegisterFlagValidator, etc | 
| 121 #include "base/dynamic_annotations.h" // for RunningOnValgrind | 122 #include "base/dynamic_annotations.h" // for RunningOnValgrind | 
| 122 #include "base/spinlock.h" // for SpinLockHolder | 123 #include "base/spinlock.h" // for SpinLockHolder | 
| 123 #include "central_freelist.h" // for CentralFreeListPadded | 124 #include "central_freelist.h" // for CentralFreeListPadded | 
| 124 #include "common.h" // for StackTrace, kPageShift, etc | 125 #include "common.h" // for StackTrace, kPageShift, etc | 
| 126 #include "free_list.h" // for FL_Init | |
| 125 #include "internal_logging.h" // for ASSERT, TCMalloc_Printer, etc | 127 #include "internal_logging.h" // for ASSERT, TCMalloc_Printer, etc | 
| 126 #include "linked_list.h" // for SLL_SetNext | |
| 127 #include "malloc_hook-inl.h" // for MallocHook::InvokeNewHook, etc | 128 #include "malloc_hook-inl.h" // for MallocHook::InvokeNewHook, etc | 
| 128 #include "page_heap.h" // for PageHeap, PageHeap::Stats | 129 #include "page_heap.h" // for PageHeap, PageHeap::Stats | 
| 129 #include "page_heap_allocator.h" // for PageHeapAllocator | 130 #include "page_heap_allocator.h" // for PageHeapAllocator | 
| 130 #include "span.h" // for Span, DLL_Prepend, etc | 131 #include "span.h" // for Span, DLL_Prepend, etc | 
| 131 #include "stack_trace_table.h" // for StackTraceTable | 132 #include "stack_trace_table.h" // for StackTraceTable | 
| 132 #include "static_vars.h" // for Static | 133 #include "static_vars.h" // for Static | 
| 133 #include "system-alloc.h" // for DumpSystemAllocatorStats, etc | 134 #include "system-alloc.h" // for DumpSystemAllocatorStats, etc | 
| 134 #include "tcmalloc_guard.h" // for TCMallocGuard | 135 #include "tcmalloc_guard.h" // for TCMallocGuard | 
| 135 #include "thread_cache.h" // for ThreadCache | 136 #include "thread_cache.h" // for ThreadCache | 
| 136 | 137 | 
| (...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1220 | 1221 | 
| 1221 ValidateAllocatedRegion(ptr, cl); | 1222 ValidateAllocatedRegion(ptr, cl); | 
| 1222 | 1223 | 
| 1223 if (cl != 0) { | 1224 if (cl != 0) { | 
| 1224 ASSERT(!Static::pageheap()->GetDescriptor(p)->sample); | 1225 ASSERT(!Static::pageheap()->GetDescriptor(p)->sample); | 
| 1225 ThreadCache* heap = GetCacheIfPresent(); | 1226 ThreadCache* heap = GetCacheIfPresent(); | 
| 1226 if (heap != NULL) { | 1227 if (heap != NULL) { | 
| 1227 heap->Deallocate(ptr, cl); | 1228 heap->Deallocate(ptr, cl); | 
| 1228 } else { | 1229 } else { | 
| 1229 // Delete directly into central cache | 1230 // Delete directly into central cache | 
| 1230 tcmalloc::SLL_SetNext(ptr, NULL); | 1231 tcmalloc::FL_Init(ptr); | 
| 1231 Static::central_cache()[cl].InsertRange(ptr, ptr, 1); | 1232 Static::central_cache()[cl].InsertRange(ptr, ptr, 1); | 
| 1232 } | 1233 } | 
| 1233 } else { | 1234 } else { | 
| 1234 SpinLockHolder h(Static::pageheap_lock()); | 1235 SpinLockHolder h(Static::pageheap_lock()); | 
| 1235 ASSERT(reinterpret_cast<uintptr_t>(ptr) % kPageSize == 0); | 1236 ASSERT(reinterpret_cast<uintptr_t>(ptr) % kPageSize == 0); | 
| 1236 ASSERT(span != NULL && span->start == p); | 1237 ASSERT(span != NULL && span->start == p); | 
| 1237 if (span->sample) { | 1238 if (span->sample) { | 
| 1238 StackTrace* st = reinterpret_cast<StackTrace*>(span->objects); | 1239 StackTrace* st = reinterpret_cast<StackTrace*>(span->objects); | 
| 1239 tcmalloc::DLL_Remove(span); | 1240 tcmalloc::DLL_Remove(span); | 
| 1240 Static::stacktrace_allocator()->Delete(st); | 1241 Static::stacktrace_allocator()->Delete(st); | 
| (...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1926 *mark = ~allocated_mark; // Distinctively not allocated. | 1927 *mark = ~allocated_mark; // Distinctively not allocated. | 
| 1927 } | 1928 } | 
| 1928 | 1929 | 
| 1929 static void MarkAllocatedRegion(void* ptr) { | 1930 static void MarkAllocatedRegion(void* ptr) { | 
| 1930 if (ptr == NULL) return; | 1931 if (ptr == NULL) return; | 
| 1931 MarkType* mark = GetMarkLocation(ptr); | 1932 MarkType* mark = GetMarkLocation(ptr); | 
| 1932 *mark = GetMarkValue(ptr, mark); | 1933 *mark = GetMarkValue(ptr, mark); | 
| 1933 } | 1934 } | 
| 1934 | 1935 | 
| 1935 #endif // TCMALLOC_VALIDATION | 1936 #endif // TCMALLOC_VALIDATION | 
| OLD | NEW |