Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: third_party/tcmalloc/vendor/src/thread_cache.cc

Issue 9316021: Update the tcmalloc vendor branch to r144 (gperftools 2.0). (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Reuploading Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2008, Google Inc. 1 // Copyright (c) 2008, 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
(...skipping 14 matching lines...) Expand all
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 29
30 // --- 30 // ---
31 // Author: Ken Ashcraft <opensource@google.com> 31 // Author: Ken Ashcraft <opensource@google.com>
32 32
33 #include <config.h> 33 #include <config.h>
34 #include "thread_cache.h" 34 #include "thread_cache.h"
35 #include <errno.h>
35 #include <string.h> // for memcpy 36 #include <string.h> // for memcpy
36 #include <algorithm> // for max, min 37 #include <algorithm> // for max, min
37 #include "base/commandlineflags.h" // for SpinLockHolder 38 #include "base/commandlineflags.h" // for SpinLockHolder
38 #include "base/spinlock.h" // for SpinLockHolder 39 #include "base/spinlock.h" // for SpinLockHolder
39 #include "central_freelist.h" // for CentralFreeListPadded 40 #include "central_freelist.h" // for CentralFreeListPadded
40 #include "maybe_threads.h" 41 #include "maybe_threads.h"
41 42
42 using std::min; 43 using std::min;
43 using std::max; 44 using std::max;
44 45
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 kernel_supports_tls = true; 79 kernel_supports_tls = true;
79 } 80 }
80 # elif !HAVE_DECL_UNAME // if too old for uname, probably too old for TLS 81 # elif !HAVE_DECL_UNAME // if too old for uname, probably too old for TLS
81 void CheckIfKernelSupportsTLS() { 82 void CheckIfKernelSupportsTLS() {
82 kernel_supports_tls = false; 83 kernel_supports_tls = false;
83 } 84 }
84 # else 85 # else
85 # include <sys/utsname.h> // DECL_UNAME checked for <sys/utsname.h> too 86 # include <sys/utsname.h> // DECL_UNAME checked for <sys/utsname.h> too
86 void CheckIfKernelSupportsTLS() { 87 void CheckIfKernelSupportsTLS() {
87 struct utsname buf; 88 struct utsname buf;
88 if (uname(&buf) != 0) { // should be impossible 89 if (uname(&buf) < 0) { // should be impossible
89 MESSAGE("uname failed assuming no TLS support (errno=%d)\n", errno); 90 Log(kLog, __FILE__, __LINE__,
91 "uname failed assuming no TLS support (errno)", errno);
90 kernel_supports_tls = false; 92 kernel_supports_tls = false;
91 } else if (strcasecmp(buf.sysname, "linux") == 0) { 93 } else if (strcasecmp(buf.sysname, "linux") == 0) {
92 // The linux case: the first kernel to support TLS was 2.6.0 94 // The linux case: the first kernel to support TLS was 2.6.0
93 if (buf.release[0] < '2' && buf.release[1] == '.') // 0.x or 1.x 95 if (buf.release[0] < '2' && buf.release[1] == '.') // 0.x or 1.x
94 kernel_supports_tls = false; 96 kernel_supports_tls = false;
95 else if (buf.release[0] == '2' && buf.release[1] == '.' && 97 else if (buf.release[0] == '2' && buf.release[1] == '.' &&
96 buf.release[2] >= '0' && buf.release[2] < '6' && 98 buf.release[2] >= '0' && buf.release[2] < '6' &&
97 buf.release[3] == '.') // 2.0 - 2.5 99 buf.release[3] == '.') // 2.0 - 2.5
98 kernel_supports_tls = false; 100 kernel_supports_tls = false;
99 else 101 else
100 kernel_supports_tls = true; 102 kernel_supports_tls = true;
103 } else if (strcasecmp(buf.sysname, "CYGWIN_NT-6.1-WOW64") == 0) {
104 // In my testing, this version of cygwin, at least, would hang
105 // when using TLS.
106 kernel_supports_tls = false;
101 } else { // some other kernel, we'll be optimisitic 107 } else { // some other kernel, we'll be optimisitic
102 kernel_supports_tls = true; 108 kernel_supports_tls = true;
103 } 109 }
104 // TODO(csilvers): VLOG(1) the tls status once we support RAW_VLOG 110 // TODO(csilvers): VLOG(1) the tls status once we support RAW_VLOG
105 } 111 }
106 # endif // HAVE_DECL_UNAME 112 # endif // HAVE_DECL_UNAME
107 #endif // HAVE_TLS 113 #endif // HAVE_TLS
108 114
109 void ThreadCache::Init(pthread_t tid) { 115 void ThreadCache::Init(pthread_t tid) {
110 size_ = 0; 116 size_ = 0;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 const int batch_size = Static::sizemap()->num_objects_to_move(cl); 259 const int batch_size = Static::sizemap()->num_objects_to_move(cl);
254 if (list->max_length() > batch_size) { 260 if (list->max_length() > batch_size) {
255 list->set_max_length( 261 list->set_max_length(
256 max<int>(list->max_length() - batch_size, batch_size)); 262 max<int>(list->max_length() - batch_size, batch_size));
257 } 263 }
258 } 264 }
259 list->clear_lowwatermark(); 265 list->clear_lowwatermark();
260 } 266 }
261 267
262 IncreaseCacheLimit(); 268 IncreaseCacheLimit();
263
264 // int64 finish = CycleClock::Now();
265 // CycleTimer ct;
266 // MESSAGE("GC: %.0f ns\n", ct.CyclesToUsec(finish-start)*1000.0);
267 } 269 }
268 270
269 void ThreadCache::IncreaseCacheLimit() { 271 void ThreadCache::IncreaseCacheLimit() {
270 SpinLockHolder h(Static::pageheap_lock()); 272 SpinLockHolder h(Static::pageheap_lock());
271 IncreaseCacheLimitLocked(); 273 IncreaseCacheLimitLocked();
272 } 274 }
273 275
274 void ThreadCache::IncreaseCacheLimitLocked() { 276 void ThreadCache::IncreaseCacheLimitLocked() {
275 if (unclaimed_cache_space_ > 0) { 277 if (unclaimed_cache_space_ > 0) {
276 // Possibly make unclaimed_cache_space_ negative. 278 // Possibly make unclaimed_cache_space_ negative.
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 for (ThreadCache* h = thread_heaps_; h != NULL; h = h->next_) { 471 for (ThreadCache* h = thread_heaps_; h != NULL; h = h->next_) {
470 // Increasing the total cache size should not circumvent the 472 // Increasing the total cache size should not circumvent the
471 // slow-start growth of max_size_. 473 // slow-start growth of max_size_.
472 if (ratio < 1.0) { 474 if (ratio < 1.0) {
473 h->max_size_ = static_cast<size_t>(h->max_size_ * ratio); 475 h->max_size_ = static_cast<size_t>(h->max_size_ * ratio);
474 } 476 }
475 claimed += h->max_size_; 477 claimed += h->max_size_;
476 } 478 }
477 unclaimed_cache_space_ = overall_thread_cache_size_ - claimed; 479 unclaimed_cache_space_ = overall_thread_cache_size_ - claimed;
478 per_thread_cache_size_ = space; 480 per_thread_cache_size_ = space;
479 // TCMalloc_MESSAGE(__FILE__, __LINE__, "Threads %d => cache size %8d\n", n, int(space));
480 }
481
482 void ThreadCache::Print(TCMalloc_Printer* out) const {
483 for (int cl = 0; cl < kNumClasses; ++cl) {
484 out->printf(" %5" PRIuS " : %4" PRIuS " len; %4d lo; %4"PRIuS
485 " max; %4"PRIuS" overages;\n",
486 Static::sizemap()->ByteSizeForClass(cl),
487 list_[cl].length(),
488 list_[cl].lowwatermark(),
489 list_[cl].max_length(),
490 list_[cl].length_overages());
491 }
492 }
493
494 void ThreadCache::PrintThreads(TCMalloc_Printer* out) {
495 size_t actual_limit = 0;
496 for (ThreadCache* h = thread_heaps_; h != NULL; h = h->next_) {
497 h->Print(out);
498 actual_limit += h->max_size_;
499 }
500 out->printf("ThreadCache overall: %"PRIuS ", unclaimed: %"PRIdS
501 ", actual: %"PRIuS"\n",
502 overall_thread_cache_size_, unclaimed_cache_space_, actual_limit);
503 } 481 }
504 482
505 void ThreadCache::GetThreadStats(uint64_t* total_bytes, uint64_t* class_count) { 483 void ThreadCache::GetThreadStats(uint64_t* total_bytes, uint64_t* class_count) {
506 for (ThreadCache* h = thread_heaps_; h != NULL; h = h->next_) { 484 for (ThreadCache* h = thread_heaps_; h != NULL; h = h->next_) {
507 *total_bytes += h->Size(); 485 *total_bytes += h->Size();
508 if (class_count) { 486 if (class_count) {
509 for (int cl = 0; cl < kNumClasses; ++cl) { 487 for (int cl = 0; cl < kNumClasses; ++cl) {
510 class_count[cl] += h->freelist_length(cl); 488 class_count[cl] += h->freelist_length(cl);
511 } 489 }
512 } 490 }
513 } 491 }
514 } 492 }
515 493
516 void ThreadCache::set_overall_thread_cache_size(size_t new_size) { 494 void ThreadCache::set_overall_thread_cache_size(size_t new_size) {
517 // Clip the value to a reasonable range 495 // Clip the value to a reasonable range
518 if (new_size < kMinThreadCacheSize) new_size = kMinThreadCacheSize; 496 if (new_size < kMinThreadCacheSize) new_size = kMinThreadCacheSize;
519 if (new_size > (1<<30)) new_size = (1<<30); // Limit to 1GB 497 if (new_size > (1<<30)) new_size = (1<<30); // Limit to 1GB
520 overall_thread_cache_size_ = new_size; 498 overall_thread_cache_size_ = new_size;
521 499
522 RecomputePerThreadCacheSize(); 500 RecomputePerThreadCacheSize();
523 } 501 }
524 502
525 } // namespace tcmalloc 503 } // namespace tcmalloc
OLDNEW
« no previous file with comments | « third_party/tcmalloc/vendor/src/thread_cache.h ('k') | third_party/tcmalloc/vendor/src/windows/auto_testing_hook.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698