summaryrefslogtreecommitdiffstats
path: root/third_party/tcmalloc/chromium/src/thread_cache.h
diff options
context:
space:
mode:
authorglider@chromium.org <glider@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-24 09:53:31 +0000
committerglider@chromium.org <glider@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-24 09:53:31 +0000
commitd06e455c161c0e52849a0f85581947f6f20cf8de (patch)
tree716b29f0a098588b1bb177a010708c87f704ddf4 /third_party/tcmalloc/chromium/src/thread_cache.h
parent779f0af5c653dfc83cb831ebbfead8dd0344fbc1 (diff)
downloadchromium_src-d06e455c161c0e52849a0f85581947f6f20cf8de.zip
chromium_src-d06e455c161c0e52849a0f85581947f6f20cf8de.tar.gz
chromium_src-d06e455c161c0e52849a0f85581947f6f20cf8de.tar.bz2
Re-land http://codereview.chromium.org/1735024/show to assess the performance.
TBR=antonm,willchan Review URL: http://codereview.chromium.org/2164001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48024 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/tcmalloc/chromium/src/thread_cache.h')
-rw-r--r--third_party/tcmalloc/chromium/src/thread_cache.h34
1 files changed, 20 insertions, 14 deletions
diff --git a/third_party/tcmalloc/chromium/src/thread_cache.h b/third_party/tcmalloc/chromium/src/thread_cache.h
index 4c6a233..1165447 100644
--- a/third_party/tcmalloc/chromium/src/thread_cache.h
+++ b/third_party/tcmalloc/chromium/src/thread_cache.h
@@ -79,7 +79,9 @@ class ThreadCache {
// Total byte size in cache
size_t Size() const { return size_; }
- void* Allocate(size_t size);
+ // Allocate an object of the given size and class. The size given
+ // must be the same as the size of the class in the size map.
+ void* Allocate(size_t size, size_t cl);
void Deallocate(void* ptr, size_t size_class);
void Scavenge();
@@ -293,15 +295,18 @@ class ThreadCache {
// across all ThreadCaches. Protected by Static::pageheap_lock.
static ssize_t unclaimed_cache_space_;
- // Warning: the offset of list_ affects performance. On general
- // principles, we don't like list_[x] to span multiple L1 cache
- // lines. However, merely placing list_ at offset 0 here seems to
- // cause cache conflicts.
+ // This class is laid out with the most frequently used fields
+ // first so that hot elements are placed on the same cache line.
size_t size_; // Combined size of data
size_t max_size_; // size_ > max_size_ --> Scavenge()
- pthread_t tid_; // Which thread owns it
+
+ // We sample allocations, biased by the size of the allocation
+ Sampler sampler_; // A sampler
+
FreeList list_[kNumClasses]; // Array indexed by size-class
+
+ pthread_t tid_; // Which thread owns it
bool in_setspecific_; // In call to pthread_setspecific?
// Allocate a new heap. REQUIRES: Static::pageheap_lock is held.
@@ -313,9 +318,10 @@ class ThreadCache {
static void DeleteCache(ThreadCache* heap);
static void RecomputePerThreadCacheSize();
- // We sample allocations, biased by the size of the allocation
- Sampler sampler_; // A sampler
-};
+ // Ensure that this class is cacheline-aligned. This is critical for
+ // performance, as false sharing would negate many of the benefits
+ // of a per-thread cache.
+} CACHELINE_ALIGNED;
// Allocator for thread heaps
// This is logically part of the ThreadCache class, but MSVC, at
@@ -331,15 +337,15 @@ inline bool ThreadCache::SampleAllocation(size_t k) {
return sampler_.SampleAllocation(k);
}
-inline void* ThreadCache::Allocate(size_t size) {
+inline void* ThreadCache::Allocate(size_t size, size_t cl) {
ASSERT(size <= kMaxSize);
- const size_t cl = Static::sizemap()->SizeClass(size);
- const size_t alloc_size = Static::sizemap()->ByteSizeForClass(cl);
+ ASSERT(size == Static::sizemap()->ByteSizeForClass(cl));
+
FreeList* list = &list_[cl];
if (list->empty()) {
- return FetchFromCentralCache(cl, alloc_size);
+ return FetchFromCentralCache(cl, size);
}
- size_ -= alloc_size;
+ size_ -= size;
return list->Pop();
}