diff options
author | csilvers <csilvers@6b5cf1ce-ec42-a296-1ba9-69fdba395a50> | 2011-07-16 01:07:10 +0000 |
---|---|---|
committer | csilvers <csilvers@6b5cf1ce-ec42-a296-1ba9-69fdba395a50> | 2011-07-16 01:07:10 +0000 |
commit | 100c38c1a225446c1bbeeaac117902d0fbebfefe (patch) | |
tree | 0880fc86d5db8c110ae469f0d702a44db1b4b5ef /src/thread_cache.cc | |
parent | 8c7d2289d24f7a49f1f6f60d4a6eaee06fa04c60 (diff) | |
download | gperftools-100c38c1a225446c1bbeeaac117902d0fbebfefe.tar.gz |
Fri Jul 15 16:10:51 2011 Google Inc. <opensource@google.com>
* google-perftools: version 1.8 release
* PORTING: (Disabled) support for patching mmap on freebsd (chapp...)
* PORTING: Support volatile __malloc_hook for glibc 2.14 (csilvers)
* PORTING: Use _asm rdtsc and __rdtsc to get cycleclock in windows (koda)
* PORTING: Fix fd vs. HANDLE compiler error on cygwin (csilvers)
* PORTING: Do not test memalign or double-linking on OS X (csilvers)
* PORTING: Actually enable TLS on windows (jontra)
* PORTING: Some work to compile under Native Client (krasin)
* PORTING: deal with pthread_once w/o -pthread on freebsd (csilvers)
* Rearrange libc-overriding to make it easier to port (csilvers)
* Display source locations in pprof disassembly (sanjay)
* BUGFIX: Actually initialize allocator name (mec)
* BUGFIX: Keep track of 'overhead' bytes in malloc reporting (csilvers)
* Allow ignoring one object twice in the leak checker (glider)
* BUGFIX: top10 in pprof should print 10 lines, not 11 (rsc)
* Refactor vdso source files (tipp)
* Some documentation cleanups
* Document MAX_TOTAL_THREAD_CACHE_SIZE <= 1Gb (nsethi)
* Add MallocExtension::GetOwnership(ptr) (csilvers)
* BUGFIX: We were leaving out a needed $(top_srcdir) in the Makefile
* PORTING: Support getting argv0 on OS X
* Add 'weblist' command to pprof: like 'list' but html (sanjay)
* Improve source listing in pprof (sanjay)
* Cap cache sizes to reduce fragmentation (ruemmler)
* Improve performance by capping or increasing sizes (ruemmler)
* Add M{,un}mapReplacmenet hooks into MallocHook (ribrdb)
* Refactored system allocator logic (gangren)
* Include cleanups (csilvers)
* Add TCMALLOC_SMALL_BUT_SLOW support (ruemmler)
* Clarify that tcmalloc stats are MiB (robinson)
* Remove support for non-tcmalloc debugallocation (blount)
* Add a new test: malloc_hook_test (csilvers)
* Change the configure script to be more crosstool-friendly (mcgrathr)
* PORTING: leading-underscore changes to support win64 (csilvers)
* Improve debugallocation tc_malloc_size (csilvers)
* Extend atomicops.h and cyceclock to use ARM V6+ optimized code (sanek)
* Change malloc-hook to use a list-like structure (llib)
* Add flag to use MAP_PRIVATE in memfs_malloc (gangren)
* Windows support for pprof: nul and /usr/bin/file (csilvers)
* TESTING: add test on strdup to tcmalloc_test (csilvers)
* Augment heap-checker to deal with no-inode maps (csilvers)
* Count .dll/.dylib as shared libs in heap-checker (csilvers)
* Disable sys_futex for arm; it's not always reliable (sanek)
* PORTING: change lots of windows/port.h macros to functions
* BUGFIX: Generate correct version# in tcmalloc.h on windows (csilvers)
* PORTING: Some casting to make solaris happier about types (csilvers)
* TESTING: Disable debugallocation_test in 'minimal' mode (csilvers)
* Rewrite debugallocation to be more modular (csilvers)
* Don't try to run the heap-checker under valgrind (ppluzhnikov)
* BUGFIX: Make focused stat %'s relative, not absolute (sanjay)
* BUGFIX: Don't use '//' comments in a C file (csilvers)
* Quiet new-gcc compiler warnings via -Wno-unused-result, etc (csilvers)
git-svn-id: http://gperftools.googlecode.com/svn/trunk@110 6b5cf1ce-ec42-a296-1ba9-69fdba395a50
Diffstat (limited to 'src/thread_cache.cc')
-rw-r--r-- | src/thread_cache.cc | 51 |
1 files changed, 37 insertions, 14 deletions
diff --git a/src/thread_cache.cc b/src/thread_cache.cc index b00e3b4..c228c0f 100644 --- a/src/thread_cache.cc +++ b/src/thread_cache.cc @@ -46,8 +46,9 @@ DEFINE_int64(tcmalloc_max_total_thread_cache_bytes, EnvToInt64("TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES", kDefaultOverallThreadCacheSize), "Bound on the total amount of bytes allocated to " - "thread caches. This bound is not strict, so it is possible " - "for the cache to go over this bound in certain circumstances. "); + "thread caches. This bound is not strict, so it is possible " + "for the cache to go over this bound in certain circumstances. " + "Maximum value of this flag is capped to 1 GB."); namespace tcmalloc { @@ -72,7 +73,11 @@ pthread_key_t ThreadCache::heap_key_; #if defined(HAVE_TLS) bool kernel_supports_tls = false; // be conservative -# if !HAVE_DECL_UNAME // if too old for uname, probably too old for TLS +# if defined(_WIN32) // windows has supported TLS since winnt, I think. + void CheckIfKernelSupportsTLS() { + kernel_supports_tls = true; + } +# elif !HAVE_DECL_UNAME // if too old for uname, probably too old for TLS void CheckIfKernelSupportsTLS() { kernel_supports_tls = false; } @@ -313,6 +318,18 @@ void ThreadCache::InitTSD() { ASSERT(!tsd_inited_); perftools_pthread_key_create(&heap_key_, DestroyThreadCache); tsd_inited_ = true; + +#ifdef PTHREADS_CRASHES_IF_RUN_TOO_EARLY + // We may have used a fake pthread_t for the main thread. Fix it. + pthread_t zero; + memset(&zero, 0, sizeof(zero)); + SpinLockHolder h(Static::pageheap_lock()); + for (ThreadCache* h = thread_heaps_; h != NULL; h = h->next_) { + if (h->tid_ == zero) { + h->tid_ = pthread_self(); + } + } +#endif } ThreadCache* ThreadCache::CreateCacheIfNecessary() { @@ -320,17 +337,23 @@ ThreadCache* ThreadCache::CreateCacheIfNecessary() { ThreadCache* heap = NULL; { SpinLockHolder h(Static::pageheap_lock()); - // On very old libc's, this call may crash if it happens too - // early. No libc using NPTL should be affected. If there - // is a crash here, we could use code (on linux, at least) - // to detect NPTL vs LinuxThreads: - // http://www.redhat.com/archives/phil-list/2003-April/msg00038.html - // If we detect not-NPTL, we could execute the old code from - // http://google-perftools.googlecode.com/svn/tags/google-perftools-1.7/src/thread_cache.cc - // that avoids calling pthread_self too early. The problem with - // that code is it caused a race condition when tcmalloc is linked - // in statically and other libraries spawn threads before main. + // On some old glibc's, and on freebsd's libc (as of freebsd 8.1), + // calling pthread routines (even pthread_self) too early could + // cause a segfault. Since we can call pthreads quite early, we + // have to protect against that in such situations by making a + // 'fake' pthread. This is not ideal since it doesn't work well + // when linking tcmalloc statically with apps that create threads + // before main, so we only do it if we have to. +#ifdef PTHREADS_CRASHES_IF_RUN_TOO_EARLY + pthread_t me; + if (!tsd_inited_) { + memset(&me, 0, sizeof(me)); + } else { + me = pthread_self(); + } +#else const pthread_t me = pthread_self(); +#endif // This may be a recursive malloc call from pthread_setspecific() // In that case, the heap for this thread has already been created @@ -474,7 +497,7 @@ void ThreadCache::PrintThreads(TCMalloc_Printer* out) { h->Print(out); actual_limit += h->max_size_; } - out->printf("ThreadCache overall: %"PRIuS ", unclaimed: %"PRIuS + out->printf("ThreadCache overall: %"PRIuS ", unclaimed: %"PRIdS ", actual: %"PRIuS"\n", overall_thread_cache_size_, unclaimed_cache_space_, actual_limit); } |