[go] runtime: reduce contention in (*lfstack).pop

0 views
Skip to first unread message

Michael Knyszek (Gerrit)

unread,
Oct 22, 2025, 8:02:34 PM (13 hours ago) Oct 22
to Fannie Zhang, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Go LUCI, Michael Pratt, t hepudds, Emmanuel Odeke, Ian Lance Taylor, Gopher Robot, golang-co...@googlegroups.com

Michael Knyszek submitted the change

Change information

Commit message:
runtime: use backoff and ISB instruction to reduce contention in (*lfstack).pop and (*spanSet).pop on arm64

When profiling CPU usage LiveKit on AArch64/x86 (AWS), the graphs show
CPU spikes that was repeating in a semi-periodic manner and spikes occur
when the GC(garbage collector) is active.

Our analysis found that the getempty function accounted for 10.54% of the
overhead, which was mainly caused by the work.empty.pop() function. And
listing pop shows that the majority of the time, with a 10.29% overhead,
is spent on atomic.Cas64((*uint64)(head), old, next).

This patch adds a backoff approach to reduce the high overhead of the
atomic operation primarily occurs when contention over a specific memory
address increases, typically with the rise in the number of threads.

Note that on paltforms other than arm64, the initial value of backoff is zero.

This patch rewrites the implementation of procyield() on arm64, which is an
Armv8.0-A compatible delay function using the counter-timer.

The garbage collector benchmark:

│ master │ opt │
│ sec/op │ sec/op vs base │
Garbage/benchmem-MB=64-160 3.782m ± 4% 2.264m ± 2% -40.12% (p=0.000 n=10)
│ user+sys-sec/op │ user+sys-sec/op vs base │
Garbage/benchmem-MB=64-160 433.5m ± 4% 255.4m ± 2% -41.08% (p=0.000 n=10)

Reference for backoff mechianism:
https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/multi-threaded-applications-arm
Change-Id: Ie8128a2243ceacbb82ab2a88941acbb8428bad94
Reviewed-by: Michael Knyszek <mkny...@google.com>
Reviewed-by: Michael Pratt <mpr...@google.com>
Files:
  • M src/runtime/asm_arm64.s
  • M src/runtime/lfstack.go
  • M src/runtime/mspanset.go
Change size: M
Delta: 3 files changed, 80 insertions(+), 5 deletions(-)
Branch: refs/heads/master
Submit Requirements:
  • requirement satisfiedCode-Review: +2 by Michael Knyszek, +1 by Michael Pratt
  • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ie8128a2243ceacbb82ab2a88941acbb8428bad94
Gerrit-Change-Number: 654895
Gerrit-PatchSet: 11
Gerrit-Owner: Fannie Zhang <Fannie...@arm.com>
Gerrit-Reviewer: Fannie Zhang <Fannie...@arm.com>
Gerrit-Reviewer: Michael Knyszek <mkny...@google.com>
Gerrit-Reviewer: Michael Pratt <mpr...@google.com>
Gerrit-Reviewer: t hepudds <thepud...@gmail.com>
Gerrit-CC: Emmanuel Odeke <emma...@orijtech.com>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages