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 20 matching lines...) Expand all Loading... |
31 // Author: Sanjay Ghemawat <opensource@google.com> | 31 // Author: Sanjay Ghemawat <opensource@google.com> |
32 | 32 |
33 #ifndef TCMALLOC_PAGE_HEAP_H_ | 33 #ifndef TCMALLOC_PAGE_HEAP_H_ |
34 #define TCMALLOC_PAGE_HEAP_H_ | 34 #define TCMALLOC_PAGE_HEAP_H_ |
35 | 35 |
36 #include <config.h> | 36 #include <config.h> |
37 #include <stddef.h> // for size_t | 37 #include <stddef.h> // for size_t |
38 #ifdef HAVE_STDINT_H | 38 #ifdef HAVE_STDINT_H |
39 #include <stdint.h> // for uint64_t, int64_t, uint16_t | 39 #include <stdint.h> // for uint64_t, int64_t, uint16_t |
40 #endif | 40 #endif |
41 #include <google/malloc_extension.h> | 41 #include <gperftools/malloc_extension.h> |
42 #include "base/basictypes.h" | 42 #include "base/basictypes.h" |
43 #include "common.h" | 43 #include "common.h" |
44 #include "packed-cache-inl.h" | 44 #include "packed-cache-inl.h" |
45 #include "pagemap.h" | 45 #include "pagemap.h" |
46 #include "span.h" | 46 #include "span.h" |
47 | 47 |
48 // We need to dllexport PageHeap just for the unittest. MSVC complains | 48 // We need to dllexport PageHeap just for the unittest. MSVC complains |
49 // that we don't dllexport the PageHeap members, but we don't need to | 49 // that we don't dllexport the PageHeap members, but we don't need to |
50 // test those, so I just suppress this warning. | 50 // test those, so I just suppress this warning. |
51 #ifdef _MSC_VER | 51 #ifdef _MSC_VER |
52 #pragma warning(push) | 52 #pragma warning(push) |
53 #pragma warning(disable:4251) | 53 #pragma warning(disable:4251) |
54 #endif | 54 #endif |
55 | 55 |
56 // This #ifdef should almost never be set. Set NO_TCMALLOC_SAMPLES if | 56 // This #ifdef should almost never be set. Set NO_TCMALLOC_SAMPLES if |
57 // you're porting to a system where you really can't get a stacktrace. | 57 // you're porting to a system where you really can't get a stacktrace. |
58 // Because we control the definition of GetStackTrace, all clients of | 58 // Because we control the definition of GetStackTrace, all clients of |
59 // GetStackTrace should #include us rather than stacktrace.h. | 59 // GetStackTrace should #include us rather than stacktrace.h. |
60 #ifdef NO_TCMALLOC_SAMPLES | 60 #ifdef NO_TCMALLOC_SAMPLES |
61 // We use #define so code compiles even if you #include stacktrace.h somehow. | 61 // We use #define so code compiles even if you #include stacktrace.h somehow. |
62 # define GetStackTrace(stack, depth, skip) (0) | 62 # define GetStackTrace(stack, depth, skip) (0) |
63 #else | 63 #else |
64 # include <google/stacktrace.h> | 64 # include <gperftools/stacktrace.h> |
65 #endif | 65 #endif |
66 | 66 |
67 class TCMalloc_Printer; | |
68 namespace base { | 67 namespace base { |
69 struct MallocRange; | 68 struct MallocRange; |
70 } | 69 } |
71 | 70 |
72 namespace tcmalloc { | 71 namespace tcmalloc { |
73 | 72 |
74 // ------------------------------------------------------------------------- | 73 // ------------------------------------------------------------------------- |
75 // Map from page-id to per-page data | 74 // Map from page-id to per-page data |
76 // ------------------------------------------------------------------------- | 75 // ------------------------------------------------------------------------- |
77 | 76 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 // REQUIRES: span->location == IN_USE | 129 // REQUIRES: span->location == IN_USE |
131 // REQUIRES: span->sizeclass == 0 | 130 // REQUIRES: span->sizeclass == 0 |
132 Span* Split(Span* span, Length n); | 131 Span* Split(Span* span, Length n); |
133 | 132 |
134 // Return the descriptor for the specified page. Returns NULL if | 133 // Return the descriptor for the specified page. Returns NULL if |
135 // this PageID was not allocated previously. | 134 // this PageID was not allocated previously. |
136 inline Span* GetDescriptor(PageID p) const { | 135 inline Span* GetDescriptor(PageID p) const { |
137 return reinterpret_cast<Span*>(pagemap_.get(p)); | 136 return reinterpret_cast<Span*>(pagemap_.get(p)); |
138 } | 137 } |
139 | 138 |
140 // Dump state to stderr | |
141 void Dump(TCMalloc_Printer* out); | |
142 | |
143 // If this page heap is managing a range with starting page # >= start, | 139 // If this page heap is managing a range with starting page # >= start, |
144 // store info about the range in *r and return true. Else return false. | 140 // store info about the range in *r and return true. Else return false. |
145 bool GetNextRange(PageID start, base::MallocRange* r); | 141 bool GetNextRange(PageID start, base::MallocRange* r); |
146 | 142 |
147 // Page heap statistics | 143 // Page heap statistics |
148 struct Stats { | 144 struct Stats { |
149 Stats() : system_bytes(0), free_bytes(0), unmapped_bytes(0) {} | 145 Stats() : system_bytes(0), free_bytes(0), unmapped_bytes(0) {} |
150 uint64_t system_bytes; // Total bytes allocated from system | 146 uint64_t system_bytes; // Total bytes allocated from system |
151 uint64_t free_bytes; // Total bytes on normal freelists | 147 uint64_t free_bytes; // Total bytes on normal freelists |
152 uint64_t unmapped_bytes; // Total bytes on returned freelists | 148 uint64_t unmapped_bytes; // Total bytes on returned freelists |
153 }; | 149 }; |
154 inline Stats stats() const { return stats_; } | 150 inline Stats stats() const { return stats_; } |
155 void GetClassSizes(int64 class_sizes_normal[kMaxPages], | 151 |
156 int64 class_sizes_returned[kMaxPages], | 152 struct SmallSpanStats { |
157 int64* normal_pages_in_spans, | 153 // For each free list of small spans, the length (in spans) of the |
158 int64* returned_pages_in_spans); | 154 // normal and returned free lists for that size. |
| 155 int64 normal_length[kMaxPages]; |
| 156 int64 returned_length[kMaxPages]; |
| 157 }; |
| 158 void GetSmallSpanStats(SmallSpanStats* result); |
| 159 |
| 160 // Stats for free large spans (i.e., spans with more than kMaxPages pages). |
| 161 struct LargeSpanStats { |
| 162 int64 spans; // Number of such spans |
| 163 int64 normal_pages; // Combined page length of normal large spans |
| 164 int64 returned_pages; // Combined page length of unmapped spans |
| 165 }; |
| 166 void GetLargeSpanStats(LargeSpanStats* result); |
159 | 167 |
160 bool Check(); | 168 bool Check(); |
161 // Like Check() but does some more comprehensive checking. | 169 // Like Check() but does some more comprehensive checking. |
162 bool CheckExpensive(); | 170 bool CheckExpensive(); |
163 bool CheckList(Span* list, Length min_pages, Length max_pages, | 171 bool CheckList(Span* list, Length min_pages, Length max_pages, |
164 int freelist); // ON_NORMAL_FREELIST or ON_RETURNED_FREELIST | 172 int freelist); // ON_NORMAL_FREELIST or ON_RETURNED_FREELIST |
165 | 173 |
166 // Try to release at least num_pages for reuse by the OS. Returns | 174 // Try to release at least num_pages for reuse by the OS. Returns |
167 // the actual number of pages released, which may be less than | 175 // the actual number of pages released, which may be less than |
168 // num_pages if there weren't enough pages to release. The result | 176 // num_pages if there weren't enough pages to release. The result |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 int release_index_; | 285 int release_index_; |
278 }; | 286 }; |
279 | 287 |
280 } // namespace tcmalloc | 288 } // namespace tcmalloc |
281 | 289 |
282 #ifdef _MSC_VER | 290 #ifdef _MSC_VER |
283 #pragma warning(pop) | 291 #pragma warning(pop) |
284 #endif | 292 #endif |
285 | 293 |
286 #endif // TCMALLOC_PAGE_HEAP_H_ | 294 #endif // TCMALLOC_PAGE_HEAP_H_ |
OLD | NEW |