Source file
src/runtime/mpagealloc_32bit.go
1
2
3
4
5
6
7
8
9
10
11
12 package runtime
13
14 import (
15 "runtime/internal/atomic"
16 "unsafe"
17 )
18
19 const (
20
21 summaryLevels = 4
22
23
24 pageAlloc32Bit = 1
25 pageAlloc64Bit = 0
26
27
28
29
30
31
32 pallocChunksL1Bits = 0
33 )
34
35
36 var levelBits = [summaryLevels]uint{
37 summaryL0Bits,
38 summaryLevelBits,
39 summaryLevelBits,
40 summaryLevelBits,
41 }
42
43
44 var levelShift = [summaryLevels]uint{
45 heapAddrBits - summaryL0Bits,
46 heapAddrBits - summaryL0Bits - 1*summaryLevelBits,
47 heapAddrBits - summaryL0Bits - 2*summaryLevelBits,
48 heapAddrBits - summaryL0Bits - 3*summaryLevelBits,
49 }
50
51
52 var levelLogPages = [summaryLevels]uint{
53 logPallocChunkPages + 3*summaryLevelBits,
54 logPallocChunkPages + 2*summaryLevelBits,
55 logPallocChunkPages + 1*summaryLevelBits,
56 logPallocChunkPages,
57 }
58
59
60
61 var scavengeIndexArray [((1 << heapAddrBits) / pallocChunkBytes) / 8]atomic.Uint8
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, totalSize)
82 p.summaryMappedReady += totalSize
83
84
85
86
87
88 for l, shift := range levelShift {
89 entries := 1 << (heapAddrBits - shift)
90
91
92 sl := notInHeapSlice{(*notInHeap)(reservation), 0, entries}
93 p.summary[l] = *(*[]pallocSum)(unsafe.Pointer(&sl))
94
95 reservation = add(reservation, uintptr(entries)*pallocSumBytes)
96 }
97
98
99 p.scav.index.chunks = scavengeIndexArray[:]
100 }
101
102
103 func (p *pageAlloc) sysGrow(base, limit uintptr) {
104 if base%pallocChunkBytes != 0 || limit%pallocChunkBytes != 0 {
105 print("runtime: base = ", hex(base), ", limit = ", hex(limit), "\n")
106 throw("sysGrow bounds not aligned to pallocChunkBytes")
107 }
108
109
110 for l := len(p.summary) - 1; l >= 0; l-- {
111
112
113
114
115 lo, hi := addrsToSummaryRange(l, base, limit)
116 _, hi = blockAlignSummaryRange(l, lo, hi)
117 if hi > len(p.summary[l]) {
118 p.summary[l] = p.summary[l][:hi]
119 }
120 }
121 }
122
View as plain text