...
Source file
src/runtime/mpagealloc_32bit.go
Documentation: runtime
1
2
3
4
5
6
7
8
9
10
11
12 package runtime
13
14 import (
15 "unsafe"
16 )
17
18 const (
19
20 summaryLevels = 4
21
22
23 pageAlloc32Bit = 1
24 pageAlloc64Bit = 0
25
26
27
28
29
30
31 pallocChunksL1Bits = 0
32 )
33
34
35 var levelBits = [summaryLevels]uint{
36 summaryL0Bits,
37 summaryLevelBits,
38 summaryLevelBits,
39 summaryLevelBits,
40 }
41
42
43 var levelShift = [summaryLevels]uint{
44 heapAddrBits - summaryL0Bits,
45 heapAddrBits - summaryL0Bits - 1*summaryLevelBits,
46 heapAddrBits - summaryL0Bits - 2*summaryLevelBits,
47 heapAddrBits - summaryL0Bits - 3*summaryLevelBits,
48 }
49
50
51 var levelLogPages = [summaryLevels]uint{
52 logPallocChunkPages + 3*summaryLevelBits,
53 logPallocChunkPages + 2*summaryLevelBits,
54 logPallocChunkPages + 1*summaryLevelBits,
55 logPallocChunkPages,
56 }
57
58
59
60 var scavengeIndexArray [(1 << heapAddrBits) / pallocChunkBytes]atomicScavChunkData
61
62
63 func (p *pageAlloc) sysInit(test bool) {
64
65
66
67 totalSize := uintptr(0)
68 for l := 0; l < summaryLevels; l++ {
69 totalSize += (uintptr(1) << (heapAddrBits - levelShift[l])) * pallocSumBytes
70 }
71 totalSize = alignUp(totalSize, physPageSize)
72
73
74 reservation := sysReserve(nil, totalSize)
75 if reservation == nil {
76 throw("failed to reserve page summary memory")
77 }
78
79 sysMap(reservation, totalSize, p.sysStat)
80 sysUsed(reservation, totalSize, totalSize)
81 p.summaryMappedReady += 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
119
120
121
122 func (s *scavengeIndex) sysInit(test bool, sysStat *sysMemStat) (mappedReady uintptr) {
123 if test {
124
125 scavIndexSize := uintptr(len(scavengeIndexArray)) * unsafe.Sizeof(atomicScavChunkData{})
126 s.chunks = ((*[(1 << heapAddrBits) / pallocChunkBytes]atomicScavChunkData)(sysAlloc(scavIndexSize, sysStat)))[:]
127 mappedReady = scavIndexSize
128 } else {
129
130 s.chunks = scavengeIndexArray[:]
131 }
132 s.min.Store(1)
133 s.max.Store(uintptr(len(s.chunks)))
134 return
135 }
136
137
138 func (s *scavengeIndex) sysGrow(base, limit uintptr, sysStat *sysMemStat) uintptr {
139 return 0
140 }
141
View as plain text