OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Memory allocator, based on tcmalloc. | 5 // Memory allocator, based on tcmalloc. |
6 // http://goog-perftools.sourceforge.net/doc/tcmalloc.html | 6 // http://goog-perftools.sourceforge.net/doc/tcmalloc.html |
7 | 7 |
8 // The main allocator works in runs of pages. | 8 // The main allocator works in runs of pages. |
9 // Small allocation sizes (up to and including 32 kB) are | 9 // Small allocation sizes (up to and including 32 kB) are |
10 // rounded to one of about 100 size classes, each of which | 10 // rounded to one of about 100 size classes, each of which |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 uint64 nlookup; // number of pointer lookups | 198 uint64 nlookup; // number of pointer lookups |
199 uint64 nmalloc; // number of mallocs | 199 uint64 nmalloc; // number of mallocs |
200 uint64 nfree; // number of frees | 200 uint64 nfree; // number of frees |
201 | 201 |
202 // Statistics about malloc heap. | 202 // Statistics about malloc heap. |
203 // protected by mheap.Lock | 203 // protected by mheap.Lock |
204 uint64 heap_alloc; // bytes allocated and still in use | 204 uint64 heap_alloc; // bytes allocated and still in use |
205 uint64 heap_sys; // bytes obtained from system | 205 uint64 heap_sys; // bytes obtained from system |
206 uint64 heap_idle; // bytes in idle spans | 206 uint64 heap_idle; // bytes in idle spans |
207 uint64 heap_inuse; // bytes in non-idle spans | 207 uint64 heap_inuse; // bytes in non-idle spans |
| 208 uint64 heap_released; // bytes released to the OS |
208 uint64 heap_objects; // total number of allocated objects | 209 uint64 heap_objects; // total number of allocated objects |
209 | 210 |
210 // Statistics about allocation of low-level fixed-size structures. | 211 // Statistics about allocation of low-level fixed-size structures. |
211 // Protected by FixAlloc locks. | 212 // Protected by FixAlloc locks. |
212 uint64 stacks_inuse; // bootstrap stacks | 213 uint64 stacks_inuse; // bootstrap stacks |
213 uint64 stacks_sys; | 214 uint64 stacks_sys; |
214 uint64 mspan_inuse; // MSpan structures | 215 uint64 mspan_inuse; // MSpan structures |
215 uint64 mspan_sys; | 216 uint64 mspan_sys; |
216 uint64 mcache_inuse; // MCache structures | 217 uint64 mcache_inuse; // MCache structures |
217 uint64 mcache_sys; | 218 uint64 mcache_sys; |
218 uint64 buckhash_sys; // profiling bucket hash table | 219 uint64 buckhash_sys; // profiling bucket hash table |
219 | 220 |
220 // Statistics about garbage collector. | 221 // Statistics about garbage collector. |
221 // Protected by stopping the world during GC. | 222 // Protected by stopping the world during GC. |
222 uint64 next_gc; // next GC (in heap_alloc time) | 223 uint64 next_gc; // next GC (in heap_alloc time) |
| 224 uint64 last_gc; // last GC (in absolute time) |
223 uint64 pause_total_ns; | 225 uint64 pause_total_ns; |
224 uint64 pause_ns[256]; | 226 uint64 pause_ns[256]; |
225 uint32 numgc; | 227 uint32 numgc; |
226 bool enablegc; | 228 bool enablegc; |
227 bool debuggc; | 229 bool debuggc; |
228 | 230 |
229 // Statistics about allocation size classes. | 231 // Statistics about allocation size classes. |
230 struct { | 232 struct { |
231 uint32 size; | 233 uint32 size; |
232 uint64 nmalloc; | 234 uint64 nmalloc; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 { | 299 { |
298 MSpanInUse = 0, | 300 MSpanInUse = 0, |
299 MSpanFree, | 301 MSpanFree, |
300 MSpanListHead, | 302 MSpanListHead, |
301 MSpanDead, | 303 MSpanDead, |
302 }; | 304 }; |
303 struct MSpan | 305 struct MSpan |
304 { | 306 { |
305 MSpan *next; // in a span linked list | 307 MSpan *next; // in a span linked list |
306 MSpan *prev; // in a span linked list | 308 MSpan *prev; // in a span linked list |
307 » MSpan» *allnext;» » // in the list of all spans | 309 » MSpan» *allnext;» // in the list of all spans |
308 PageID start; // starting page number | 310 PageID start; // starting page number |
309 uintptr npages; // number of pages in span | 311 uintptr npages; // number of pages in span |
310 MLink *freelist; // list of free objects | 312 MLink *freelist; // list of free objects |
311 uint32 ref; // number of allocated objects in this span | 313 uint32 ref; // number of allocated objects in this span |
312 uint32 sizeclass; // size class | 314 uint32 sizeclass; // size class |
313 uint32 state; // MSpanInUse etc | 315 uint32 state; // MSpanInUse etc |
314 » byte» *limit;»// end of data in span | 316 » int64 unusedsince;» // First time spotted by GC in MSpanFree state |
| 317 » uintptr npreleased;» // number of pages released to the OS |
| 318 » byte» *limit;»» // end of data in span |
315 }; | 319 }; |
316 | 320 |
317 void runtime·MSpan_Init(MSpan *span, PageID start, uintptr npages); | 321 void runtime·MSpan_Init(MSpan *span, PageID start, uintptr npages); |
318 | 322 |
319 // Every MSpan is in one doubly-linked list, | 323 // Every MSpan is in one doubly-linked list, |
320 // either one of the MHeap's free lists or one of the | 324 // either one of the MHeap's free lists or one of the |
321 // MCentral's span lists. We use empty MSpan structures as list heads. | 325 // MCentral's span lists. We use empty MSpan structures as list heads. |
322 void runtime·MSpanList_Init(MSpan *list); | 326 void runtime·MSpanList_Init(MSpan *list); |
323 bool runtime·MSpanList_IsEmpty(MSpan *list); | 327 bool runtime·MSpanList_IsEmpty(MSpan *list); |
324 void runtime·MSpanList_Insert(MSpan *list, MSpan *span); | 328 void runtime·MSpanList_Insert(MSpan *list, MSpan *span); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 extern MHeap runtime·mheap; | 378 extern MHeap runtime·mheap; |
375 | 379 |
376 void runtime·MHeap_Init(MHeap *h, void *(*allocator)(uintptr)); | 380 void runtime·MHeap_Init(MHeap *h, void *(*allocator)(uintptr)); |
377 MSpan* runtime·MHeap_Alloc(MHeap *h, uintptr npage, int32 sizeclass, int32 acct
); | 381 MSpan* runtime·MHeap_Alloc(MHeap *h, uintptr npage, int32 sizeclass, int32 acct
); |
378 void runtime·MHeap_Free(MHeap *h, MSpan *s, int32 acct); | 382 void runtime·MHeap_Free(MHeap *h, MSpan *s, int32 acct); |
379 MSpan* runtime·MHeap_Lookup(MHeap *h, void *v); | 383 MSpan* runtime·MHeap_Lookup(MHeap *h, void *v); |
380 MSpan* runtime·MHeap_LookupMaybe(MHeap *h, void *v); | 384 MSpan* runtime·MHeap_LookupMaybe(MHeap *h, void *v); |
381 void runtime·MGetSizeClassInfo(int32 sizeclass, uintptr *size, int32 *npages,
int32 *nobj); | 385 void runtime·MGetSizeClassInfo(int32 sizeclass, uintptr *size, int32 *npages,
int32 *nobj); |
382 void* runtime·MHeap_SysAlloc(MHeap *h, uintptr n); | 386 void* runtime·MHeap_SysAlloc(MHeap *h, uintptr n); |
383 void runtime·MHeap_MapBits(MHeap *h); | 387 void runtime·MHeap_MapBits(MHeap *h); |
| 388 void runtime·MHeap_Scavenger(void); |
384 | 389 |
385 void* runtime·mallocgc(uintptr size, uint32 flag, int32 dogc, int32 zeroed); | 390 void* runtime·mallocgc(uintptr size, uint32 flag, int32 dogc, int32 zeroed); |
386 int32 runtime·mlookup(void *v, byte **base, uintptr *size, MSpan **s); | 391 int32 runtime·mlookup(void *v, byte **base, uintptr *size, MSpan **s); |
387 void runtime·gc(int32 force); | 392 void runtime·gc(int32 force); |
388 void runtime·markallocated(void *v, uintptr n, bool noptr); | 393 void runtime·markallocated(void *v, uintptr n, bool noptr); |
389 void runtime·checkallocated(void *v, uintptr n); | 394 void runtime·checkallocated(void *v, uintptr n); |
390 void runtime·markfreed(void *v, uintptr n); | 395 void runtime·markfreed(void *v, uintptr n); |
391 void runtime·checkfreed(void *v, uintptr n); | 396 void runtime·checkfreed(void *v, uintptr n); |
392 int32 runtime·checking; | 397 int32 runtime·checking; |
393 void runtime·markspan(void *v, uintptr size, uintptr n, bool leftover); | 398 void runtime·markspan(void *v, uintptr size, uintptr n, bool leftover); |
(...skipping 19 matching lines...) Expand all Loading... |
413 // Must match definition in extern.go. | 418 // Must match definition in extern.go. |
414 enum { | 419 enum { |
415 MProf_None = 0, | 420 MProf_None = 0, |
416 MProf_Sample = 1, | 421 MProf_Sample = 1, |
417 MProf_All = 2, | 422 MProf_All = 2, |
418 }; | 423 }; |
419 extern int32 runtime·malloc_profile; | 424 extern int32 runtime·malloc_profile; |
420 | 425 |
421 bool runtime·getfinalizer(void *p, bool del, void (**fn)(void*), int32 *nret)
; | 426 bool runtime·getfinalizer(void *p, bool del, void (**fn)(void*), int32 *nret)
; |
422 void runtime·walkfintab(void (*fn)(void*)); | 427 void runtime·walkfintab(void (*fn)(void*)); |
OLD | NEW |