Skip to content
Closed
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
8 changes: 6 additions & 2 deletions doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -1114,15 +1114,19 @@ over the IPC channel using `process.send()`.
added:
- v19.6.0
- v18.15.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/52039
description: Aligned return value with `uv_get_constrained_memory`.
-->

> Stability: 1 - Experimental

* {number|undefined}
* {number}

Gets the amount of memory available to the process (in bytes) based on
limits imposed by the OS. If there is no such constraint, or the constraint
is unknown, `undefined` is returned.
is unknown, `0` is returned.

See [`uv_get_constrained_memory`][uv_get_constrained_memory] for more
information.
Expand Down
4 changes: 1 addition & 3 deletions src/node_process_methods.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,7 @@ static void MemoryUsage(const FunctionCallbackInfo<Value>& args) {

static void GetConstrainedMemory(const FunctionCallbackInfo<Value>& args) {
uint64_t value = uv_get_constrained_memory();
if (value != 0) {
args.GetReturnValue().Set(static_cast<double>(value));
}
args.GetReturnValue().Set(static_cast<double>(value));
}

void RawDebug(const FunctionCallbackInfo<Value>& args) {
Expand Down
10 changes: 2 additions & 8 deletions test/parallel/test-process-constrained-memory.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
'use strict';
require('../common');
const assert = require('assert');
const { Worker } = require('worker_threads');

const constrainedMemory = process.constrainedMemory();
if (constrainedMemory !== undefined) {
assert(constrainedMemory > 0);
}
if (!process.env.isWorker) {
process.env.isWorker = true;
new Worker(__filename);
}
assert.strictEqual(typeof constrainedMemory, 'number');