From bd4a357b3d27fe4cc292bc915f9d022feb9dc499 Mon Sep 17 00:00:00 2001 From: "Shuowang (Wayne) Zhang" Date: Wed, 9 Dec 2020 12:19:26 -0500 Subject: [PATCH] zos: implement uv_get_constrained_memory() Implementation is based on RLIMIT_MEMLIMIT. Co-authored-by: Igor Todorovski PR-URL: https://github.com/libuv/libuv/pull/3133 Reviewed-By: Richard Lau --- docs/src/misc.rst | 2 +- src/unix/os390.c | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/src/misc.rst b/docs/src/misc.rst index b2725c39..9a8595e5 100644 --- a/docs/src/misc.rst +++ b/docs/src/misc.rst @@ -533,7 +533,7 @@ API .. note:: This function currently only returns a non-zero value on Linux, based - on cgroups if it is present. + on cgroups if it is present, and on z/OS based on RLIMIT_MEMLIMIT. .. versionadded:: 1.29.0 diff --git a/src/unix/os390.c b/src/unix/os390.c index 2912579a..9f0c8a46 100644 --- a/src/unix/os390.c +++ b/src/unix/os390.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "zos-base.h" #if defined(__clang__) #include "csrsic.h" @@ -199,7 +200,13 @@ uint64_t uv_get_total_memory(void) { uint64_t uv_get_constrained_memory(void) { - return 0; /* Memory constraints are unknown. */ + struct rlimit rl; + + /* RLIMIT_MEMLIMIT return value is in megabytes rather than bytes. */ + if (getrlimit(RLIMIT_MEMLIMIT, &rl) == 0) + return rl.rlim_cur * 1024 * 1024; + + return 0; /* There is no memory limit set. */ }