summaryrefslogtreecommitdiffstats
path: root/third_party
diff options
context:
space:
mode:
authorjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-01 00:25:41 +0000
committerjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-01 00:25:41 +0000
commite94afbb913b95f512cb8745a2729c73f82b15ae7 (patch)
treea6743a8f89cb44c6a5873c87706e83203fc05303 /third_party
parente0bf7382ae532696f850d41a131509a9cae5f215 (diff)
downloadchromium_src-e94afbb913b95f512cb8745a2729c73f82b15ae7.zip
chromium_src-e94afbb913b95f512cb8745a2729c73f82b15ae7.tar.gz
chromium_src-e94afbb913b95f512cb8745a2729c73f82b15ae7.tar.bz2
Rollback Scavenge implemetation and rely on existing functionality to free
This is a landing of a patch provided by antonm. See: http://codereview.chromium.org/235022 Also included change to browser_about_handler.cc to fix build, and I set TCMALLOC_RELEASE_RATE to 1.0 on line 40 of page_heap.cc (I think this was an inadvertent rollback element). r=antonm Review URL: http://codereview.chromium.org/257009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27692 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party')
-rw-r--r--third_party/tcmalloc/config_linux.h6
-rw-r--r--third_party/tcmalloc/config_win.h6
-rw-r--r--third_party/tcmalloc/google/malloc_extension.h239
-rw-r--r--third_party/tcmalloc/malloc_extension.cc326
-rw-r--r--third_party/tcmalloc/page_heap.cc109
-rw-r--r--third_party/tcmalloc/page_heap.h32
-rw-r--r--third_party/tcmalloc/tcmalloc.cc5
-rw-r--r--third_party/tcmalloc/tcmalloc.gyp6
8 files changed, 6 insertions, 723 deletions
diff --git a/third_party/tcmalloc/config_linux.h b/third_party/tcmalloc/config_linux.h
index e813dc5..b359ed5 100644
--- a/third_party/tcmalloc/config_linux.h
+++ b/third_party/tcmalloc/config_linux.h
@@ -31,12 +31,6 @@
*/
#define HAVE_DECL_VALLOC 1
-/* Define to 1 if you prefer to defer decommitting pages
- (on OSes which have ability) which could be performed offline
- (either by background thread or in idle time.)
- */
-#define DEFER_DECOMMIT 1
-
/* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 1
diff --git a/third_party/tcmalloc/config_win.h b/third_party/tcmalloc/config_win.h
index 9bca17b..9f4efa8 100644
--- a/third_party/tcmalloc/config_win.h
+++ b/third_party/tcmalloc/config_win.h
@@ -61,12 +61,6 @@
*/
#undef HAVE_DECL_VALLOC
-/* Define to 1 if you prefer to defer decommitting pages
- (on OSes which have ability) which could be performed offline
- (either by background thread or in idle time.)
- */
-#define DEFER_DECOMMIT 1
-
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H
diff --git a/third_party/tcmalloc/google/malloc_extension.h b/third_party/tcmalloc/google/malloc_extension.h
deleted file mode 100644
index 8264787..0000000
--- a/third_party/tcmalloc/google/malloc_extension.h
+++ /dev/null
@@ -1,239 +0,0 @@
-// Copyright (c) 2005, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// ---
-// Author: Sanjay Ghemawat <opensource@google.com>
-//
-// Extra extensions exported by some malloc implementations. These
-// extensions are accessed through a virtual base class so an
-// application can link against a malloc that does not implement these
-// extensions, and it will get default versions that do nothing.
-//
-// NOTE FOR C USERS: If you wish to use this functionality from within
-// a C program, see malloc_extension_c.h.
-
-#ifndef BASE_MALLOC_EXTENSION_H_
-#define BASE_MALLOC_EXTENSION_H_
-
-#include <stddef.h>
-#include <string>
-
-// Annoying stuff for windows -- makes sure clients can import these functions
-#ifndef PERFTOOLS_DLL_DECL
-# ifdef _WIN32
-# define PERFTOOLS_DLL_DECL __declspec(dllimport)
-# else
-# define PERFTOOLS_DLL_DECL
-# endif
-#endif
-
-static const int kMallocHistogramSize = 64;
-
-// One day, we could support other types of writers (perhaps for C?)
-typedef std::string MallocExtensionWriter;
-
-// The default implementations of the following routines do nothing.
-// All implementations should be thread-safe; the current one
-// (TCMallocImplementation) is.
-class PERFTOOLS_DLL_DECL MallocExtension {
- public:
- virtual ~MallocExtension();
-
- // Call this very early in the program execution -- say, in a global
- // constructor -- to set up parameters and state needed by all
- // instrumented malloc implemenatations. One example: this routine
- // sets environemnt variables to tell STL to use libc's malloc()
- // instead of doing its own memory management. This is safe to call
- // multiple times, as long as each time is before threads start up.
- static void Initialize();
-
- // See "verify_memory.h" to see what these routines do
- virtual bool VerifyAllMemory();
- virtual bool VerifyNewMemory(void* p);
- virtual bool VerifyArrayNewMemory(void* p);
- virtual bool VerifyMallocMemory(void* p);
- virtual bool MallocMemoryStats(int* blocks, size_t* total,
- int histogram[kMallocHistogramSize]);
-
- // Get a human readable description of the current state of the malloc
- // data structures. The state is stored as a null-terminated string
- // in a prefix of "buffer[0,buffer_length-1]".
- // REQUIRES: buffer_length > 0.
- virtual void GetStats(char* buffer, int buffer_length);
-
- // Outputs to "writer" a sample of live objects and the stack traces
- // that allocated these objects. The format of the returned output
- // is equivalent to the output of the heap profiler and can
- // therefore be passed to "pprof".
- virtual void GetHeapSample(MallocExtensionWriter* writer);
-
- // Outputs to "writer" the stack traces that caused growth in the
- // address space size. The format of the returned output is
- // equivalent to the output of the heap profiler and can therefore
- // be passed to "pprof".
- virtual void GetHeapGrowthStacks(MallocExtensionWriter* writer);
-
- // -------------------------------------------------------------------
- // Control operations for getting and setting malloc implementation
- // specific parameters. Some currently useful properties:
- //
- // generic
- // -------
- // "generic.current_allocated_bytes"
- // Number of bytes currently allocated by application
- // This property is not writable.
- //
- // "generic.heap_size"
- // Number of bytes in the heap ==
- // current_allocated_bytes +
- // fragmentation +
- // freed memory regions
- // This property is not writable.
- //
- // tcmalloc
- // --------
- // "tcmalloc.max_total_thread_cache_bytes"
- // Upper limit on total number of bytes stored across all
- // per-thread caches. Default: 16MB.
- //
- // "tcmalloc.current_total_thread_cache_bytes"
- // Number of bytes used across all thread caches.
- // This property is not writable.
- //
- // "tcmalloc.slack_bytes"
- // Number of bytes allocated from system, but not currently
- // in use by malloced objects. I.e., bytes available for
- // allocation without needing more bytes from system.
- // This property is not writable.
- //
- // TODO: Add more properties as necessary
- // -------------------------------------------------------------------
-
- // Get the named "property"'s value. Returns true if the property
- // is known. Returns false if the property is not a valid property
- // name for the current malloc implementation.
- // REQUIRES: property != NULL; value != NULL
- virtual bool GetNumericProperty(const char* property, size_t* value);
-
- // Set the named "property"'s value. Returns true if the property
- // is known and writable. Returns false if the property is not a
- // valid property name for the current malloc implementation, or
- // is not writable.
- // REQUIRES: property != NULL
- virtual bool SetNumericProperty(const char* property, size_t value);
-
- // Mark the current thread as "idle". This routine may optionally
- // be called by threads as a hint to the malloc implementation that
- // any thread-specific resources should be released. Note: this may
- // be an expensive routine, so it should not be called too often.
- //
- // Also, if the code that calls this routine will go to sleep for
- // a while, it should take care to not allocate anything between
- // the call to this routine and the beginning of the sleep.
- //
- // Most malloc implementations ignore this routine.
- virtual void MarkThreadIdle();
-
- // Scavenge at least some resources and free them back to OS.
- // This method doesn't promise to do anything useful (it might be
- // implemented as noop), but it's a good idea to invoke it when
- // application is idle.
- virtual void Scavenge();
-
- // Try to free memory back to the operating system for reuse. Only
- // use this extension if the application has recently freed a lot of
- // memory, and does not anticipate using it again for a long time --
- // to get this memory back may require faulting pages back in by the
- // OS, and that may be slow. (Currently only implemented in
- // tcmalloc.)
- virtual void ReleaseFreeMemory();
-
- // Sets the rate at which we release unused memory to the system.
- // Zero means we never release memory back to the system. Increase
- // this flag to return memory faster; decrease it to return memory
- // slower. Reasonable rates are in the range [0,10]. (Currently
- // only implemented in tcmalloc).
- virtual void SetMemoryReleaseRate(double rate);
-
- // Gets the release rate. Returns a value < 0 if unknown.
- virtual double GetMemoryReleaseRate();
-
- // Returns the estimated number of bytes that will be allocated for
- // a request of "size" bytes. This is an estimate: an allocation of
- // SIZE bytes may reserve more bytes, but will never reserve less.
- // (Currently only implemented in tcmalloc, other implementations
- // always return SIZE.)
- virtual size_t GetEstimatedAllocatedSize(size_t size);
-
- // Returns the actual number of bytes reserved by tcmalloc for the
- // pointer p. This number may be equal to or greater than
- // the number of bytes requested when p was allocated.
- // p must have been allocated by this malloc implementation,
- // must not be an interior pointer -- that is, must be exactly
- // the pointer returned to by malloc() et al., not some offset
- // from that -- and should not have been freed yet. p may be NULL.
- // (Currently only implemented in tcmalloc; other implementations
- // will return 0.)
- virtual size_t GetAllocatedSize(void* p);
-
- // The current malloc implementation. Always non-NULL.
- static MallocExtension* instance();
-
- // Change the malloc implementation. Typically called by the
- // malloc implementation during initialization.
- static void Register(MallocExtension* implementation);
-
- protected:
- // Get a list of stack traces of sampled allocation points. Returns
- // a pointer to a "new[]-ed" result array, and stores the sample
- // period in "sample_period".
- //
- // The state is stored as a sequence of adjacent entries
- // in the returned array. Each entry has the following form:
- // uintptr_t count; // Number of objects with following trace
- // uintptr_t size; // Total size of objects with following trace
- // uintptr_t depth; // Number of PC values in stack trace
- // void* stack[depth]; // PC values that form the stack trace
- //
- // The list of entries is terminated by a "count" of 0.
- //
- // It is the responsibility of the caller to "delete[]" the returned array.
- //
- // May return NULL to indicate no results.
- //
- // This is an internal extension. Callers should use the more
- // convenient "GetHeapSample(string*)" method defined above.
- virtual void** ReadStackTraces(int* sample_period);
-
- // Like ReadStackTraces(), but returns stack traces that caused growth
- // in the address space size.
- virtual void** ReadHeapGrowthStackTraces();
-};
-
-#endif // BASE_MALLOC_EXTENSION_H_
diff --git a/third_party/tcmalloc/malloc_extension.cc b/third_party/tcmalloc/malloc_extension.cc
deleted file mode 100644
index c681c4e..0000000
--- a/third_party/tcmalloc/malloc_extension.cc
+++ /dev/null
@@ -1,326 +0,0 @@
-// Copyright (c) 2005, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// ---
-// Author: Sanjay Ghemawat <opensource@google.com>
-
-#include <config.h>
-#include <assert.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdio.h>
-#if defined HAVE_STDINT_H
-#include <stdint.h>
-#elif defined HAVE_INTTYPES_H
-#include <inttypes.h>
-#else
-#include <sys/types.h>
-#endif
-#include <string>
-#include "base/dynamic_annotations.h"
-#include "base/sysinfo.h" // for FillProcSelfMaps
-#include "google/malloc_extension.h"
-#include "maybe_threads.h"
-
-using STL_NAMESPACE::string;
-
-static void DumpAddressMap(string* result) {
- *result += "\nMAPPED_LIBRARIES:\n";
- // We keep doubling until we get a fit
- const size_t old_resultlen = result->size();
- for (int amap_size = 10240; amap_size < 10000000; amap_size *= 2) {
- result->resize(old_resultlen + amap_size);
- const int bytes_written =
- tcmalloc::FillProcSelfMaps(&((*result)[old_resultlen]), amap_size);
- if (bytes_written < amap_size - 1) { // we fit!
- (*result)[old_resultlen + bytes_written] = '\0';
- result->resize(old_resultlen + bytes_written);
- return;
- }
- }
- result->reserve(old_resultlen); // just don't print anything
-}
-
-// Note: this routine is meant to be called before threads are spawned.
-void MallocExtension::Initialize() {
- static bool initialize_called = false;
-
- if (initialize_called) return;
- initialize_called = true;
-
-#ifdef __GLIBC__
- // GNU libc++ versions 3.3 and 3.4 obey the environment variables
- // GLIBCPP_FORCE_NEW and GLIBCXX_FORCE_NEW respectively. Setting
- // one of these variables forces the STL default allocator to call
- // new() or delete() for each allocation or deletion. Otherwise
- // the STL allocator tries to avoid the high cost of doing
- // allocations by pooling memory internally. However, tcmalloc
- // does allocations really fast, especially for the types of small
- // items one sees in STL, so it's better off just using us.
- // TODO: control whether we do this via an environment variable?
- setenv("GLIBCPP_FORCE_NEW", "1", false /* no overwrite*/);
- setenv("GLIBCXX_FORCE_NEW", "1", false /* no overwrite*/);
-
- // Now we need to make the setenv 'stick', which it may not do since
- // the env is flakey before main() is called. But luckily stl only
- // looks at this env var the first time it tries to do an alloc, and
- // caches what it finds. So we just cause an stl alloc here.
- string dummy("I need to be allocated");
- dummy += "!"; // so the definition of dummy isn't optimized out
-#endif /* __GLIBC__ */
-}
-
-// Default implementation -- does nothing
-MallocExtension::~MallocExtension() { }
-bool MallocExtension::VerifyAllMemory() { return true; }
-bool MallocExtension::VerifyNewMemory(void* p) { return true; }
-bool MallocExtension::VerifyArrayNewMemory(void* p) { return true; }
-bool MallocExtension::VerifyMallocMemory(void* p) { return true; }
-
-bool MallocExtension::GetNumericProperty(const char* property, size_t* value) {
- return false;
-}
-
-bool MallocExtension::SetNumericProperty(const char* property, size_t value) {
- return false;
-}
-
-void MallocExtension::GetStats(char* buffer, int length) {
- assert(length > 0);
- buffer[0] = '\0';
-}
-
-bool MallocExtension::MallocMemoryStats(int* blocks, size_t* total,
- int histogram[kMallocHistogramSize]) {
- *blocks = 0;
- *total = 0;
- memset(histogram, 0, sizeof(histogram));
- return true;
-}
-
-void** MallocExtension::ReadStackTraces(int* sample_period) {
- return NULL;
-}
-
-void** MallocExtension::ReadHeapGrowthStackTraces() {
- return NULL;
-}
-
-void MallocExtension::MarkThreadIdle() {
- // Default implementation does nothing
-}
-
-void MallocExtension::ReleaseFreeMemory() {
- // Default implementation does nothing
-}
-
-void MallocExtension::Scavenge() {
- // Default implementation does nothing
-}
-
-void MallocExtension::SetMemoryReleaseRate(double rate) {
- // Default implementation does nothing
-}
-
-double MallocExtension::GetMemoryReleaseRate() {
- return -1.0;
-}
-
-size_t MallocExtension::GetEstimatedAllocatedSize(size_t size) {
- return size;
-}
-
-size_t MallocExtension::GetAllocatedSize(void* p) {
- return 0;
-}
-
-// The current malloc extension object. We also keep a pointer to
-// the default implementation so that the heap-leak checker does not
-// complain about a memory leak.
-
-static pthread_once_t module_init = PTHREAD_ONCE_INIT;
-static MallocExtension* default_instance = NULL;
-static MallocExtension* current_instance = NULL;
-
-static void InitModule() {
- default_instance = new MallocExtension;
- current_instance = default_instance;
-}
-
-MallocExtension* MallocExtension::instance() {
- perftools_pthread_once(&module_init, InitModule);
- return current_instance;
-}
-
-void MallocExtension::Register(MallocExtension* implementation) {
- perftools_pthread_once(&module_init, InitModule);
- // When running under valgrind, our custom malloc is replaced with
- // valgrind's one and malloc extensions will not work.
- if (!RunningOnValgrind()) {
- current_instance = implementation;
- }
-}
-
-// -----------------------------------------------------------------------
-// Heap sampling support
-// -----------------------------------------------------------------------
-
-namespace {
-
-// Accessors
-uintptr_t Count(void** entry) {
- return reinterpret_cast<uintptr_t>(entry[0]);
-}
-uintptr_t Size(void** entry) {
- return reinterpret_cast<uintptr_t>(entry[1]);
-}
-uintptr_t Depth(void** entry) {
- return reinterpret_cast<uintptr_t>(entry[2]);
-}
-void* PC(void** entry, int i) {
- return entry[3+i];
-}
-
-void PrintCountAndSize(MallocExtensionWriter* writer,
- uintptr_t count, uintptr_t size) {
- char buf[100];
- snprintf(buf, sizeof(buf),
- "%6lld: %8lld [%6lld: %8lld] @",
- static_cast<long long>(count),
- static_cast<long long>(size),
- static_cast<long long>(count),
- static_cast<long long>(size));
- writer->append(buf, strlen(buf));
-}
-
-void PrintHeader(MallocExtensionWriter* writer,
- const char* label, void** entries) {
- // Compute the total count and total size
- uintptr_t total_count = 0;
- uintptr_t total_size = 0;
- for (void** entry = entries; Count(entry) != 0; entry += 3 + Depth(entry)) {
- total_count += Count(entry);
- total_size += Size(entry);
- }
-
- const char* const kTitle = "heap profile: ";
- writer->append(kTitle, strlen(kTitle));
- PrintCountAndSize(writer, total_count, total_size);
- writer->append(" ", 1);
- writer->append(label, strlen(label));
- writer->append("\n", 1);
-}
-
-void PrintStackEntry(MallocExtensionWriter* writer, void** entry) {
- PrintCountAndSize(writer, Count(entry), Size(entry));
-
- for (int i = 0; i < Depth(entry); i++) {
- char buf[32];
- snprintf(buf, sizeof(buf), " %p", PC(entry, i));
- writer->append(buf, strlen(buf));
- }
- writer->append("\n", 1);
-}
-
-}
-
-void MallocExtension::GetHeapSample(MallocExtensionWriter* writer) {
- int sample_period = 0;
- void** entries = ReadStackTraces(&sample_period);
- if (entries == NULL) {
- const char* const kErrorMsg =
- "This malloc implementation does not support sampling.\n"
- "As of 2005/01/26, only tcmalloc supports sampling, and\n"
- "you are probably running a binary that does not use\n"
- "tcmalloc.\n";
- writer->append(kErrorMsg, strlen(kErrorMsg));
- return;
- }
-
- char label[32];
- sprintf(label, "heap_v2/%d", sample_period);
- PrintHeader(writer, label, entries);
- for (void** entry = entries; Count(entry) != 0; entry += 3 + Depth(entry)) {
- PrintStackEntry(writer, entry);
- }
- delete[] entries;
-
- DumpAddressMap(writer);
-}
-
-void MallocExtension::GetHeapGrowthStacks(MallocExtensionWriter* writer) {
- void** entries = ReadHeapGrowthStackTraces();
- if (entries == NULL) {
- const char* const kErrorMsg =
- "This malloc implementation does not support "
- "ReadHeapGrowthStackTraces().\n"
- "As of 2005/09/27, only tcmalloc supports this, and you\n"
- "are probably running a binary that does not use tcmalloc.\n";
- writer->append(kErrorMsg, strlen(kErrorMsg));
- return;
- }
-
- // Do not canonicalize the stack entries, so that we get a
- // time-ordered list of stack traces, which may be useful if the
- // client wants to focus on the latest stack traces.
- PrintHeader(writer, "growth", entries);
- for (void** entry = entries; Count(entry) != 0; entry += 3 + Depth(entry)) {
- PrintStackEntry(writer, entry);
- }
- delete[] entries;
-
- DumpAddressMap(writer);
-}
-
-// These are C shims that work on the current instance.
-
-#define C_SHIM(fn, retval, paramlist, arglist) \
- extern "C" PERFTOOLS_DLL_DECL retval MallocExtension_##fn paramlist { \
- return MallocExtension::instance()->fn arglist; \
- }
-
-C_SHIM(VerifyAllMemory, bool, (), ());
-C_SHIM(VerifyNewMemory, bool, (void* p), (p));
-C_SHIM(VerifyArrayNewMemory, bool, (void* p), (p));
-C_SHIM(VerifyMallocMemory, bool, (void* p), (p));
-C_SHIM(MallocMemoryStats, bool,
- (int* blocks, size_t* total, int histogram[kMallocHistogramSize]),
- (blocks, total, histogram));
-
-C_SHIM(GetStats, void,
- (char* buffer, int buffer_length), (buffer, buffer_length));
-C_SHIM(GetNumericProperty, bool,
- (const char* property, size_t* value), (property, value));
-C_SHIM(SetNumericProperty, bool,
- (const char* property, size_t value), (property, value));
-
-C_SHIM(MarkThreadIdle, void, (), ());
-C_SHIM(ReleaseFreeMemory, void, (), ());
-C_SHIM(GetEstimatedAllocatedSize, size_t, (size_t size), (size));
-C_SHIM(GetAllocatedSize, size_t, (void* p), (p));
diff --git a/third_party/tcmalloc/page_heap.cc b/third_party/tcmalloc/page_heap.cc
index 7e54bf5..f9ffd9d 100644
--- a/third_party/tcmalloc/page_heap.cc
+++ b/third_party/tcmalloc/page_heap.cc
@@ -51,12 +51,7 @@ PageHeap::PageHeap()
pagemap_cache_(0),
free_pages_(0),
system_bytes_(0),
-#if DEFER_DECOMMIT
- free_committed_pages_(0),
- pages_committed_since_last_scavenge_(0),
-#else
scavenge_counter_(0),
-#endif
// Start scavenging at kMaxPages list
scavenge_index_(kMaxPages-1) {
COMPILE_ASSERT(kNumClasses <= (1 << PageMapCache::kValuebits), valuebits);
@@ -160,9 +155,6 @@ void PageHeap::CommitSpan(Span* span) {
reinterpret_cast<void*>(span->start << kPageShift),
static_cast<size_t>(span->length << kPageShift)
);
-#if DEFER_DECOMMIT
- pages_committed_since_last_scavenge_ += span->length;
-#endif
}
Span* PageHeap::Carve(Span* span, Length n) {
@@ -193,13 +185,6 @@ Span* PageHeap::Carve(Span* span, Length n) {
if (old_location == Span::ON_RETURNED_FREELIST) {
// We need to recommit this address space.
CommitSpan(span);
- } else {
-#if DEFER_DECOMMIT
- // The newly allocated memory is from a span that's already committed.
- // Update the free_committed_pages_ count.
- ASSERT(free_committed_pages_ >= n);
- free_committed_pages_ -= n;
-#endif
}
ASSERT(span->location == Span::IN_USE);
ASSERT(span->length == n);
@@ -235,9 +220,6 @@ void PageHeap::Delete(Span* span) {
const Length len = prev->length;
if (prev->location == Span::ON_RETURNED_FREELIST) {
CommitSpan(prev);
-#if DEFER_DECOMMIT
- free_committed_pages_ += len;
-#endif
}
DLL_Remove(prev);
DeleteSpan(prev);
@@ -253,9 +235,6 @@ void PageHeap::Delete(Span* span) {
const Length len = next->length;
if (next->location == Span::ON_RETURNED_FREELIST) {
CommitSpan(next);
-#if DEFER_DECOMMIT
- free_committed_pages_ += len;
-#endif
}
DLL_Remove(next);
DeleteSpan(next);
@@ -266,92 +245,17 @@ void PageHeap::Delete(Span* span) {
Event(span, 'D', span->length);
span->location = Span::ON_NORMAL_FREELIST;
- if (span->length < kMaxPages)
+ if (span->length < kMaxPages) {
DLL_Prepend(&free_[span->length].normal, span);
- else
+ } else {
DLL_Prepend(&large_.normal, span);
+ }
free_pages_ += n;
-#if DEFER_DECOMMIT
- free_committed_pages_ += n;
-#endif
-#if DEFER_DECOMMIT
- // TODO(antonm): notify that could start scavenging
-#else
IncrementalScavenge(n);
-#endif
ASSERT(Check());
}
-
-void PageHeap::Scavenge() {
-#if DEFER_DECOMMIT
- // If we have to commit memory since the last scavenge, it means we don't
- // have enough free committed pages of necessary size for the amount of
- // allocations that we do. So hold off on releasing memory back to the system.
- if (pages_committed_since_last_scavenge_ > 0) {
- pages_committed_since_last_scavenge_ = 0;
- return;
- }
-
- if (free_committed_pages_ <= kMinimumFreeCommittedPageCount) {
- return;
- }
-
- uint64_t to_decommit = std::min(
- free_committed_pages_ - kMinimumFreeCommittedPageCount,
- free_committed_pages_ / kMaxScavengeAmountFactor);
- to_decommit = DecommitFromSpanList(&large_, to_decommit);
- for (int i = kMaxPages - 1; i >= 0; i--) {
- to_decommit = DecommitFromSpanList(&free_[i], to_decommit);
- }
-
- // Force at least one decommit from large list, otherwise big sized blocks
- // sitting might block as from releasing smaller blocks behind.
- if (to_decommit > 0) {
- if (!DLL_IsEmpty(&large_.normal)) {
- DecommitLastSpan(&large_, large_.normal.prev);
- }
- }
-#endif
-}
-
-#if DEFER_DECOMMIT
-Length PageHeap::DecommitLastSpan(SpanList* span_list, Span* span) {
- ASSERT(!DLL_IsEmpty(&span_list->normal));
- ASSERT(span_list->normal.prev == span);
-
- Length length = span->length;
-
- DLL_Remove(span);
-
- TCMalloc_SystemRelease(reinterpret_cast<void*>(span->start << kPageShift), span->length << kPageShift);
- span->location = Span::ON_RETURNED_FREELIST;
- ASSERT(free_committed_pages_ >= length);
- free_committed_pages_ -= length;
-
- DLL_Prepend(&span_list->returned, span);
-
- return length;
-}
-
-uint64_t PageHeap::DecommitFromSpanList(SpanList* span_list, uint64_t to_decommit) {
- while (!DLL_IsEmpty(&span_list->normal)) {
- // Release the last span on the normal portion of this list.
- Span* span = span_list->normal.prev;
-
- if (span->length > to_decommit) {
- return to_decommit;
- }
-
- to_decommit -= DecommitLastSpan(span_list, span);
- }
-
- return to_decommit;
-}
-
-#else
-
void PageHeap::IncrementalScavenge(Length n) {
// Fast path; not yet time to release memory
scavenge_counter_ -= n;
@@ -411,7 +315,6 @@ void PageHeap::IncrementalScavenge(Length n) {
// Nothing to scavenge, delay for a while
scavenge_counter_ = kDefaultReleaseDelay;
}
-#endif
void PageHeap::RegisterSizeClass(Span* span, size_t sc) {
// Associate span object with all interior pages as well
@@ -513,9 +416,6 @@ bool PageHeap::GrowHeap(Length n) {
if (ptr == NULL) return false;
}
ask = actual_size >> kPageShift;
-#if DEFER_DECOMMIT
- pages_committed_since_last_scavenge_ += ask;
-#endif
RecordGrowth(ask << kPageShift);
uint64_t old_system_bytes = system_bytes_;
@@ -601,9 +501,6 @@ void PageHeap::ReleaseFreePages() {
}
ReleaseFreeList(&large_.normal, &large_.returned);
ASSERT(Check());
-#if DEFER_DECOMMIT
- free_committed_pages_ = 0;
-#endif
}
} // namespace tcmalloc
diff --git a/third_party/tcmalloc/page_heap.h b/third_party/tcmalloc/page_heap.h
index 242623b..8d9822c 100644
--- a/third_party/tcmalloc/page_heap.h
+++ b/third_party/tcmalloc/page_heap.h
@@ -48,7 +48,6 @@
# include <google/stacktrace.h>
#endif
-
namespace tcmalloc {
// -------------------------------------------------------------------------
@@ -146,9 +145,6 @@ class PageHeap {
}
void CacheSizeClass(PageID p, size_t cl) const { pagemap_cache_.Put(p, cl); }
- // Attempt to free some free pages currently not used.
- void Scavenge();
-
private:
// Allocates a big block of memory for the pagemap once we reach more than
// 128MB
@@ -214,41 +210,15 @@ class PageHeap {
// span of exactly the specified length. Else, returns NULL.
Span* AllocLarge(Length n);
- // Commits the span.
+ // Commit the span.
void CommitSpan(Span* span);
-#if DEFER_DECOMMIT
- // Number of free committed pages that we want to keep around.
- static const size_t kMinimumFreeCommittedPageCount = 512; // 2M (2 ** 21) for 4K pages
-
- // During a scavenge, we'll release up to a fraction of the free committed pages.
-#ifdef _WIN32
- // We are slightly less aggressive in releasing memory on Windows due to performance reasons.
- static const int kMaxScavengeAmountFactor = 3;
-#else
- static const int kMaxScavengeAmountFactor = 2;
-#endif
-
- // Decommits some parts from SpanList.
- uint64_t DecommitFromSpanList(SpanList* span_list, uint64_t to_decommit);
-
- // Decommits some parts from SpanList.
- Length DecommitLastSpan(SpanList* span_list, Span* span);
-
- // Number of pages kept in free lists that are still committed a.k.a. total
- // number of pages in "normal" lists.
- uint64_t free_committed_pages_;
-
- // Number of pages that we commited in the last scavenge wait interval.
- uint64_t pages_committed_since_last_scavenge_;
-#else
// Incrementally release some memory to the system.
// IncrementalScavenge(n) is called whenever n pages are freed.
void IncrementalScavenge(Length n);
// Number of pages to deallocate before doing more scavenging
int64_t scavenge_counter_;
-#endif
// Index of last free list we scavenged
int scavenge_index_;
diff --git a/third_party/tcmalloc/tcmalloc.cc b/third_party/tcmalloc/tcmalloc.cc
index 6853eba..e3bbb81 100644
--- a/third_party/tcmalloc/tcmalloc.cc
+++ b/third_party/tcmalloc/tcmalloc.cc
@@ -616,11 +616,6 @@ class TCMallocImplementation : public MallocExtension {
Static::pageheap()->ReleaseFreePages();
}
- virtual void Scavenge() {
- SpinLockHolder h(Static::pageheap_lock());
- Static::pageheap()->Scavenge();
- }
-
virtual void SetMemoryReleaseRate(double rate) {
FLAGS_tcmalloc_release_rate = rate;
}
diff --git a/third_party/tcmalloc/tcmalloc.gyp b/third_party/tcmalloc/tcmalloc.gyp
index ee06a98..f53e730 100644
--- a/third_party/tcmalloc/tcmalloc.gyp
+++ b/third_party/tcmalloc/tcmalloc.gyp
@@ -76,6 +76,8 @@
'tcmalloc/src/linked_list.h',
'tcmalloc/src/malloc_hook.cc',
'tcmalloc/src/malloc_hook-inl.h',
+ 'tcmalloc/src/malloc_extension.cc',
+ 'tcmalloc/src/google/malloc_extension.h',
'tcmalloc/src/page_heap.cc',
'tcmalloc/src/page_heap.h',
'tcmalloc/src/port.h',
@@ -123,8 +125,6 @@
# tcmalloc forked files
'allocator_shim.cc',
'generic_allocators.cc',
- 'malloc_extension.cc',
- 'google/malloc_extension.h',
'page_heap.cc',
'page_heap.h',
'port.cc',
@@ -146,8 +146,6 @@
'generic_allocators.cc',
'tcmalloc.cc',
'win_allocator.cc',
- 'tcmalloc/src/malloc_extension.cc',
- 'tcmalloc/src/google/malloc_extension.h',
],
'msvs_settings': {
# TODO(sgk): merge this with build/common.gypi settings