Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deno.systemMemoryInfo().available and Deno.systemMemoryInfo().free are incorrect on macOS #27435

Open
brettchalupa opened this issue Dec 20, 2024 · 0 comments

Comments

@brettchalupa
Copy link

brettchalupa commented Dec 20, 2024

Version: Deno 2.1.4
OS: macOS 14.6 (Sonoma)

I copied the example for reading system metrics (https://docs.deno.com/examples/reading_system_metrics/) to test it and noticed that Deno.systemMemoryInfo().available and Deno.systemMemoryInfo().free appear to be ~1000x smaller than they should be.

Total Memory: 16384 MB

what Deno.systemMemoryInfo() reports - deno 2.1.4
Free Memory: 0.102996826171875 MB
Available Memory: 4.8754119873046875 MB
Used Memory: 16379.124588012695 MB

corrected for macOS:
Free Memory: 105.46875 MB
Available Memory: 4992.421875 MB
Used Memory: 11391.578125 MB

Deno 2.1.4 Wrong Percentage: 99.97%
macOS Corrected Percentage: 69.53%

The corrected values are more accurate to what I see in macOS Activity Monitor and when running a similar Rust program with the sysinfo crate.

Repro Steps

deno run --allow-sys https://gist.githubusercontent.com/brettchalupa/62e489396ae4cf87ee59517fcc0880c4/raw/34d8cc2908644bd458dec5b4894f6468ba9644e4/deno_ram_check_bug.ts

View the Gist source.

Zoom into the problem code and fix for macOS:

console.log("what Deno.systemMemoryInfo() reports - deno 2.1.4");
console.log(`Free Memory: ${toMB(memoryInfo.free)} MB`);
console.log(`Available Memory: ${toMB(memoryInfo.available)} MB`);
console.log(
  `Used Memory: ${toMB(memoryInfo.total - memoryInfo.available)} MB`,
);

console.log("\ncorrected for macOS:");
console.log(`Free Memory: ${toMB(memoryInfo.free * 1024)} MB`);
console.log(`Available Memory: ${toMB(memoryInfo.available * 1024)} MB`);
console.log(
  `Used Memory: ${toMB(memoryInfo.total - memoryInfo.available * 1024)} MB`,
);

I'm not 100% sure whether the multiplication needs to be * 1024 or * 1000.

Additional Notes

  • I confirmed the values reported by Deno.systemMemoryInfo().available and .free are correct on Fedora Linux
  • I confirmed this isn't an issue on Windows 11 (although .available reports 0, but .free seems to be correct

See Also

@brettchalupa brettchalupa changed the title Deno.systemMemoryInfo().available and Deno.systemMemoryInfo().free are off by x1024 on macOS Deno.systemMemoryInfo().available and Deno.systemMemoryInfo().free are incorrect on macOS Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant