LEFT | RIGHT |
(no file at all) | |
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 // Garbage collector. | 5 // Garbage collector. |
6 | 6 |
7 #include "runtime.h" | 7 #include "runtime.h" |
8 #include "arch_GOARCH.h" | 8 #include "arch_GOARCH.h" |
9 #include "malloc.h" | 9 #include "malloc.h" |
10 #include "stack.h" | 10 #include "stack.h" |
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 // It clears the mark bits in preparation for the next GC round. | 709 // It clears the mark bits in preparation for the next GC round. |
710 static void | 710 static void |
711 sweep(void) | 711 sweep(void) |
712 { | 712 { |
713 MSpan *s; | 713 MSpan *s; |
714 int32 cl, n, npages; | 714 int32 cl, n, npages; |
715 uintptr size; | 715 uintptr size; |
716 byte *p; | 716 byte *p; |
717 MCache *c; | 717 MCache *c; |
718 byte *arena_start; | 718 byte *arena_start; |
| 719 int64 now; |
719 | 720 |
720 arena_start = runtime·mheap.arena_start; | 721 arena_start = runtime·mheap.arena_start; |
| 722 now = runtime·nanotime(); |
721 | 723 |
722 for(;;) { | 724 for(;;) { |
723 s = work.spans; | 725 s = work.spans; |
724 if(s == nil) | 726 if(s == nil) |
725 break; | 727 break; |
726 if(!runtime·casp(&work.spans, s, s->allnext)) | 728 if(!runtime·casp(&work.spans, s, s->allnext)) |
727 continue; | 729 continue; |
| 730 |
| 731 // Stamp newly unused spans. The scavenger will use that |
| 732 // info to potentially give back some pages to the OS. |
| 733 if(s->state == MSpanFree && s->unusedsince == 0) |
| 734 s->unusedsince = now; |
728 | 735 |
729 if(s->state != MSpanInUse) | 736 if(s->state != MSpanInUse) |
730 continue; | 737 continue; |
731 | 738 |
732 p = (byte*)(s->start << PageShift); | 739 p = (byte*)(s->start << PageShift); |
733 cl = s->sizeclass; | 740 cl = s->sizeclass; |
734 if(cl == 0) { | 741 if(cl == 0) { |
735 size = s->npages<<PageShift; | 742 size = s->npages<<PageShift; |
736 n = 1; | 743 n = 1; |
737 } else { | 744 } else { |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 runtime·ready(fing); | 963 runtime·ready(fing); |
957 } | 964 } |
958 } | 965 } |
959 m->locks--; | 966 m->locks--; |
960 | 967 |
961 cachestats(); | 968 cachestats(); |
962 heap1 = mstats.heap_alloc; | 969 heap1 = mstats.heap_alloc; |
963 obj1 = mstats.nmalloc - mstats.nfree; | 970 obj1 = mstats.nmalloc - mstats.nfree; |
964 | 971 |
965 t3 = runtime·nanotime(); | 972 t3 = runtime·nanotime(); |
| 973 mstats.last_gc = t3; |
966 mstats.pause_ns[mstats.numgc%nelem(mstats.pause_ns)] = t3 - t0; | 974 mstats.pause_ns[mstats.numgc%nelem(mstats.pause_ns)] = t3 - t0; |
967 mstats.pause_total_ns += t3 - t0; | 975 mstats.pause_total_ns += t3 - t0; |
968 mstats.numgc++; | 976 mstats.numgc++; |
969 if(mstats.debuggc) | 977 if(mstats.debuggc) |
970 runtime·printf("pause %D\n", t3-t0); | 978 runtime·printf("pause %D\n", t3-t0); |
971 | 979 |
972 if(gctrace) { | 980 if(gctrace) { |
973 runtime·printf("gc%d(%d): %D+%D+%D ms %D -> %D MB %D -> %D (%D-%
D) objects %D handoff\n", | 981 runtime·printf("gc%d(%d): %D+%D+%D ms %D -> %D MB %D -> %D (%D-%
D) objects %D handoff\n", |
974 mstats.numgc, work.nproc, (t1-t0)/1000000, (t2-t1)/10000
00, (t3-t2)/1000000, | 982 mstats.numgc, work.nproc, (t1-t0)/1000000, (t2-t1)/10000
00, (t3-t2)/1000000, |
975 heap0>>20, heap1>>20, obj0, obj1, | 983 heap0>>20, heap1>>20, obj0, obj1, |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1258 uintptr n; | 1266 uintptr n; |
1259 | 1267 |
1260 n = (h->arena_used - h->arena_start) / wordsPerBitmapWord; | 1268 n = (h->arena_used - h->arena_start) / wordsPerBitmapWord; |
1261 n = (n+bitmapChunk-1) & ~(bitmapChunk-1); | 1269 n = (n+bitmapChunk-1) & ~(bitmapChunk-1); |
1262 if(h->bitmap_mapped >= n) | 1270 if(h->bitmap_mapped >= n) |
1263 return; | 1271 return; |
1264 | 1272 |
1265 runtime·SysMap(h->arena_start - n, n - h->bitmap_mapped); | 1273 runtime·SysMap(h->arena_start - n, n - h->bitmap_mapped); |
1266 h->bitmap_mapped = n; | 1274 h->bitmap_mapped = n; |
1267 } | 1275 } |
LEFT | RIGHT |