summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Benvenuto <mark.benvenuto@mongodb.com>2017-11-03 16:47:21 -0400
committerMark Benvenuto <mark.benvenuto@mongodb.com>2017-11-03 16:47:21 -0400
commit4c6227e943d1867d0626624fc0975781e2b977ec (patch)
tree8d60ead5ec455e655961598a7a609884fd21edef
parent265fa69f73e083e07c0092d62dc0f5ed54bc9cfe (diff)
downloadmongo-4c6227e943d1867d0626624fc0975781e2b977ec.tar.gz
SERVER-28599 Fix MarkThreadTemporarilyIdle
-rw-r--r--src/third_party/gperftools-2.5/src/thread_cache.cc31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/third_party/gperftools-2.5/src/thread_cache.cc b/src/third_party/gperftools-2.5/src/thread_cache.cc
index ef1f435e0c6..bd2d66f9fa2 100644
--- a/src/third_party/gperftools-2.5/src/thread_cache.cc
+++ b/src/third_party/gperftools-2.5/src/thread_cache.cc
@@ -398,8 +398,37 @@ void ThreadCache::BecomeIdle() {
void ThreadCache::BecomeTemporarilyIdle() {
ThreadCache* heap = GetCacheIfPresent();
- if (heap)
+ if (heap) {
heap->Cleanup();
+
+ // Re-initialize the free list state to reset the slow-start
+ // algorithm for max_size_; this avoids requesting more and more
+ // memory from the central freelist due to frequent calls.
+ for (size_t cl = 0; cl < kNumClasses; ++cl) {
+ heap->list_[cl].Init();
+ }
+
+ // Re-calculate the Thread Cache max size if we have a non-default size.
+ if (heap->max_size_ != kMinThreadCacheSize) {
+ SpinLockHolder h(Static::pageheap_lock());
+
+ // Return claimed thread space
+ unclaimed_cache_space_ += heap->max_size_;
+
+ // Re-init max_size_
+ heap->max_size_ = 0;
+ heap->IncreaseCacheLimitLocked();
+
+ if (heap->max_size_ == 0) {
+ // There isn't enough memory to go around. Just give the minimum to
+ // this thread.
+ heap->max_size_ = kMinThreadCacheSize;
+
+ // Take unclaimed_cache_space_ negative.
+ unclaimed_cache_space_ -= kMinThreadCacheSize;
+ }
+ }
+ }
}
void ThreadCache::DestroyThreadCache(void* ptr) {