| OLD | NEW |
| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 } else { // some other kernel, we'll be optimisitic | 96 } else { // some other kernel, we'll be optimisitic |
| 97 kernel_supports_tls = true; | 97 kernel_supports_tls = true; |
| 98 } | 98 } |
| 99 // TODO(csilvers): VLOG(1) the tls status once we support RAW_VLOG | 99 // TODO(csilvers): VLOG(1) the tls status once we support RAW_VLOG |
| 100 } | 100 } |
| 101 # endif // HAVE_DECL_UNAME | 101 # endif // HAVE_DECL_UNAME |
| 102 #endif // HAVE_TLS | 102 #endif // HAVE_TLS |
| 103 | 103 |
| 104 void ThreadCache::Init(pthread_t tid) { | 104 void ThreadCache::Init(pthread_t tid) { |
| 105 size_ = 0; | 105 size_ = 0; |
| 106 total_bytes_allocated_ = 0; |
| 106 | 107 |
| 107 max_size_ = 0; | 108 max_size_ = 0; |
| 108 IncreaseCacheLimitLocked(); | 109 IncreaseCacheLimitLocked(); |
| 109 if (max_size_ == 0) { | 110 if (max_size_ == 0) { |
| 110 // There isn't enough memory to go around. Just give the minimum to | 111 // There isn't enough memory to go around. Just give the minimum to |
| 111 // this thread. | 112 // this thread. |
| 112 max_size_ = kMinThreadCacheSize; | 113 max_size_ = kMinThreadCacheSize; |
| 113 | 114 |
| 114 // Take unclaimed_cache_space_ negative. | 115 // Take unclaimed_cache_space_ negative. |
| 115 unclaimed_cache_space_ -= kMinThreadCacheSize; | 116 unclaimed_cache_space_ -= kMinThreadCacheSize; |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 | 297 |
| 297 next_memory_steal_ = next_memory_steal_->next_; | 298 next_memory_steal_ = next_memory_steal_->next_; |
| 298 return; | 299 return; |
| 299 } | 300 } |
| 300 } | 301 } |
| 301 | 302 |
| 302 int ThreadCache::GetSamplePeriod() { | 303 int ThreadCache::GetSamplePeriod() { |
| 303 return sampler_.GetSamplePeriod(); | 304 return sampler_.GetSamplePeriod(); |
| 304 } | 305 } |
| 305 | 306 |
| 307 // static |
| 308 unsigned int ThreadCache::GetBytesAllocatedOnCurrentThread() { |
| 309 return ThreadCache::GetThreadHeap()->GetTotalBytesAllocated(); |
| 310 } |
| 311 |
| 306 void ThreadCache::InitModule() { | 312 void ThreadCache::InitModule() { |
| 307 SpinLockHolder h(Static::pageheap_lock()); | 313 SpinLockHolder h(Static::pageheap_lock()); |
| 308 if (!phinited) { | 314 if (!phinited) { |
| 309 Static::InitStaticVars(); | 315 Static::InitStaticVars(); |
| 310 threadcache_allocator.Init(); | 316 threadcache_allocator.Init(); |
| 311 phinited = 1; | 317 phinited = 1; |
| 312 } | 318 } |
| 313 } | 319 } |
| 314 | 320 |
| 315 void ThreadCache::InitTSD() { | 321 void ThreadCache::InitTSD() { |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 void ThreadCache::set_overall_thread_cache_size(size_t new_size) { | 502 void ThreadCache::set_overall_thread_cache_size(size_t new_size) { |
| 497 // Clip the value to a reasonable range | 503 // Clip the value to a reasonable range |
| 498 if (new_size < kMinThreadCacheSize) new_size = kMinThreadCacheSize; | 504 if (new_size < kMinThreadCacheSize) new_size = kMinThreadCacheSize; |
| 499 if (new_size > (1<<30)) new_size = (1<<30); // Limit to 1GB | 505 if (new_size > (1<<30)) new_size = (1<<30); // Limit to 1GB |
| 500 overall_thread_cache_size_ = new_size; | 506 overall_thread_cache_size_ = new_size; |
| 501 | 507 |
| 502 RecomputePerThreadCacheSize(); | 508 RecomputePerThreadCacheSize(); |
| 503 } | 509 } |
| 504 | 510 |
| 505 } // namespace tcmalloc | 511 } // namespace tcmalloc |
| OLD | NEW |