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 <gperftools/malloc_extension.h> | 41 #include <google/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 <gperftools/stacktrace.h> | 64 # include <google/stacktrace.h> |
65 #endif | 65 #endif |
66 | 66 |
| 67 class TCMalloc_Printer; |
67 namespace base { | 68 namespace base { |
68 struct MallocRange; | 69 struct MallocRange; |
69 } | 70 } |
70 | 71 |
71 namespace tcmalloc { | 72 namespace tcmalloc { |
72 | 73 |
73 // ------------------------------------------------------------------------- | 74 // ------------------------------------------------------------------------- |
74 // Map from page-id to per-page data | 75 // Map from page-id to per-page data |
75 // ------------------------------------------------------------------------- | 76 // ------------------------------------------------------------------------- |
76 | 77 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 // REQUIRES: span->location == IN_USE | 138 // REQUIRES: span->location == IN_USE |
138 // REQUIRES: span->sizeclass == 0 | 139 // REQUIRES: span->sizeclass == 0 |
139 Span* Split(Span* span, Length n); | 140 Span* Split(Span* span, Length n); |
140 | 141 |
141 // Return the descriptor for the specified page. Returns NULL if | 142 // Return the descriptor for the specified page. Returns NULL if |
142 // this PageID was not allocated previously. | 143 // this PageID was not allocated previously. |
143 inline Span* GetDescriptor(PageID p) const { | 144 inline Span* GetDescriptor(PageID p) const { |
144 return reinterpret_cast<Span*>(pagemap_.get(p)); | 145 return reinterpret_cast<Span*>(pagemap_.get(p)); |
145 } | 146 } |
146 | 147 |
| 148 // Dump state to stderr |
| 149 void Dump(TCMalloc_Printer* out); |
| 150 |
147 // If this page heap is managing a range with starting page # >= start, | 151 // If this page heap is managing a range with starting page # >= start, |
148 // store info about the range in *r and return true. Else return false. | 152 // store info about the range in *r and return true. Else return false. |
149 bool GetNextRange(PageID start, base::MallocRange* r); | 153 bool GetNextRange(PageID start, base::MallocRange* r); |
150 | 154 |
151 // Page heap statistics | 155 // Page heap statistics |
152 struct Stats { | 156 struct Stats { |
153 Stats() : system_bytes(0), free_bytes(0), unmapped_bytes(0) {} | 157 Stats() : system_bytes(0), free_bytes(0), unmapped_bytes(0) {} |
154 uint64_t system_bytes; // Total bytes allocated from system | 158 uint64_t system_bytes; // Total bytes allocated from system |
155 uint64_t free_bytes; // Total bytes on normal freelists | 159 uint64_t free_bytes; // Total bytes on normal freelists |
156 uint64_t unmapped_bytes; // Total bytes on returned freelists | 160 uint64_t unmapped_bytes; // Total bytes on returned freelists |
157 uint64_t committed_bytes; // Bytes committed, always <= system_bytes_. | 161 uint64_t committed_bytes; // Bytes committed, always <= system_bytes_. |
158 | 162 |
159 }; | 163 }; |
160 inline Stats stats() const { return stats_; } | 164 inline Stats stats() const { return stats_; } |
161 | 165 void GetClassSizes(int64 class_sizes_normal[kMaxPages], |
162 struct SmallSpanStats { | 166 int64 class_sizes_returned[kMaxPages], |
163 // For each free list of small spans, the length (in spans) of the | 167 int64* normal_pages_in_spans, |
164 // normal and returned free lists for that size. | 168 int64* returned_pages_in_spans); |
165 int64 normal_length[kMaxPages]; | |
166 int64 returned_length[kMaxPages]; | |
167 }; | |
168 void GetSmallSpanStats(SmallSpanStats* result); | |
169 | |
170 // Stats for free large spans (i.e., spans with more than kMaxPages pages). | |
171 struct LargeSpanStats { | |
172 int64 spans; // Number of such spans | |
173 int64 normal_pages; // Combined page length of normal large spans | |
174 int64 returned_pages; // Combined page length of unmapped spans | |
175 }; | |
176 void GetLargeSpanStats(LargeSpanStats* result); | |
177 | 169 |
178 bool Check(); | 170 bool Check(); |
179 // Like Check() but does some more comprehensive checking. | 171 // Like Check() but does some more comprehensive checking. |
180 bool CheckExpensive(); | 172 bool CheckExpensive(); |
181 bool CheckList(Span* list, Length min_pages, Length max_pages, | 173 bool CheckList(Span* list, Length min_pages, Length max_pages, |
182 int freelist); // ON_NORMAL_FREELIST or ON_RETURNED_FREELIST | 174 int freelist); // ON_NORMAL_FREELIST or ON_RETURNED_FREELIST |
183 | 175 |
184 // Try to release at least num_pages for reuse by the OS. Returns | 176 // Try to release at least num_pages for reuse by the OS. Returns |
185 // the actual number of pages released, which may be less than | 177 // the actual number of pages released, which may be less than |
186 // num_pages if there weren't enough pages to release. The result | 178 // num_pages if there weren't enough pages to release. The result |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 int release_index_; | 294 int release_index_; |
303 }; | 295 }; |
304 | 296 |
305 } // namespace tcmalloc | 297 } // namespace tcmalloc |
306 | 298 |
307 #ifdef _MSC_VER | 299 #ifdef _MSC_VER |
308 #pragma warning(pop) | 300 #pragma warning(pop) |
309 #endif | 301 #endif |
310 | 302 |
311 #endif // TCMALLOC_PAGE_HEAP_H_ | 303 #endif // TCMALLOC_PAGE_HEAP_H_ |
OLD | NEW |