Skip to content

Commit bef691c

Browse files
committed
Expose constrained memory as Sys.total_memory; add Sys.physical_memory.
1 parent 3a34293 commit bef691c

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

base/sysinfo.jl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export BINDIR,
2020
loadavg,
2121
free_memory,
2222
total_memory,
23+
physical_memory,
2324
isapple,
2425
isbsd,
2526
isdragonfly,
@@ -257,8 +258,25 @@ free_memory() = ccall(:uv_get_free_memory, UInt64, ())
257258
Sys.total_memory()
258259
259260
Get the total memory in RAM (including that which is currently used) in bytes.
261+
This amount may be constrained, e.g., by Linux control groups. For the unconstrained
262+
amount, see `Sys.physical_memory()`.
260263
"""
261-
total_memory() = ccall(:uv_get_total_memory, UInt64, ())
264+
function total_memory()
265+
memory = ccall(:uv_get_constrained_memory, UInt64, ())
266+
if memory == typemax(UInt64)
267+
return physical_memory()
268+
else
269+
return memory
270+
end
271+
end
272+
273+
"""
274+
Sys.physical_memory()
275+
276+
Get the total memory in RAM (including that which is currently used) in bytes. The entire
277+
amount may not be available to the current process; see `Sys.total_memory()`.
278+
"""
279+
physical_memory() = ccall(:uv_get_total_memory, UInt64, ())
262280

263281
"""
264282
Sys.get_process_title()

0 commit comments

Comments
 (0)