This repository has been archived by the owner on Dec 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
mheap.go
141 lines (122 loc) · 2.95 KB
/
mheap.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Page heap.
//
// See malloc.go for overview.
package runtime
import (
"github.com/huandu/goroutine/hack/go1_6_1/runtime/internal/sys"
)
// Main malloc heap.
// The heap itself is the "free[]" and "large" arrays,
// but all the other global data is here too.
type mheap struct {
lock mutex
free [_MaxMHeapList]mSpanList
freelarge mSpanList
busy [_MaxMHeapList]mSpanList
busylarge mSpanList
allspans **mspan
gcspans **mspan
nspan uint32
sweepgen uint32
sweepdone uint32
spans **mspan
spans_mapped uintptr
pagesInUse uint64
spanBytesAlloc uint64
pagesSwept uint64
sweepPagesPerByte float64
largefree uint64
nlargefree uint64
nsmallfree [_NumSizeClasses]uint64
bitmap uintptr
bitmap_mapped uintptr
arena_start uintptr
arena_used uintptr
arena_end uintptr
arena_reserved bool
central [_NumSizeClasses]struct {
mcentral mcentral
pad [sys.CacheLineSize]byte
}
spanalloc fixalloc
cachealloc fixalloc
specialfinalizeralloc fixalloc
specialprofilealloc fixalloc
speciallock mutex
}
// An MSpan representing actual memory has state _MSpanInUse,
// _MSpanStack, or _MSpanFree. Transitions between these states are
// constrained as follows:
//
// * A span may transition from free to in-use or stack during any GC
// phase.
//
// * During sweeping (gcphase == _GCoff), a span may transition from
// in-use to free (as a result of sweeping) or stack to free (as a
// result of stacks being freed).
//
// * During GC (gcphase != _GCoff), a span *must not* transition from
// stack or in-use to free. Because concurrent GC may read a pointer
// and then look up its span, the span state must be monotonic.
const (
_MSpanInUse = iota
_MSpanStack
_MSpanFree
_MSpanDead
)
// mSpanList heads a linked list of spans.
//
// Linked list structure is based on BSD's "tail queue" data structure.
type mSpanList struct {
first *mspan
last **mspan
}
type mspan struct {
next *mspan
prev **mspan
list *mSpanList
start pageID
npages uintptr
freelist gclinkptr
sweepgen uint32
divMul uint32
ref uint16
sizeclass uint8
incache bool
state uint8
needzero uint8
divShift uint8
divShift2 uint8
elemsize uintptr
unusedsince int64
npreleased uintptr
limit uintptr
speciallock mutex
specials *special
baseMask uintptr
}
const (
_KindSpecialFinalizer = 1
_KindSpecialProfile = 2
)
type special struct {
next *special
offset uint16
kind byte
}
// The described object has a finalizer set for it.
type specialfinalizer struct {
special special
fn *funcval
nret uintptr
fint *_type
ot *ptrtype
}
// The described object is being heap profiled.
type specialprofile struct {
special special
b *bucket
}