diff options
| author | Joseph Richey <joerichey@google.com> | 2021-05-24 22:18:42 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-24 22:18:42 -0700 |
| commit | 8f569e461e098d6c2f4b6b73b06243351c635f69 (patch) | |
| tree | ee4e314ceff92d77a9a36a57db5353fc55609aeb /actions | |
| parent | e479779a7f39e66d3f76673f18308906e817be02 (diff) | |
| parent | b9573511c6deb13e9d56ff28d8420ed99509a742 (diff) | |
Merge pull request #292 from josephlr/mem
Only use 1/8 of the system RAM and run the Garbage Collector in the timing loop
Diffstat (limited to 'actions')
| -rw-r--r-- | actions/config.go | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/actions/config.go b/actions/config.go index b848d92..a8eb029 100644 --- a/actions/config.go +++ b/actions/config.go @@ -242,7 +242,7 @@ func getHashingCosts(target time.Duration) (*metadata.HashingCosts, error) { // memoryBytesLimit returns the maximum amount of memory we will use for // passphrase hashing. This will never be more than a reasonable maximum (for -// compatibility) or half the available system RAM. +// compatibility) or an 8th the available system RAM. func memoryBytesLimit() int64 { // The sysinfo syscall only fails if given a bad address var info unix.Sysinfo_t @@ -250,7 +250,7 @@ func memoryBytesLimit() int64 { util.NeverError(err) totalRAMBytes := int64(info.Totalram) - return util.MinInt64(totalRAMBytes/2, maxMemoryBytes) + return util.MinInt64(totalRAMBytes/8, maxMemoryBytes) } // betweenCosts returns a cost between a and b. Specifically, it returns the @@ -276,6 +276,9 @@ func timeHashingCosts(costs *metadata.HashingCosts) (time.Duration, error) { } end := cpuTimeInNanoseconds() + // This uses a lot of memory, run the garbage collector + runtime.GC() + return time.Duration((end - begin) / costs.Parallelism), nil } |