Skip to content

Commit 2ae8bf7

Browse files
committed
runtime: fix stale comments about mheap and mspan
As of 07e738e all spans are allocated out of a treap, and not just large spans or spans for large objects. Also, now we have a separate treap for spans that have been scavenged. Change-Id: I9c2cb7b6798fc536bbd34835da2e888224fd7ed4 Reviewed-on: https://go-review.googlesource.com/c/142958 Reviewed-by: Austin Clements <[email protected]>
1 parent e72595e commit 2ae8bf7

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/runtime/mheap.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
const minPhysPageSize = 4096
2222

2323
// Main malloc heap.
24-
// The heap itself is the "free[]" and "large" arrays,
24+
// The heap itself is the "free" and "scav" treaps,
2525
// but all the other global data is here too.
2626
//
2727
// mheap must not be heap-allocated because it contains mSpanLists,
@@ -147,7 +147,7 @@ type mheap struct {
147147

148148
spanalloc fixalloc // allocator for span*
149149
cachealloc fixalloc // allocator for mcache*
150-
treapalloc fixalloc // allocator for treapNodes* used by large objects
150+
treapalloc fixalloc // allocator for treapNodes*
151151
specialfinalizeralloc fixalloc // allocator for specialfinalizer*
152152
specialprofilealloc fixalloc // allocator for specialprofile*
153153
speciallock mutex // lock for special record allocators.
@@ -198,15 +198,16 @@ type arenaHint struct {
198198

199199
// An MSpan is a run of pages.
200200
//
201-
// When a MSpan is in the heap free list, state == mSpanFree
201+
// When a MSpan is in the heap free treap, state == mSpanFree
202202
// and heapmap(s->start) == span, heapmap(s->start+s->npages-1) == span.
203+
// If the MSpan is in the heap scav treap, then in addition to the
204+
// above scavenged == true. scavenged == false in all other cases.
203205
//
204206
// When a MSpan is allocated, state == mSpanInUse or mSpanManual
205207
// and heapmap(i) == span for all s->start <= i < s->start+s->npages.
206208

207-
// Every MSpan is in one doubly-linked list,
208-
// either one of the MHeap's free lists or one of the
209-
// MCentral's span lists.
209+
// Every MSpan is in one doubly-linked list, either in the MHeap's
210+
// busy list or one of the MCentral's span lists.
210211

211212
// An MSpan representing actual memory has state mSpanInUse,
212213
// mSpanManual, or mSpanFree. Transitions between these states are
@@ -848,7 +849,7 @@ func (h *mheap) setSpans(base, npage uintptr, s *mspan) {
848849

849850
// Allocates a span of the given size. h must be locked.
850851
// The returned span has been removed from the
851-
// free list, but its state is still mSpanFree.
852+
// free structures, but its state is still mSpanFree.
852853
func (h *mheap) allocSpanLocked(npage uintptr, stat *uint64) *mspan {
853854
var s *mspan
854855

0 commit comments

Comments
 (0)