Repository: node
Issue: Memory allocation problem after upgrade from version 14.16.1 to 14.17.0
Labels: windows,v8 engine,memory

<!--
Thank you for reporting an issue.

This issue tracker is for bugs and issues found within Node.js core.
If you require more general support please file an issue on our help
repo. https://github.com/nodejs/help


Please fill in as much of the template below as you're able.

Version: output of `node -v`
Platform: output of `uname -a` (UNIX), or output of `"$([Environment]::OSVersion | ForEach-Object VersionString) $(if ([Environment]::Is64BitOperatingSystem) { "x64" } else { "x86" })"` in PowerShell console (Windows)
Subsystem: if known, please specify affected core module name
-->

After upgrade from version 14.16.1 to 14.17.0 our project stopped building. I think there is problem with using --max-old-space-size option. I have prepared an example application https://github.com/stachupl/node-memory-allocation where you can see the incorrect operation of this option.

* **Version**: 14.17.0
* **Platform**: Microsoft Windows NT 10.0.19042.0 x64

### What steps will reproduce the bug?

<!--
Enter details about your bug, preferably a simple code snippet that can be
run using `node` directly without installing third-party dependencies.
-->

<!--StartFragment-->
"scripts": {
  "build": "webpack",
  "build2": "node --max-old-space-size=8096 node_modules/webpack/bin/webpack",
  "build3": "node --max-old-space-size=8192 node_modules/webpack/bin/webpack"
},
<!--EndFragment-->

Running commands npm run build and npm run build2 works fine. Running the npm run build3 command causes an error.

> node --max-old-space-size=8192 node_modules/webpack/bin/webpack


<--- Last few GCs --->

[9508:04153330]       47 ms: Mark-sweep 1.2 (3.3) -> 1.0 (3.3) MB, 1.9 / 0.0 ms  (average mu = 0.893, current mu = 0.895) allocation failure GC in old space requested
[9508:04153330]       50 ms: Mark-sweep 1.0 (3.3) -> 1.0 (3.3) MB, 1.5 / 0.0 ms  (average mu = 0.829, current mu = 0.398) allocation failure GC in old space requested
[9508:04153330]       53 ms: Mark-sweep 1.0 (3.3) -> 1.0 (3.3) MB, 1.6 / 0.0 ms  (average mu = 0.740, current mu = 0.424) allocation failure GC in old space requested


<--- JS stacktrace --->

FATAL ERROR: MarkCompactCollector: young object promotion failed Allocation failed - JavaScript heap out of memory
npm ERR! code ELIFECYCLE
npm ERR! errno 134
npm ERR! webpack-demo@1.0.0 build3: `node --max-old-space-size=8192 node_modules/webpack/bin/webpack`
npm ERR! Exit status 134
npm ERR!
npm ERR! Failed at the webpack-demo@1.0.0 build3 script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

2 info using npm@6.14.13
3 info using node@v14.17.0
4 verbose run-script [ 'prebuild3', 'build3', 'postbuild3' ]
5 info lifecycle webpack-demo@1.0.0~prebuild3: webpack-demo@1.0.0
6 info lifecycle webpack-demo@1.0.0~build3: webpack-demo@1.0.0
7 verbose lifecycle webpack-demo@1.0.0~build3: unsafe-perm in lifecycle true
8 verbose lifecycle webpack-demo@1.0.0~build3: PATH: ...
9 verbose lifecycle webpack-demo@1.0.0~build3: CWD: C:\Users\user\Projects\webpack-demo
10 silly lifecycle webpack-demo@1.0.0~build3: Args: [
10 silly lifecycle   '/d /s /c',
10 silly lifecycle   'node --max-old-space-size=8192 node_modules/webpack/bin/webpack'
10 silly lifecycle ]
11 silly lifecycle webpack-demo@1.0.0~build3: Returned: code: 134  signal: null
12 info lifecycle webpack-demo@1.0.0~build3: Failed to exec build3 script
13 verbose stack Error: webpack-demo@1.0.0 build3: `node --max-old-space-size=8192 node_modules/webpack/bin/webpack`
13 verbose stack Exit status 134
13 verbose stack     at EventEmitter.<anonymous> (C:\Users\user\ProcesDevel\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:376:20)
13 verbose stack     at ChildProcess.<anonymous> (C:\Users\user\ProcesDevel\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:376:20)
13 verbose stack     at maybeClose (internal/child_process.js:1055:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
14 verbose pkgid webpack-demo@1.0.0
15 verbose cwd C:\Users\user\Projects\webpack-demo
16 verbose Windows_NT 10.0.19042
17 verbose argv "C:\\Users\\user\\ProcesDevel\\nodejs\\node.exe" "C:\\Users\\\user\\ProcesDevel\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build3"
18 verbose node v14.17.0
19 verbose npm  v6.14.13
20 error code ELIFECYCLE
21 error errno 134
22 error webpack-demo@1.0.0 build3: `node --max-old-space-size=8192 node_modules/webpack/bin/webpack`
22 error Exit status 134
23 error Failed at the webpack-demo@1.0.0 build3 script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 134, true ]

### How often does it reproduce? Is there a required condition?
Always

### What is the expected behavior?
Building without errors
<!--
If possible please provide textual output instead of screenshots.
-->

### What do you see instead?

<!--
If possible please provide textual output instead of screenshots.
-->
Memory allocation failure

### Additional information

<!--
Tell us anything else you think we should know.
-->