Description
Problem
Even when Deno is running in a containerized environment (i.e. cgroups), the entire system's total memory amount is passed to V8 when configuring heap limits.
As a result, Deno can easily hit OOM under cgroups with memory limit way less than the entire system's total memory when the workload is memory heavy.
Reproducer
Start a docker container with --memory=512m
and run v8.getHeapStatistics()
.
In Node:
$ docker run -it --memory=512m node:22.15.0
Welcome to Node.js v22.15.0.
Type ".help" for more information.
> const v8 = await import("node:v8");
undefined
> v8.getHeapStatistics().heap_size_limit
271581184
heap_size_limit
is 259Mi, about half of the amount allocated to the container.
In Deno:
$ docker run -it --memory=512m --entrypoint /bin/bash denoland/deno:2.2.12
root@9a2a0916720a:/# deno
Deno 2.2.12
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
> const v8 = await import("node:v8");
undefined
> v8.getHeapStatistics().heap_size_limit
4496293888
heap_size_limit
is over 4Gi which is obviously exceeding the container allocated memory.
What is expected
Deno passes memory limit that takes cgroups into account when configuring V8 isolate.
Other info
Version: Deno 2.2.12
Ref: nodejs/node#47259 - Node.js addressed a similar issue (for cgroups v2 though)