fix(go): 第二轮细查再修正 12 处版本与机制细节
- 02:reentersyscall 在 1.25 的顺序是 save -> 改 _Gsyscall -> 复制 syscalltick、解绑、置 _Psyscall;1.26 起整个解绑取消,P 保持 _Prunning - 03:pallocSum 的 bit63 是"整片完全空闲"哨兵(三个数都等于 2^21 时只置这一位),不是闲置位 - 04:STW① 的 gcBgMarkStartWorkers 在停世界之前执行(mgc.go:817 -> :834) - 07:sync.Map 三代关系:1.23 及以前 read/dirty;1.24 起 HashTrieMap 可选(GOEXPERIMENT=synchashtriemap);1.25 起默认;1.26 删旧实现 - 10:Mutex 实现搬到 internal/sync 是 1.24(不是 1.26);WaitGroup waiter 只占低 31 位,bit31 是 synctest bubble 标志;wg.Go 的"panic 不调 Done"是 1.26 行为,1.25 要求 f 不能 panic - 11:Ticker 不可达可回收始于 1.23(原文把 1.22 及以前写成"1.23 及以前",与同页自相矛盾);cancelCtx.err 是 atomic.Value - 14:GMP 调度器是 Go 1.1 引入(P / per-P runq / work-stealing),1.5 只是 GOMAXPROCS 默认改为核数 校验:check-pages 15 页通过;114 个 go 代码块 -> 16/16 完整程序实跑通过、5 个伪代码片段预期解析失败;KPI 9.7 万字。
This commit is contained in:
@@ -268,7 +268,10 @@ func (sc spanClass) noscan() bool { return sc&1 != 0 }</pre>
|
||||
「根到叶」最多 5 次跳转,这就是它能常数时间的原因。</p>
|
||||
<p>每个节点是一个 <code>uint64</code> 的 <code>pallocSum</code>,用 21 位各打包三个数:
|
||||
<code>start</code>(首部连续空闲页数)、<code>max</code>(内部最大连续页数)、
|
||||
<code>end</code>(尾部连续页数),最高 1 位闲置。父节点由 8 个子节点聚合而来,自底向上维护。</p>
|
||||
<code>end</code>(尾部连续页数)。剩下的最高位不是闲置位,而是<strong>「整片完全空闲」的哨兵</strong>:
|
||||
21 位最多存 2²¹ − 1,而一个满空闲的节点三个数都等于 2²¹,装不下,于是只把 bit63 置 1、
|
||||
其余位全 0 来表示这种状态(源码注释:<i>The latter case is represented by just setting the 64th bit</i>)。
|
||||
父节点由 8 个子节点聚合而来,自底向上维护。</p>
|
||||
<pre data-lang="go" data-name="runtime/mpagealloc.go:pageAlloc 与 pallocSum(简化)">const (
|
||||
summaryLevels = 5
|
||||
logMaxPackedValue = 21 // 每段 21 bit
|
||||
@@ -284,10 +287,15 @@ type pageAlloc struct {
|
||||
// ...
|
||||
}
|
||||
|
||||
// 布局:[end:21][max:21][start:21][闲置 1 bit]
|
||||
// 布局:[bit63 哨兵][end:21][max:21][start:21];bit63 置位代表"整片完全空闲"
|
||||
type pallocSum uint64
|
||||
|
||||
func (p pallocSum) start() uint { return uint(uint64(p) & (maxPackedValue - 1)) }
|
||||
func (p pallocSum) start() uint {
|
||||
if uint64(p)&(1<<63) != 0 {
|
||||
return maxPackedValue // 哨兵:三个数都是 2^21
|
||||
}
|
||||
return uint(uint64(p) & (maxPackedValue - 1))
|
||||
}
|
||||
func (p pallocSum) max() uint { return uint((uint64(p) >> logMaxPackedValue) & (maxPackedValue - 1)) }
|
||||
func (p pallocSum) end() uint { return uint((uint64(p) >> (2 * logMaxPackedValue)) & (maxPackedValue - 1)) }</pre>
|
||||
<p>查找自顶向下,每个节点只做三次判断:<code>start</code> 够了就地返回;<code>max</code> 够了说明答案在内部,
|
||||
|
||||
Reference in New Issue
Block a user