Commit 4ebf295
runtime: prefer to restart Ps on the same M after STW
Today, Ps jump around arbitrarily across STW. Instead, try to keep the P
on the previous M it ran on. In the future, we'll likely want to try to
expand this beyond STW to create a more general affinity for specific
Ms.
For this to be useful, the Ps need to have runnable Gs. Today, STW
preemption goes through goschedImpl, which places the G on the global
run queue. If that was the only G then the P won't have runnable
goroutines anymore.
It makes more sense to keep the G with its P across STW anyway, so add a
special case to goschedImpl for that.
On my machine, this CL reduces the error rate in TestTraceSTW from 99.8%
to 1.9%.
As a nearly 2% error rate shows, there are still cases where this best
effort scheduling doesn't work. The most obvious is that while
procresize assigns Ps back to their original M, startTheWorldWithSema
calls wakep to start a spinning M. The spinning M may steal a goroutine
from another P if that P is too slow to start.
For #65694.
Change-Id: I6a6a636c0969c587d039b68bc68ea16c74ff1fc9
Reviewed-on: https://go-review.googlesource.com/c/go/+/714801
Reviewed-by: Michael Knyszek <[email protected]>
Auto-Submit: Michael Pratt <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>1 parent 625d8e9 commit 4ebf295
File tree
6 files changed
+656
-9
lines changed- src
- internal/trace/testtrace
- runtime
- testdata/testprog
6 files changed
+656
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
| 19 | + | |
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1009 | 1009 | | |
1010 | 1010 | | |
1011 | 1011 | | |
| 1012 | + | |
| 1013 | + | |
1012 | 1014 | | |
1013 | 1015 | | |
1014 | 1016 | | |
| |||
2018 | 2020 | | |
2019 | 2021 | | |
2020 | 2022 | | |
| 2023 | + | |
| 2024 | + | |
| 2025 | + | |
| 2026 | + | |
2021 | 2027 | | |
2022 | 2028 | | |
2023 | 2029 | | |
| |||
4259 | 4265 | | |
4260 | 4266 | | |
4261 | 4267 | | |
| 4268 | + | |
4262 | 4269 | | |
4263 | 4270 | | |
4264 | 4271 | | |
| |||
4281 | 4288 | | |
4282 | 4289 | | |
4283 | 4290 | | |
4284 | | - | |
4285 | | - | |
4286 | | - | |
| 4291 | + | |
| 4292 | + | |
| 4293 | + | |
| 4294 | + | |
| 4295 | + | |
| 4296 | + | |
| 4297 | + | |
| 4298 | + | |
| 4299 | + | |
4287 | 4300 | | |
4288 | 4301 | | |
4289 | 4302 | | |
| |||
6013 | 6026 | | |
6014 | 6027 | | |
6015 | 6028 | | |
| 6029 | + | |
6016 | 6030 | | |
6017 | 6031 | | |
6018 | 6032 | | |
| |||
6021 | 6035 | | |
6022 | 6036 | | |
6023 | 6037 | | |
6024 | | - | |
6025 | | - | |
6026 | | - | |
6027 | | - | |
| 6038 | + | |
6028 | 6039 | | |
| 6040 | + | |
| 6041 | + | |
| 6042 | + | |
| 6043 | + | |
| 6044 | + | |
| 6045 | + | |
| 6046 | + | |
| 6047 | + | |
| 6048 | + | |
| 6049 | + | |
| 6050 | + | |
| 6051 | + | |
| 6052 | + | |
| 6053 | + | |
| 6054 | + | |
| 6055 | + | |
| 6056 | + | |
| 6057 | + | |
| 6058 | + | |
| 6059 | + | |
| 6060 | + | |
| 6061 | + | |
6029 | 6062 | | |
| 6063 | + | |
| 6064 | + | |
| 6065 | + | |
| 6066 | + | |
| 6067 | + | |
| 6068 | + | |
| 6069 | + | |
| 6070 | + | |
| 6071 | + | |
| 6072 | + | |
6030 | 6073 | | |
6031 | 6074 | | |
6032 | 6075 | | |
| |||
6064 | 6107 | | |
6065 | 6108 | | |
6066 | 6109 | | |
| 6110 | + | |
| 6111 | + | |
| 6112 | + | |
| 6113 | + | |
| 6114 | + | |
6067 | 6115 | | |
6068 | 6116 | | |
6069 | 6117 | | |
| |||
6998 | 7046 | | |
6999 | 7047 | | |
7000 | 7048 | | |
| 7049 | + | |
| 7050 | + | |
| 7051 | + | |
| 7052 | + | |
| 7053 | + | |
| 7054 | + | |
| 7055 | + | |
| 7056 | + | |
| 7057 | + | |
| 7058 | + | |
| 7059 | + | |
| 7060 | + | |
| 7061 | + | |
| 7062 | + | |
| 7063 | + | |
| 7064 | + | |
| 7065 | + | |
| 7066 | + | |
| 7067 | + | |
| 7068 | + | |
| 7069 | + | |
7001 | 7070 | | |
7002 | 7071 | | |
7003 | 7072 | | |
| |||
0 commit comments