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

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

Issue 9701040: Revert 126715 - Update the tcmalloc vendor branch to r144 (gperftools 2.0). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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>
36 #include <string.h> // for memcpy 35 #include <string.h> // for memcpy
37 #include <algorithm> // for max, min 36 #include <algorithm> // for max, min
38 #include "base/commandlineflags.h" // for SpinLockHolder 37 #include "base/commandlineflags.h" // for SpinLockHolder
39 #include "base/spinlock.h" // for SpinLockHolder 38 #include "base/spinlock.h" // for SpinLockHolder
40 #include "central_freelist.h" // for CentralFreeListPadded 39 #include "central_freelist.h" // for CentralFreeListPadded
41 #include "maybe_threads.h" 40 #include "maybe_threads.h"
42 41
43 using std::min; 42 using std::min;
44 using std::max; 43 using std::max;
45 44
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 kernel_supports_tls = true; 78 kernel_supports_tls = true;
80 } 79 }
81 # elif !HAVE_DECL_UNAME // if too old for uname, probably too old for TLS 80 # elif !HAVE_DECL_UNAME // if too old for uname, probably too old for TLS
82 void CheckIfKernelSupportsTLS() { 81 void CheckIfKernelSupportsTLS() {
83 kernel_supports_tls = false; 82 kernel_supports_tls = false;
84 } 83 }
85 # else 84 # else
86 # include <sys/utsname.h> // DECL_UNAME checked for <sys/utsname.h> too 85 # include <sys/utsname.h> // DECL_UNAME checked for <sys/utsname.h> too
87 void CheckIfKernelSupportsTLS() { 86 void CheckIfKernelSupportsTLS() {
88 struct utsname buf; 87 struct utsname buf;
89 if (uname(&buf) < 0) { // should be impossible 88 if (uname(&buf) != 0) { // should be impossible
90 Log(kLog, __FILE__, __LINE__, 89 MESSAGE("uname failed assuming no TLS support (errno=%d)\n", errno);
91 "uname failed assuming no TLS support (errno)", errno);
92 kernel_supports_tls = false; 90 kernel_supports_tls = false;
93 } else if (strcasecmp(buf.sysname, "linux") == 0) { 91 } else if (strcasecmp(buf.sysname, "linux") == 0) {
94 // The linux case: the first kernel to support TLS was 2.6.0 92 // The linux case: the first kernel to support TLS was 2.6.0
95 if (buf.release[0] < '2' && buf.release[1] == '.') // 0.x or 1.x 93 if (buf.release[0] < '2' && buf.release[1] == '.') // 0.x or 1.x
96 kernel_supports_tls = false; 94 kernel_supports_tls = false;
97 else if (buf.release[0] == '2' && buf.release[1] == '.' && 95 else if (buf.release[0] == '2' && buf.release[1] == '.' &&
98 buf.release[2] >= '0' && buf.release[2] < '6' && 96 buf.release[2] >= '0' && buf.release[2] < '6' &&
99 buf.release[3] == '.') // 2.0 - 2.5 97 buf.release[3] == '.') // 2.0 - 2.5
100 kernel_supports_tls = false; 98 kernel_supports_tls = false;
101 else 99 else
102 kernel_supports_tls = true; 100 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;
107 } else { // some other kernel, we'll be optimisitic 101 } else { // some other kernel, we'll be optimisitic
108 kernel_supports_tls = true; 102 kernel_supports_tls = true;
109 } 103 }
110 // TODO(csilvers): VLOG(1) the tls status once we support RAW_VLOG 104 // TODO(csilvers): VLOG(1) the tls status once we support RAW_VLOG
111 } 105 }
112 # endif // HAVE_DECL_UNAME 106 # endif // HAVE_DECL_UNAME
113 #endif // HAVE_TLS 107 #endif // HAVE_TLS
114 108
115 void ThreadCache::Init(pthread_t tid) { 109 void ThreadCache::Init(pthread_t tid) {
116 size_ = 0; 110 size_ = 0;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 const int batch_size = Static::sizemap()->num_objects_to_move(cl); 253 const int batch_size = Static::sizemap()->num_objects_to_move(cl);
260 if (list->max_length() > batch_size) { 254 if (list->max_length() > batch_size) {
261 list->set_max_length( 255 list->set_max_length(
262 max<int>(list->max_length() - batch_size, batch_size)); 256 max<int>(list->max_length() - batch_size, batch_size));
263 } 257 }
264 } 258 }
265 list->clear_lowwatermark(); 259 list->clear_lowwatermark();
266 } 260 }
267 261
268 IncreaseCacheLimit(); 262 IncreaseCacheLimit();
263
264 // int64 finish = CycleClock::Now();
265 // CycleTimer ct;
266 // MESSAGE("GC: %.0f ns\n", ct.CyclesToUsec(finish-start)*1000.0);
269 } 267 }
270 268
271 void ThreadCache::IncreaseCacheLimit() { 269 void ThreadCache::IncreaseCacheLimit() {
272 SpinLockHolder h(Static::pageheap_lock()); 270 SpinLockHolder h(Static::pageheap_lock());
273 IncreaseCacheLimitLocked(); 271 IncreaseCacheLimitLocked();
274 } 272 }
275 273
276 void ThreadCache::IncreaseCacheLimitLocked() { 274 void ThreadCache::IncreaseCacheLimitLocked() {
277 if (unclaimed_cache_space_ > 0) { 275 if (unclaimed_cache_space_ > 0) {
278 // Possibly make unclaimed_cache_space_ negative. 276 // Possibly make unclaimed_cache_space_ negative.
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 for (ThreadCache* h = thread_heaps_; h != NULL; h = h->next_) { 469 for (ThreadCache* h = thread_heaps_; h != NULL; h = h->next_) {
472 // Increasing the total cache size should not circumvent the 470 // Increasing the total cache size should not circumvent the
473 // slow-start growth of max_size_. 471 // slow-start growth of max_size_.
474 if (ratio < 1.0) { 472 if (ratio < 1.0) {
475 h->max_size_ = static_cast<size_t>(h->max_size_ * ratio); 473 h->max_size_ = static_cast<size_t>(h->max_size_ * ratio);
476 } 474 }
477 claimed += h->max_size_; 475 claimed += h->max_size_;
478 } 476 }
479 unclaimed_cache_space_ = overall_thread_cache_size_ - claimed; 477 unclaimed_cache_space_ = overall_thread_cache_size_ - claimed;
480 per_thread_cache_size_ = space; 478 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);
481 } 503 }
482 504
483 void ThreadCache::GetThreadStats(uint64_t* total_bytes, uint64_t* class_count) { 505 void ThreadCache::GetThreadStats(uint64_t* total_bytes, uint64_t* class_count) {
484 for (ThreadCache* h = thread_heaps_; h != NULL; h = h->next_) { 506 for (ThreadCache* h = thread_heaps_; h != NULL; h = h->next_) {
485 *total_bytes += h->Size(); 507 *total_bytes += h->Size();
486 if (class_count) { 508 if (class_count) {
487 for (int cl = 0; cl < kNumClasses; ++cl) { 509 for (int cl = 0; cl < kNumClasses; ++cl) {
488 class_count[cl] += h->freelist_length(cl); 510 class_count[cl] += h->freelist_length(cl);
489 } 511 }
490 } 512 }
491 } 513 }
492 } 514 }
493 515
494 void ThreadCache::set_overall_thread_cache_size(size_t new_size) { 516 void ThreadCache::set_overall_thread_cache_size(size_t new_size) {
495 // Clip the value to a reasonable range 517 // Clip the value to a reasonable range
496 if (new_size < kMinThreadCacheSize) new_size = kMinThreadCacheSize; 518 if (new_size < kMinThreadCacheSize) new_size = kMinThreadCacheSize;
497 if (new_size > (1<<30)) new_size = (1<<30); // Limit to 1GB 519 if (new_size > (1<<30)) new_size = (1<<30); // Limit to 1GB
498 overall_thread_cache_size_ = new_size; 520 overall_thread_cache_size_ = new_size;
499 521
500 RecomputePerThreadCacheSize(); 522 RecomputePerThreadCacheSize();
501 } 523 }
502 524
503 } // namespace tcmalloc 525 } // 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