Skip to content

src: use cgroups to get memory limits

Rodrigo Muino Tomonari requested to merge github/fork/kjin/res-limits into master

This PR improves the way we set the memory ceiling for a Node.js process. Previously we would use the physical memory size (from libuv) to estimate the necessary V8 heap sizes. The physical memory size is not necessarily the correct limit, e.g. if the process is running inside a docker container or is otherwise constrained.

This change adds the ability to get a memory limit set by linux cgroups, which is used by docker containers to set resource constraints.

I've created a "resource limits" namespace/class that maybe should be the interface through which all resource constraint parameters are retrieved. So far that is just the memory limit but this could be expanded to other cgroups controller params. Also, this functionality is not necessarily specific to linux, so it's possible to have other implementations for other platforms (though this change is primarily motivated by the docker use case). Currently, behavior for other platforms besides linux is unchanged.

See also this article about support for cgroups in Java.

cc/ @ofrobots

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

Merge request reports

Loading