runtime: high contention in mheap_.lock causing low CPU utilization on allocation-intensive workload #23182
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Performance
Milestone
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go 1.8.0
Does this issue reproduce with the latest release?
It is reproducible with 1.9.2. We haven't tested with tip.
What operating system and processor architecture are you using (
go env
)?linux amd64
What did you do?
While tuning our application, we observed that on a system with 38 cores, we could not get more than 3000% CPU utilization. Investigation with
go tool trace
showed that all processors were always busy executing goroutines with no obvious idle times. Since the application is designed to be parallel, we suspected that the lower-than-expected CPU utilization is due to unforeseen contention and blocking, but block profiling did not show any significant user-level blocking, so we turned our attention to runtime-level contention.We instrumented
runtime.lock
to count the number of times threads have to callfutexsleep
, and record which locks they were waiting for. The hottest locks and the number of times they were contended within a 1-minute run time were:Sampling the call sites of
runtime.lock
reveals thatmheap_.lock
is contended most inruntime.(*mheap).alloc_m
, mostly called fromruntime.(*mcentral).grow
. By hackinggrow
to increase the number of pages reserved each timemcentral
needs more space for a size class, we were able to reduce the contention ofmheap_.lock
by a significant amount, and actually improved the average request latency of our application.The text was updated successfully, but these errors were encountered: