From bc092114c1f7645cd1efdce947359ff61d0d2171 Mon Sep 17 00:00:00 2001 From: Alexis Svinartchouk Date: Tue, 18 Aug 2020 17:14:23 +0200 Subject: [PATCH] Don't use more than a 8th of the system memory as buffers Change-type: patch --- lib/gui/modules/child-writer.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/gui/modules/child-writer.ts b/lib/gui/modules/child-writer.ts index 623b7b04..24052220 100644 --- a/lib/gui/modules/child-writer.ts +++ b/lib/gui/modules/child-writer.ts @@ -18,6 +18,7 @@ import { Drive as DrivelistDrive } from 'drivelist'; import * as sdk from 'etcher-sdk'; import { cleanupTmpFiles } from 'etcher-sdk/build/tmp'; import * as ipc from 'node-ipc'; +import { totalmem } from 'os'; import { toJSON } from '../../shared/errors'; import { GENERAL_ERROR, SUCCESS } from '../../shared/exit-codes'; @@ -117,7 +118,11 @@ async function writeAndValidate({ onProgress, verify, trim: autoBlockmapping, - numBuffers: Math.min(2 + (destinations.length - 1) * 32, 256), + numBuffers: Math.min( + 2 + (destinations.length - 1) * 32, + 256, + Math.floor(totalmem() / 1024 ** 2 / 8), + ), decompressFirst, }); const result: WriteResult = {