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