From 1ac740106ea45006ed7a3244f69135673e209cd9 Mon Sep 17 00:00:00 2001 From: theanarkh Date: Sun, 15 Jan 2023 12:55:54 +0800 Subject: [PATCH] src,lib: add constrainedMemory API for process --- doc/api/process.md | 22 +++++++++++++++++++ lib/internal/bootstrap/node.js | 1 + lib/internal/process/per_thread.js | 9 ++++++++ lib/internal/process/pre_execution.js | 2 -- src/node_process_methods.cc | 7 ++++++ .../test-process-constrained-memory.js | 12 ++++++++++ 6 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 test/parallel/test-process-constrained-memory.js diff --git a/doc/api/process.md b/doc/api/process.md index 80fa2f826de93a..b5da672f06e642 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -1103,6 +1103,27 @@ and [Cluster][] documentation), the `process.connected` property will return Once `process.connected` is `false`, it is no longer possible to send messages over the IPC channel using `process.send()`. +## `process.constrainedMemory()` + + + +> Stability: 1 - Experimental + +* {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. + +It is not unusual for this value to be less than or greater than `os.totalmem()`. +This function currently only returns a non-zero value on Linux, based on cgroups +if it is present, and on z/OS based on `RLIMIT_MEMLIMIT`. + +See [`uv_get_constrained_memory`][uv_get_constrained_memory] for more +information. + ## `process.cpuUsage([previousValue])`