From 5c7c3bcbcf1d18842e8dd9d2c346acdfb06fcf23 Mon Sep 17 00:00:00 2001 From: Joe Richey Date: Sat, 27 Aug 2022 01:01:31 -0700 Subject: Only use up to MaxParallelism CPUs This prevents panics on 256-core systems, and has a 300-core system use 255 CPUs (the max) rather than 44 CPUs (300 casted to a uint8). Signed-off-by: Joe Richey [ebiggers: also set TruncationFixed at the end of getHashingCosts()] Signed-off-by: Eric Biggers --- actions/config.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'actions/config.go') diff --git a/actions/config.go b/actions/config.go index 03d6b04..7c7c0e6 100644 --- a/actions/config.go +++ b/actions/config.go @@ -187,11 +187,17 @@ func getHashingCosts(target time.Duration) (*metadata.HashingCosts, error) { log.Printf("Finding hashing costs that take %v\n", target) // Start out with the minimal possible costs that use all the CPUs. - nCPUs := int64(runtime.NumCPU()) + parallelism := int64(runtime.NumCPU()) + // golang.org/x/crypto/argon2 only supports parallelism up to 255. + // For compatibility, don't use more than that amount. + if parallelism > metadata.MaxParallelism { + parallelism = metadata.MaxParallelism + } costs := &metadata.HashingCosts{ - Time: 1, - Memory: 8 * nCPUs, - Parallelism: nCPUs, + Time: 1, + Memory: 8 * parallelism, + Parallelism: parallelism, + TruncationFixed: true, } // If even the minimal costs are not fast enough, just return the @@ -233,9 +239,10 @@ func getHashingCosts(target time.Duration) (*metadata.HashingCosts, error) { if t >= target { f := float64(target-tPrev) / float64(t-tPrev) return &metadata.HashingCosts{ - Time: betweenCosts(costsPrev.Time, costs.Time, f), - Memory: betweenCosts(costsPrev.Memory, costs.Memory, f), - Parallelism: costs.Parallelism, + Time: betweenCosts(costsPrev.Time, costs.Time, f), + Memory: betweenCosts(costsPrev.Memory, costs.Memory, f), + Parallelism: costs.Parallelism, + TruncationFixed: costs.TruncationFixed, }, nil } } -- cgit v1.2.3