From 55d7dcc3cd4b3ee6bca0ab7101866d785776ff51 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Tue, 10 Nov 2020 21:02:18 +0800 Subject: [PATCH] runtime: optimize the memory padding in p struct Since allocation for p struct will be rounded up to the next size class, the two relevant adjacent classes for this case are 9728 bytes and 10240 bytes. A p is currently 10072 bytes, so it gets rounded up to 10240 bytes when we allocate one, So the pad in p struct is unnecessary, eliminate it and add comments for warning the false sharing. Change-Id: Iae8b32931d1beddbfff1f58044d8401703da6407 Reviewed-on: https://go-review.googlesource.com/c/go/+/268759 Reviewed-by: Keith Randall Run-TryBot: Keith Randall TryBot-Result: Go Bot Trust: Ian Lance Taylor --- src/runtime/runtime2.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go index 5bd283d12f..f5318e6f11 100644 --- a/src/runtime/runtime2.go +++ b/src/runtime/runtime2.go @@ -5,7 +5,6 @@ package runtime import ( - "internal/cpu" "runtime/internal/atomic" "runtime/internal/sys" "unsafe" @@ -713,7 +712,8 @@ type p struct { // scheduler ASAP (regardless of what G is running on it). preempt bool - pad cpu.CacheLinePad + // Padding is no longer needed. False sharing is now not a worry because p is large enough + // that its size class is an integer multiple of the cache line size (for any of our architectures). } type schedt struct { -- 2.50.0