From bef691cbd625c529ca0ca16ef5f4b3ef5d7d9841 Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Fri, 16 Sep 2022 16:33:30 +0200 Subject: [PATCH] Expose constrained memory as Sys.total_memory; add Sys.physical_memory. --- base/sysinfo.jl | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/base/sysinfo.jl b/base/sysinfo.jl index f0852f32fc17d..c8214a86150f1 100644 --- a/base/sysinfo.jl +++ b/base/sysinfo.jl @@ -20,6 +20,7 @@ export BINDIR, loadavg, free_memory, total_memory, + physical_memory, isapple, isbsd, isdragonfly, @@ -257,8 +258,25 @@ free_memory() = ccall(:uv_get_free_memory, UInt64, ()) Sys.total_memory() Get the total memory in RAM (including that which is currently used) in bytes. +This amount may be constrained, e.g., by Linux control groups. For the unconstrained +amount, see `Sys.physical_memory()`. """ -total_memory() = ccall(:uv_get_total_memory, UInt64, ()) +function total_memory() + memory = ccall(:uv_get_constrained_memory, UInt64, ()) + if memory == typemax(UInt64) + return physical_memory() + else + return memory + end +end + +""" + Sys.physical_memory() + +Get the total memory in RAM (including that which is currently used) in bytes. The entire +amount may not be available to the current process; see `Sys.total_memory()`. +""" +physical_memory() = ccall(:uv_get_total_memory, UInt64, ()) """ Sys.get_process_title()