diff options
| author | Joe Richey <joerichey@google.com> | 2022-08-27 01:01:31 -0700 |
|---|---|---|
| committer | Eric Biggers <ebiggers3@gmail.com> | 2022-12-04 14:36:56 -0800 |
| commit | 5c7c3bcbcf1d18842e8dd9d2c346acdfb06fcf23 (patch) | |
| tree | 6c19cef564c6c5f3c09c576d436574004661d8b6 /actions | |
| parent | 9d96413911725504aaf4f4f1b00d492ae21282de (diff) | |
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 <joerichey@google.com>
[ebiggers: also set TruncationFixed at the end of getHashingCosts()]
Signed-off-by: Eric Biggers <ebiggers@google.com>
Diffstat (limited to 'actions')
| -rw-r--r-- | actions/config.go | 21 |
1 files changed, 14 insertions, 7 deletions
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 } } |