From b9573511c6deb13e9d56ff28d8420ed99509a742 Mon Sep 17 00:00:00 2001 From: Joe Richey Date: Mon, 24 May 2021 03:42:01 -0700 Subject: [PATCH] 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 --- actions/config.go | 3 +++ 1 file changed, 3 insertions(+) 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 } -- 2.39.5