diff options
author | jar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-05 17:58:51 +0000 |
---|---|---|
committer | jar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-05 17:58:51 +0000 |
commit | aef4f1be3eec2059a7c6e2c106050a5f3d6ccf12 (patch) | |
tree | 8e2c94cb76ac4b87a9b72f2e036f82f0c1683fa3 /third_party/tcmalloc | |
parent | bc77765e44ca594f4b2501db7a7c7411220552a9 (diff) | |
download | chromium_src-aef4f1be3eec2059a7c6e2c106050a5f3d6ccf12.zip chromium_src-aef4f1be3eec2059a7c6e2c106050a5f3d6ccf12.tar.gz chromium_src-aef4f1be3eec2059a7c6e2c106050a5f3d6ccf12.tar.bz2 |
Revert further back to MBelshe's baseline forking TCMalloc
This changes to decommitting in all paths through the
page_heap delete method (which adds spans to the free lists).
r=mbelshe,jamesr
Review URL: http://codereview.chromium.org/255067
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28006 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/tcmalloc')
-rw-r--r-- | third_party/tcmalloc/page_heap.cc | 48 | ||||
-rw-r--r-- | third_party/tcmalloc/page_heap.h | 3 |
2 files changed, 32 insertions, 19 deletions
diff --git a/third_party/tcmalloc/page_heap.cc b/third_party/tcmalloc/page_heap.cc index f9ffd9d..b46e728 100644 --- a/third_party/tcmalloc/page_heap.cc +++ b/third_party/tcmalloc/page_heap.cc @@ -151,10 +151,13 @@ Span* PageHeap::Split(Span* span, Length n) { } void PageHeap::CommitSpan(Span* span) { - TCMalloc_SystemCommit( - reinterpret_cast<void*>(span->start << kPageShift), - static_cast<size_t>(span->length << kPageShift) - ); + TCMalloc_SystemCommit(reinterpret_cast<void*>(span->start << kPageShift), + static_cast<size_t>(span->length << kPageShift)); +} + +void PageHeap::DecommitSpan(Span* span) { + TCMalloc_SystemRelease(reinterpret_cast<void*>(span->start << kPageShift), + static_cast<size_t>(span->length << kPageShift)); } Span* PageHeap::Carve(Span* span, Length n) { @@ -182,14 +185,14 @@ Span* PageHeap::Carve(Span* span, Length n) { span->length = n; pagemap_.set(span->start + n - 1, span); } + ASSERT(Check()); + free_pages_ -= n; if (old_location == Span::ON_RETURNED_FREELIST) { // We need to recommit this address space. CommitSpan(span); } ASSERT(span->location == Span::IN_USE); ASSERT(span->length == n); - ASSERT(Check()); - free_pages_ -= n; return span; } @@ -207,10 +210,22 @@ void PageHeap::Delete(Span* span) { // entries for the pieces we are merging together because we only // care about the pagemap entries for the boundaries. // - // Note that the spans we merge into "span" may come out of - // a "returned" list. We move those into "normal" list - // as for 'immediate' operations we favour committing over - // decommitting (decommitting is performed offline). + // Note that the adjacent spans we merge into "span" may come out of a + // "normal" (committed) list, and cleanly merge with our IN_USE span, which + // is implicitly committed. If the adjacents spans are on the "returned" + // (decommitted) list, then we must get both spans into the same state before + // or after we coalesce them. The current code always decomits. This is + // achieved by blindly decommitting the entire coalesced region, which may + // include any combination of committed and decommitted spans, at the end of + // the method. + + // TODO(jar): "Always decommit" causes some extra calls to commit when we are + // called in GrowHeap() during an allocation :-/. We need to eval the cost of + // that oscillation, and possibly do something to reduce it. + + // TODO(jar): We need a better strategy for deciding to commit, or decommit, + // based on memory usage and free heap sizes. + const PageID p = span->start; const Length n = span->length; Span* prev = GetDescriptor(p-1); @@ -218,9 +233,6 @@ void PageHeap::Delete(Span* span) { // Merge preceding span into this span ASSERT(prev->start + prev->length == p); const Length len = prev->length; - if (prev->location == Span::ON_RETURNED_FREELIST) { - CommitSpan(prev); - } DLL_Remove(prev); DeleteSpan(prev); span->start -= len; @@ -233,9 +245,6 @@ void PageHeap::Delete(Span* span) { // Merge next span into this span ASSERT(next->start == p+n); const Length len = next->length; - if (next->location == Span::ON_RETURNED_FREELIST) { - CommitSpan(next); - } DLL_Remove(next); DeleteSpan(next); span->length += len; @@ -244,11 +253,12 @@ void PageHeap::Delete(Span* span) { } Event(span, 'D', span->length); - span->location = Span::ON_NORMAL_FREELIST; + span->location = Span::ON_RETURNED_FREELIST; + DecommitSpan(span); if (span->length < kMaxPages) { - DLL_Prepend(&free_[span->length].normal, span); + DLL_Prepend(&free_[span->length].returned, span); } else { - DLL_Prepend(&large_.normal, span); + DLL_Prepend(&large_.returned, span); } free_pages_ += n; diff --git a/third_party/tcmalloc/page_heap.h b/third_party/tcmalloc/page_heap.h index 8d9822c..aec933d 100644 --- a/third_party/tcmalloc/page_heap.h +++ b/third_party/tcmalloc/page_heap.h @@ -213,6 +213,9 @@ class PageHeap { // Commit the span. void CommitSpan(Span* span); + // Decommit the span. + void DecommitSpan(Span* span); + // Incrementally release some memory to the system. // IncrementalScavenge(n) is called whenever n pages are freed. void IncrementalScavenge(Length n); |