Index: third_party/tcmalloc/chromium/src/page_heap.cc |
=================================================================== |
--- third_party/tcmalloc/chromium/src/page_heap.cc (revision 87277) |
+++ third_party/tcmalloc/chromium/src/page_heap.cc (working copy) |
@@ -31,11 +31,17 @@ |
// Author: Sanjay Ghemawat <opensource@google.com> |
#include <config.h> |
-#include "page_heap.h" |
+#ifdef HAVE_INTTYPES_H |
+#include <inttypes.h> // for PRIuPTR |
antonm
2011/06/02 13:37:35
I'd suggest to unify indenting: either fixed one o
Alexander Potapenko
2011/06/09 09:35:24
I think this line was merged automatically: http:/
|
+#endif |
+#include <google/malloc_extension.h> // for MallocRange, etc |
+#include "base/basictypes.h" |
+#include "base/commandlineflags.h" |
+#include "internal_logging.h" // for ASSERT, TCMalloc_Printer, etc |
+#include "page_heap_allocator.h" // for PageHeapAllocator |
+#include "static_vars.h" // for Static |
+#include "system-alloc.h" // for TCMalloc_SystemAlloc, etc |
-#include "static_vars.h" |
-#include "system-alloc.h" |
- |
DEFINE_double(tcmalloc_release_rate, |
EnvToDouble("TCMALLOC_RELEASE_RATE", 1.0), |
"Rate at which we release unused memory to the system. " |
@@ -61,7 +67,7 @@ |
} |
} |
-Span* PageHeap::New(Length n) { |
+Span* PageHeap::SearchFreeAndLargeLists(Length n) { |
ASSERT(Check()); |
ASSERT(n > 0); |
@@ -79,20 +85,26 @@ |
ASSERT(ll->next->location == Span::ON_RETURNED_FREELIST); |
return Carve(ll->next, n); |
} |
- // Still no luck, so keep looking in larger classes. |
} |
+ // No luck in free lists, our last chance is in a larger class. |
+ return AllocLarge(n); // May be NULL |
+} |
- Span* result = AllocLarge(n); |
- if (result != NULL) return result; |
+Span* PageHeap::New(Length n) { |
+ ASSERT(Check()); |
+ ASSERT(n > 0); |
- // Grow the heap and try again |
+ Span* result = SearchFreeAndLargeLists(n); |
+ if (result != NULL) |
+ return result; |
+ |
+ // Grow the heap and try again. |
if (!GrowHeap(n)) { |
ASSERT(stats_.unmapped_bytes+ stats_.committed_bytes==stats_.system_bytes); |
ASSERT(Check()); |
return NULL; |
} |
- |
- return AllocLarge(n); |
+ return SearchFreeAndLargeLists(n); |
} |
Span* PageHeap::AllocLarge(Length n) { |
@@ -391,14 +403,43 @@ |
} |
} |
-static double MB(uint64_t bytes) { |
+static double MiB(uint64_t bytes) { |
return bytes / 1048576.0; |
} |
-static double PagesToMB(uint64_t pages) { |
+static double PagesToMiB(uint64_t pages) { |
return (pages << kPageShift) / 1048576.0; |
} |
+void PageHeap::GetClassSizes(int64 class_sizes_normal[kMaxPages], |
+ int64 class_sizes_returned[kMaxPages], |
+ int64* normal_pages_in_spans, |
+ int64* returned_pages_in_spans) { |
+ |
+ for (int s = 0; s < kMaxPages; s++) { |
+ if (class_sizes_normal != NULL) { |
+ class_sizes_normal[s] = DLL_Length(&free_[s].normal); |
+ } |
+ if (class_sizes_returned != NULL) { |
+ class_sizes_returned[s] = DLL_Length(&free_[s].returned); |
+ } |
+ } |
+ |
+ if (normal_pages_in_spans != NULL) { |
+ *normal_pages_in_spans = 0; |
+ for (Span* s = large_.normal.next; s != &large_.normal; s = s->next) { |
+ *normal_pages_in_spans += s->length;; |
+ } |
+ } |
+ |
+ if (returned_pages_in_spans != NULL) { |
+ *returned_pages_in_spans = 0; |
+ for (Span* s = large_.returned.next; s != &large_.returned; s = s->next) { |
+ *returned_pages_in_spans += s->length; |
+ } |
+ } |
+} |
+ |
void PageHeap::Dump(TCMalloc_Printer* out) { |
int nonempty_sizes = 0; |
for (int s = 0; s < kMaxPages; s++) { |
@@ -407,8 +448,9 @@ |
} |
} |
out->printf("------------------------------------------------\n"); |
- out->printf("PageHeap: %d sizes; %6.1f MB free; %6.1f MB unmapped\n", |
- nonempty_sizes, MB(stats_.free_bytes), MB(stats_.unmapped_bytes)); |
+ out->printf("PageHeap: %d sizes; %6.1f MiB free; %6.1f MiB unmapped\n", |
+ nonempty_sizes, MiB(stats_.free_bytes), |
+ MiB(stats_.unmapped_bytes)); |
out->printf("------------------------------------------------\n"); |
uint64_t total_normal = 0; |
uint64_t total_returned = 0; |
@@ -420,14 +462,14 @@ |
uint64_t r_pages = s * r_length; |
total_normal += n_pages; |
total_returned += r_pages; |
- out->printf("%6u pages * %6u spans ~ %6.1f MB; %6.1f MB cum" |
- "; unmapped: %6.1f MB; %6.1f MB cum\n", |
+ out->printf("%6u pages * %6u spans ~ %6.1f MiB; %6.1f MiB cum" |
+ "; unmapped: %6.1f MiB; %6.1f MiB cum\n", |
s, |
(n_length + r_length), |
- PagesToMB(n_pages + r_pages), |
- PagesToMB(total_normal + total_returned), |
- PagesToMB(r_pages), |
- PagesToMB(total_returned)); |
+ PagesToMiB(n_pages + r_pages), |
+ PagesToMiB(total_normal + total_returned), |
+ PagesToMiB(r_pages), |
+ PagesToMiB(total_returned)); |
} |
} |
@@ -437,27 +479,27 @@ |
int r_spans = 0; |
out->printf("Normal large spans:\n"); |
for (Span* s = large_.normal.next; s != &large_.normal; s = s->next) { |
- out->printf(" [ %6" PRIuPTR " pages ] %6.1f MB\n", |
- s->length, PagesToMB(s->length)); |
+ out->printf(" [ %6" PRIuPTR " pages ] %6.1f MiB\n", |
+ s->length, PagesToMiB(s->length)); |
n_pages += s->length; |
n_spans++; |
} |
out->printf("Unmapped large spans:\n"); |
for (Span* s = large_.returned.next; s != &large_.returned; s = s->next) { |
- out->printf(" [ %6" PRIuPTR " pages ] %6.1f MB\n", |
- s->length, PagesToMB(s->length)); |
+ out->printf(" [ %6" PRIuPTR " pages ] %6.1f MiB\n", |
+ s->length, PagesToMiB(s->length)); |
r_pages += s->length; |
r_spans++; |
} |
total_normal += n_pages; |
total_returned += r_pages; |
- out->printf(">255 large * %6u spans ~ %6.1f MB; %6.1f MB cum" |
- "; unmapped: %6.1f MB; %6.1f MB cum\n", |
+ out->printf(">255 large * %6u spans ~ %6.1f MiB; %6.1f MiB cum" |
+ "; unmapped: %6.1f MiB; %6.1f MiB cum\n", |
(n_spans + r_spans), |
- PagesToMB(n_pages + r_pages), |
- PagesToMB(total_normal + total_returned), |
- PagesToMB(r_pages), |
- PagesToMB(total_returned)); |
+ PagesToMiB(n_pages + r_pages), |
+ PagesToMiB(total_normal + total_returned), |
+ PagesToMiB(r_pages), |
+ PagesToMiB(total_returned)); |
} |
bool PageHeap::GetNextRange(PageID start, base::MallocRange* r) { |