Skip to content

Commit 3968a5b

Browse files
rscgopherbot
authored andcommitted
runtime: handle m0 padding better
The SpinbitMutex experiment requires m structs other than m0 to be allocated in 2048-byte size class, by adding padding. Do the calculation more explicitly, to avoid future CLs like CL 653335. Change-Id: I83ae1e86ef3711ab65441f4e487f94b9e1429029 Reviewed-on: https://go-review.googlesource.com/c/go/+/654595 Reviewed-by: Rhys Hiltner <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Michael Knyszek <[email protected]>
1 parent c77ada1 commit 3968a5b

File tree

5 files changed

+11
-4
lines changed

5 files changed

+11
-4
lines changed

src/runtime/asan.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func ASanWrite(addr unsafe.Pointer, len int) {
2626

2727
// Private interface for the runtime.
2828
const asanenabled = true
29+
const asanenabledBit = 1
2930

3031
// asan{read,write} are nosplit because they may be called between
3132
// fork and exec, when the stack must not grow. See issue #50391.

src/runtime/asan0.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
)
1414

1515
const asanenabled = false
16+
const asanenabledBit = 0
1617

1718
// Because asanenabled is false, none of these functions should be called.
1819

src/runtime/lock_spinbit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ type mWaitList struct {
9090

9191
// lockVerifyMSize confirms that we can recreate the low bits of the M pointer.
9292
func lockVerifyMSize() {
93-
size := roundupsize(unsafe.Sizeof(m{}), false) + mallocHeaderSize
93+
size := roundupsize(unsafe.Sizeof(mPadded{}), false) + mallocHeaderSize
9494
if size&mutexMMask != 0 {
9595
print("M structure uses sizeclass ", size, "/", hex(size), " bytes; ",
9696
"incompatible with mutex flag mask ", hex(mutexMMask), "\n")

src/runtime/proc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2256,7 +2256,7 @@ func allocm(pp *p, fn func(), id int64) *m {
22562256
unlock(&sched.lock)
22572257
}
22582258

2259-
mp := new(m)
2259+
mp := &new(mPadded).m
22602260
mp.mstartfn = fn
22612261
mcommoninit(mp, id)
22622262

src/runtime/runtime2.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,13 +619,18 @@ type m struct {
619619
// Up to 10 locks held by this m, maintained by the lock ranking code.
620620
locksHeldLen int
621621
locksHeld [10]heldLockInfo
622+
}
623+
624+
const mRedZoneSize = (16 << 3) * asanenabledBit // redZoneSize(2048)
625+
626+
type mPadded struct {
627+
m
622628

623629
// Size the runtime.m structure so it fits in the 2048-byte size class, and
624630
// not in the next-smallest (1792-byte) size class. That leaves the 11 low
625631
// bits of muintptr values available for flags, as required for
626632
// GOEXPERIMENT=spinbitmutex.
627-
_ [goexperiment.SpinbitMutexInt * 64 * goarch.PtrSize / 8]byte
628-
_ [goexperiment.SpinbitMutexInt * 700 * (2 - goarch.PtrSize/4)]byte
633+
_ [goexperiment.SpinbitMutexInt * (2048 - mallocHeaderSize - mRedZoneSize - unsafe.Sizeof(m{}))]byte
629634
}
630635

631636
type p struct {

0 commit comments

Comments
 (0)