From 8aa31d5dae9644b3e8f6950af58c0cb83e8fc062 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 18 Apr 2017 13:12:58 +0300 Subject: [PATCH] sync: align poolLocal to CPU cache line size Make poolLocal size multiple of 128, so it aligns to CPU cache line on the most common architectures. This also has the following benefits: - It may help compiler substituting integer multiplication by bit shift inside indexLocal. - It shrinks poolLocal size from 176 bytes to 128 bytes on amd64, so now it fits two cache lines (or a single cache line on certain Intel CPUs - see https://software.intel.com/en-us/articles/optimizing-application-performance-on-intel-coret-microarchitecture-using-hardware-implemented-prefetchers). No measurable performance changes on linux/amd64 and linux/386. Change-Id: I11df0f064718a662e77a85d88b8a15a8919f25e9 Reviewed-on: https://go-review.googlesource.com/40918 Reviewed-by: Dmitry Vyukov Run-TryBot: Dmitry Vyukov TryBot-Result: Gobot Gobot --- src/sync/pool.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/sync/pool.go b/src/sync/pool.go index b3fd9d397c..e54f917225 100644 --- a/src/sync/pool.go +++ b/src/sync/pool.go @@ -54,11 +54,18 @@ type Pool struct { } // Local per-P Pool appendix. -type poolLocal struct { +type poolLocalInternal struct { private interface{} // Can be used only by the respective P. shared []interface{} // Can be used by any P. Mutex // Protects shared. - pad [128]byte // Prevents false sharing. +} + +type poolLocal struct { + poolLocalInternal + + // Prevents false sharing on widespread platforms with + // 128 mod (cache line size) = 0 . + pad [128 - unsafe.Sizeof(poolLocalInternal{})%128]byte } // from runtime -- 2.50.0