From f875f8fe76160699432cdab8a23cfd292462c2b3 Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Thu, 30 Apr 2020 16:07:31 -0400 Subject: [PATCH] [dev.link] cmd/link: tweaks to data alignment processing MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Now that the loader's internal storage mechanism for symbol alignment is array-based and not map-based, we can go back to computing symbol alignment in the parallel-by-section section of dodata. With this patch plus the previous one, this produces a small kubelet speedup: $ benchstat out.devlink.txt out.align.txt name old time/op new time/op delta RelinkKubelet 13.3s ± 2% 13.1s ± 2% -1.27% (p=0.000 n=20+20) RelinkKubelet-WithoutDebug 7.36s ± 5% 7.14s ± 3% -3.00% (p=0.000 n=20+20) Change-Id: I9eb0e8fea6aeb12f188f499e9031d5a3a23232c7 Reviewed-on: https://go-review.googlesource.com/c/go/+/231221 Run-TryBot: Than McIntosh TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang Reviewed-by: Jeremy Faller --- src/cmd/link/internal/ld/data.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go index 102fcabe47..162ef9ba4e 100644 --- a/src/cmd/link/internal/ld/data.go +++ b/src/cmd/link/internal/ld/data.go @@ -1436,16 +1436,12 @@ func (ctxt *Link) dodata2(symGroupType []sym.SymKind) { // Move any RO data with relocations to a separate section. state.makeRelroForSharedLib2(ctxt) - // Set explicit alignment here, so as to avoid having to update - // symbol alignment in doDataSect2, which would cause a concurrent - // map read/write violation. - // NOTE: this needs to be done after dynreloc2, where symbol size - // may change. - for _, list := range state.data2 { - for _, s := range list { - state.symalign2(s) - } - } + // Set alignment for the symbol with the largest known index, + // so as to trigger allocation of the loader's internal + // alignment array. This will avoid data races in the parallel + // section below. + lastSym := loader.Sym(ldr.NSym() - 1) + ldr.SetSymAlign(lastSym, ldr.SymAlign(lastSym)) // Sort symbols. var wg sync.WaitGroup @@ -2044,7 +2040,7 @@ func (state *dodataState) dodataSect2(ctxt *Link, symn sym.SymKind, syms []loade return si < sj }) - // Reap alignment, construct result + // Set alignment, construct result syms = syms[:0] for k := range sl { s := sl[k].sym -- 2.50.0