zos: implement uv_get_constrained_memory()

Implementation is based on RLIMIT_MEMLIMIT.

Co-authored-by: Igor Todorovski <itodorov@ca.ibm.com>
PR-URL: https://github.com/libuv/libuv/pull/3133
Reviewed-By: Richard Lau <rlau@redhat.com>
This commit is contained in:
Shuowang (Wayne) Zhang 2020-12-09 12:19:26 -05:00 committed by Santiago Gimeno
parent 9737baf004
commit bd4a357b3d
No known key found for this signature in database
GPG Key ID: F28C3C8DA33C03BE
2 changed files with 9 additions and 2 deletions

View File

@ -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

View File

@ -28,6 +28,7 @@
#include <builtins.h>
#include <termios.h>
#include <sys/msg.h>
#include <sys/resource.h>
#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. */
}