mirror of https://github.com/golang/go.git
runtime: reduced struct sizes found via pahole
During my research of pahole with Go structs, I've found couple of structs in runtime/ pkg where we can reduce several structs' sizes highligted by pahole tool which detect byte holes and paddings. Overall, there are 80 bytes reduced. Change-Id: I398e5ed6f5b199394307741981cb5ad5b875e98f Reviewed-on: https://go-review.googlesource.com/c/go/+/578795 Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Joedian Reid <joedian@google.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
674657e130
commit
552faa8927
|
|
@ -33,16 +33,6 @@ type gcCPULimiterState struct {
|
||||||
lock atomic.Uint32
|
lock atomic.Uint32
|
||||||
|
|
||||||
enabled atomic.Bool
|
enabled atomic.Bool
|
||||||
bucket struct {
|
|
||||||
// Invariants:
|
|
||||||
// - fill >= 0
|
|
||||||
// - capacity >= 0
|
|
||||||
// - fill <= capacity
|
|
||||||
fill, capacity uint64
|
|
||||||
}
|
|
||||||
// overflow is the cumulative amount of GC CPU time that we tried to fill the
|
|
||||||
// bucket with but exceeded its capacity.
|
|
||||||
overflow uint64
|
|
||||||
|
|
||||||
// gcEnabled is an internal copy of gcBlackenEnabled that determines
|
// gcEnabled is an internal copy of gcBlackenEnabled that determines
|
||||||
// whether the limiter tracks total assist time.
|
// whether the limiter tracks total assist time.
|
||||||
|
|
@ -55,6 +45,20 @@ type gcCPULimiterState struct {
|
||||||
// the mark and sweep phases.
|
// the mark and sweep phases.
|
||||||
transitioning bool
|
transitioning bool
|
||||||
|
|
||||||
|
// test indicates whether this instance of the struct was made for testing purposes.
|
||||||
|
test bool
|
||||||
|
|
||||||
|
bucket struct {
|
||||||
|
// Invariants:
|
||||||
|
// - fill >= 0
|
||||||
|
// - capacity >= 0
|
||||||
|
// - fill <= capacity
|
||||||
|
fill, capacity uint64
|
||||||
|
}
|
||||||
|
// overflow is the cumulative amount of GC CPU time that we tried to fill the
|
||||||
|
// bucket with but exceeded its capacity.
|
||||||
|
overflow uint64
|
||||||
|
|
||||||
// assistTimePool is the accumulated assist time since the last update.
|
// assistTimePool is the accumulated assist time since the last update.
|
||||||
assistTimePool atomic.Int64
|
assistTimePool atomic.Int64
|
||||||
|
|
||||||
|
|
@ -77,9 +81,6 @@ type gcCPULimiterState struct {
|
||||||
//
|
//
|
||||||
// gomaxprocs isn't used directly so as to keep this structure unit-testable.
|
// gomaxprocs isn't used directly so as to keep this structure unit-testable.
|
||||||
nprocs int32
|
nprocs int32
|
||||||
|
|
||||||
// test indicates whether this instance of the struct was made for testing purposes.
|
|
||||||
test bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// limiting returns true if the CPU limiter is currently enabled, meaning the Go GC
|
// limiting returns true if the CPU limiter is currently enabled, meaning the Go GC
|
||||||
|
|
|
||||||
|
|
@ -281,15 +281,19 @@ type scavengerState struct {
|
||||||
// g is the goroutine the scavenger is bound to.
|
// g is the goroutine the scavenger is bound to.
|
||||||
g *g
|
g *g
|
||||||
|
|
||||||
// parked is whether or not the scavenger is parked.
|
|
||||||
parked bool
|
|
||||||
|
|
||||||
// timer is the timer used for the scavenger to sleep.
|
// timer is the timer used for the scavenger to sleep.
|
||||||
timer *timer
|
timer *timer
|
||||||
|
|
||||||
// sysmonWake signals to sysmon that it should wake the scavenger.
|
// sysmonWake signals to sysmon that it should wake the scavenger.
|
||||||
sysmonWake atomic.Uint32
|
sysmonWake atomic.Uint32
|
||||||
|
|
||||||
|
// parked is whether or not the scavenger is parked.
|
||||||
|
parked bool
|
||||||
|
|
||||||
|
// printControllerReset instructs printScavTrace to signal that
|
||||||
|
// the controller was reset.
|
||||||
|
printControllerReset bool
|
||||||
|
|
||||||
// targetCPUFraction is the target CPU overhead for the scavenger.
|
// targetCPUFraction is the target CPU overhead for the scavenger.
|
||||||
targetCPUFraction float64
|
targetCPUFraction float64
|
||||||
|
|
||||||
|
|
@ -312,10 +316,6 @@ type scavengerState struct {
|
||||||
// value. Used if the controller's assumptions fail to hold.
|
// value. Used if the controller's assumptions fail to hold.
|
||||||
controllerCooldown int64
|
controllerCooldown int64
|
||||||
|
|
||||||
// printControllerReset instructs printScavTrace to signal that
|
|
||||||
// the controller was reset.
|
|
||||||
printControllerReset bool
|
|
||||||
|
|
||||||
// sleepStub is a stub used for testing to avoid actually having
|
// sleepStub is a stub used for testing to avoid actually having
|
||||||
// the scavenger sleep.
|
// the scavenger sleep.
|
||||||
//
|
//
|
||||||
|
|
|
||||||
|
|
@ -102,14 +102,14 @@ type pollDesc struct {
|
||||||
|
|
||||||
lock mutex // protects the following fields
|
lock mutex // protects the following fields
|
||||||
closing bool
|
closing bool
|
||||||
|
rrun bool // whether rt is running
|
||||||
|
wrun bool // whether wt is running
|
||||||
user uint32 // user settable cookie
|
user uint32 // user settable cookie
|
||||||
rseq uintptr // protects from stale read timers
|
rseq uintptr // protects from stale read timers
|
||||||
rt timer // read deadline timer
|
rt timer // read deadline timer
|
||||||
rrun bool // whether rt is running
|
|
||||||
rd int64 // read deadline (a nanotime in the future, -1 when expired)
|
rd int64 // read deadline (a nanotime in the future, -1 when expired)
|
||||||
wseq uintptr // protects from stale write timers
|
wseq uintptr // protects from stale write timers
|
||||||
wt timer // write deadline timer
|
wt timer // write deadline timer
|
||||||
wrun bool // whether wt is running
|
|
||||||
wd int64 // write deadline (a nanotime in the future, -1 when expired)
|
wd int64 // write deadline (a nanotime in the future, -1 when expired)
|
||||||
self *pollDesc // storage for indirect interface. See (*pollDesc).makeArg.
|
self *pollDesc // storage for indirect interface. See (*pollDesc).makeArg.
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6024,8 +6024,8 @@ func sysmon() {
|
||||||
|
|
||||||
type sysmontick struct {
|
type sysmontick struct {
|
||||||
schedtick uint32
|
schedtick uint32
|
||||||
schedwhen int64
|
|
||||||
syscalltick uint32
|
syscalltick uint32
|
||||||
|
schedwhen int64
|
||||||
syscallwhen int64
|
syscallwhen int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -510,12 +510,12 @@ type g struct {
|
||||||
sleepWhen int64 // when to sleep until
|
sleepWhen int64 // when to sleep until
|
||||||
selectDone atomic.Uint32 // are we participating in a select and did someone win the race?
|
selectDone atomic.Uint32 // are we participating in a select and did someone win the race?
|
||||||
|
|
||||||
coroarg *coro // argument during coroutine transfers
|
|
||||||
|
|
||||||
// goroutineProfiled indicates the status of this goroutine's stack for the
|
// goroutineProfiled indicates the status of this goroutine's stack for the
|
||||||
// current in-progress goroutine profile
|
// current in-progress goroutine profile
|
||||||
goroutineProfiled goroutineProfileStateHolder
|
goroutineProfiled goroutineProfileStateHolder
|
||||||
|
|
||||||
|
coroarg *coro // argument during coroutine transfers
|
||||||
|
|
||||||
// Per-G tracer state.
|
// Per-G tracer state.
|
||||||
trace gTraceState
|
trace gTraceState
|
||||||
|
|
||||||
|
|
@ -604,8 +604,8 @@ type m struct {
|
||||||
// there's no stack to put them on. That is their sole purpose.
|
// there's no stack to put them on. That is their sole purpose.
|
||||||
waitunlockf func(*g, unsafe.Pointer) bool
|
waitunlockf func(*g, unsafe.Pointer) bool
|
||||||
waitlock unsafe.Pointer
|
waitlock unsafe.Pointer
|
||||||
waitTraceBlockReason traceBlockReason
|
|
||||||
waitTraceSkip int
|
waitTraceSkip int
|
||||||
|
waitTraceBlockReason traceBlockReason
|
||||||
|
|
||||||
syscalltick uint32
|
syscalltick uint32
|
||||||
freelink *m // on sched.freem
|
freelink *m // on sched.freem
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ func TestSizeof(t *testing.T) {
|
||||||
_32bit uintptr // size on 32bit platforms
|
_32bit uintptr // size on 32bit platforms
|
||||||
_64bit uintptr // size on 64bit platforms
|
_64bit uintptr // size on 64bit platforms
|
||||||
}{
|
}{
|
||||||
{runtime.G{}, 272, 440}, // g, but exported for testing
|
{runtime.G{}, 272, 432}, // g, but exported for testing
|
||||||
{runtime.Sudog{}, 56, 88}, // sudog, but exported for testing
|
{runtime.Sudog{}, 56, 88}, // sudog, but exported for testing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -401,13 +401,12 @@ type moduledata struct {
|
||||||
modulehashes []modulehash
|
modulehashes []modulehash
|
||||||
|
|
||||||
hasmain uint8 // 1 if module contains the main function, 0 otherwise
|
hasmain uint8 // 1 if module contains the main function, 0 otherwise
|
||||||
|
bad bool // module failed to load and should be ignored
|
||||||
|
|
||||||
gcdatamask, gcbssmask bitvector
|
gcdatamask, gcbssmask bitvector
|
||||||
|
|
||||||
typemap map[typeOff]*_type // offset to *_rtype in previous module
|
typemap map[typeOff]*_type // offset to *_rtype in previous module
|
||||||
|
|
||||||
bad bool // module failed to load and should be ignored
|
|
||||||
|
|
||||||
next *moduledata
|
next *moduledata
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue