Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -3454,6 +3454,7 @@ V8 options that are allowed are:
* `--expose-gc`
* `--interpreted-frames-native-stack`
* `--jitless`
* `--max-heap-size`
* `--max-old-space-size`
* `--max-semi-space-size`
* `--perf-basic-prof-only-functions`
Expand Down Expand Up @@ -3796,6 +3797,12 @@ documented here:

### `--jitless`

### `--max-heap-size`

Specifies the maximum heap size (in megabytes) for the process.

This option is typically used to limit the amount of memory the process can use for its JavaScript heap.

<!-- Anchor to make sure old links find a target -->

<a id="--max-old-space-sizesize-in-megabytes"></a>
Expand Down
1 change: 1 addition & 0 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,7 @@ PerIsolateOptionsParser::PerIsolateOptionsParser(
"help system profilers to translate JavaScript interpreted frames",
V8Option{},
kAllowedInEnvvar);
AddOption("--max-heap-size", "", V8Option{}, kAllowedInEnvvar);
AddOption("--max-old-space-size", "", V8Option{}, kAllowedInEnvvar);
AddOption("--max-semi-space-size", "", V8Option{}, kAllowedInEnvvar);
AddOption("--perf-basic-prof", "", V8Option{}, kAllowedInEnvvar);
Expand Down
49 changes: 49 additions & 0 deletions test/common/v8-max-heap-size-option.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use strict';

const assert = require('assert');
const { spawnSync } = require('child_process');
const path = require('path');
const fs = require('fs');
const tmpdir = require('./tmpdir');

const testScript = `
const v8 = require('v8');
const stats = v8.getHeapStatistics();
const maxHeapSizeMB = Math.round(stats.heap_size_limit / 1024 / 1024);
console.log(maxHeapSizeMB);
`;

tmpdir.refresh();
const scriptPath = path.join(tmpdir.path, 'heap-limit-test.js');
fs.writeFileSync(scriptPath, testScript);

const child = spawnSync(
process.execPath,
[scriptPath],
{
encoding: 'utf8',
env: {
...process.env,
NODE_OPTIONS: '--max-heap-size=750',
},
},
);

assert.strictEqual(
child.status,
0,
[
`Child process did not exit cleanly.`,
` Exit code: ${child.status}`,
child.stderr ? ` Stderr: ${child.stderr.toString()}` : '',
child.stdout ? ` Stdout: ${child.stdout.toString()}` : '',
].filter(Boolean).join('\n'),
);
const output = child.stdout.trim();
const heapLimit = Number(output);

assert.strictEqual(
heapLimit,
750,
`max heap size is ${heapLimit}MB, expected 750MB`,
);
Loading