aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Richey <joerichey@google.com>2021-05-24 03:42:01 -0700
committerJoe Richey <joerichey@google.com>2021-05-24 03:42:01 -0700
commitb9573511c6deb13e9d56ff28d8420ed99509a742 (patch)
treeee4e314ceff92d77a9a36a57db5353fc55609aeb
parent6f97cc7522ebb2adc56c4bdb278e80bf7b9d3656 (diff)
Run the Garbage Collector in the timing loop
Running `crypto.PassphraseHash` in a loop allocates a lot of memory. Golang is not always prudent about collecting the garbage from previous runs, resulting in a OOM error on memory-pressured systems. With a `maxMemoryBytes` of 128 MiB, this change reduces the maximum resident memory for `fscrypt setup` to 141 MiB (was perviously 405 MiB) Signed-off-by: Joe Richey <joerichey@google.com>
-rw-r--r--actions/config.go3
1 files changed, 3 insertions, 0 deletions
diff --git a/actions/config.go b/actions/config.go
index fb0e3c1..a8eb029 100644
--- a/actions/config.go
+++ b/actions/config.go
@@ -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
}