Source file
src/runtime/mpagealloc_32bit.go
Documentation: runtime
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package runtime
20
21 import "unsafe"
22
23 const (
24
25 summaryLevels = 4
26
27
28 pageAlloc32Bit = 1
29 pageAlloc64Bit = 0
30
31
32
33
34
35
36 pallocChunksL1Bits = 0
37 )
38
39
40 var levelBits = [summaryLevels]uint{
41 summaryL0Bits,
42 summaryLevelBits,
43 summaryLevelBits,
44 summaryLevelBits,
45 }
46
47
48 var levelShift = [summaryLevels]uint{
49 heapAddrBits - summaryL0Bits,
50 heapAddrBits - summaryL0Bits - 1*summaryLevelBits,
51 heapAddrBits - summaryL0Bits - 2*summaryLevelBits,
52 heapAddrBits - summaryL0Bits - 3*summaryLevelBits,
53 }
54
55
56 var levelLogPages = [summaryLevels]uint{
57 logPallocChunkPages + 3*summaryLevelBits,
58 logPallocChunkPages + 2*summaryLevelBits,
59 logPallocChunkPages + 1*summaryLevelBits,
60 logPallocChunkPages,
61 }
62
63
64 func (p *pageAlloc) sysInit() {
65
66
67
68 totalSize := uintptr(0)
69 for l := 0; l < summaryLevels; l++ {
70 totalSize += (uintptr(1) << (heapAddrBits - levelShift[l])) * pallocSumBytes
71 }
72 totalSize = alignUp(totalSize, physPageSize)
73
74
75 reservation := sysReserve(nil, totalSize)
76 if reservation == nil {
77 throw("failed to reserve page summary memory")
78 }
79
80 sysMap(reservation, totalSize, p.sysStat)
81 sysUsed(reservation, totalSize)
82
83
84
85
86
87 for l, shift := range levelShift {
88 entries := 1 << (heapAddrBits - shift)
89
90
91 sl := notInHeapSlice{(*notInHeap)(reservation), 0, entries}
92 p.summary[l] = *(*[]pallocSum)(unsafe.Pointer(&sl))
93
94 reservation = add(reservation, uintptr(entries)*pallocSumBytes)
95 }
96 }
97
98
99 func (p *pageAlloc) sysGrow(base, limit uintptr) {
100 if base%pallocChunkBytes != 0 || limit%pallocChunkBytes != 0 {
101 print("runtime: base = ", hex(base), ", limit = ", hex(limit), "\n")
102 throw("sysGrow bounds not aligned to pallocChunkBytes")
103 }
104
105
106 for l := len(p.summary) - 1; l >= 0; l-- {
107
108
109
110
111 lo, hi := addrsToSummaryRange(l, base, limit)
112 _, hi = blockAlignSummaryRange(l, lo, hi)
113 if hi > len(p.summary[l]) {
114 p.summary[l] = p.summary[l][:hi]
115 }
116 }
117 }
118
View as plain text