]> git.apps.os.sepia.ceph.com Git - fscrypt.git/commitdiff
Run the Garbage Collector in the timing loop
authorJoe Richey <joerichey@google.com>
Mon, 24 May 2021 10:42:01 +0000 (03:42 -0700)
committerJoe Richey <joerichey@google.com>
Mon, 24 May 2021 10:42:01 +0000 (03:42 -0700)
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>
actions/config.go

index fb0e3c1e7257198e6e1267a4bebd15f469a4b3a3..a8eb029dbdcce3064677bacf223070aa6628c02f 100644 (file)
@@ -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
 }