From 3591ba8578b5eff96c13afc6fdfcf95a96083761 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Thu, 30 Nov 2023 22:06:01 +0900 Subject: fix(ext/node): fix os.freemem (#21347) --- ext/node/polyfills/os.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'ext/node') diff --git a/ext/node/polyfills/os.ts b/ext/node/polyfills/os.ts index 06de4ad44..d1f5e7bfa 100644 --- a/ext/node/polyfills/os.ts +++ b/ext/node/polyfills/os.ts @@ -159,7 +159,14 @@ export function endianness(): "BE" | "LE" { /** Return free memory amount */ export function freemem(): number { - return Deno.systemMemoryInfo().free; + if (Deno.build.os === "linux") { + // On linux, use 'available' memory + // https://github.com/libuv/libuv/blob/a5c01d4de3695e9d9da34cfd643b5ff0ba582ea7/src/unix/linux.c#L2064 + return Deno.systemMemoryInfo().available; + } else { + // Use 'free' memory on other platforms + return Deno.systemMemoryInfo().free; + } } /** Not yet implemented */ -- cgit v1.2.3