Skip to content

Commit d7bdf9c

Browse files
committed
Expose constrained memory as Sys.(total|free)_memory; add Sys.physical_(total_free)_memory.
1 parent 7c15a3c commit d7bdf9c

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

base/sysinfo.jl

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export BINDIR,
2020
loadavg,
2121
free_memory,
2222
total_memory,
23+
physical_free_memory,
24+
physical_total_memory,
2325
isapple,
2426
isbsd,
2527
isdragonfly,
@@ -246,19 +248,44 @@ function loadavg()
246248
return loadavg_
247249
end
248250

251+
"""
252+
Sys.free_physical_memory()
253+
254+
Get the total memory in RAM (including that which is currently used) in bytes. The entire
255+
amount may not be available to the current process; see `Sys.total_memory()`.
256+
"""
257+
free_physical_memory() = ccall(:uv_get_free_memory, UInt64, ())
258+
259+
"""
260+
Sys.total_physical_memory()
261+
262+
Get the total memory in RAM (including that which is currently used) in bytes. The entire
263+
amount may not be available to the current process; see `Sys.total_memory()`.
264+
"""
265+
total_physical_memory() = ccall(:uv_get_total_memory, UInt64, ())
266+
249267
"""
250268
Sys.free_memory()
251269
252270
Get the total free memory in RAM in bytes.
253271
"""
254-
free_memory() = ccall(:uv_get_free_memory, UInt64, ())
272+
free_memory() = ccall(:uv_get_available_memory, UInt64, ())
255273

256274
"""
257275
Sys.total_memory()
258276
259277
Get the total memory in RAM (including that which is currently used) in bytes.
278+
This amount may be constrained, e.g., by Linux control groups. For the unconstrained
279+
amount, see `Sys.physical_memory()`.
260280
"""
261-
total_memory() = ccall(:uv_get_total_memory, UInt64, ())
281+
function total_memory()
282+
memory = ccall(:uv_get_constrained_memory, UInt64, ())
283+
if memory == 0
284+
return total_physical_memory()
285+
else
286+
return memory
287+
end
288+
end
262289

263290
"""
264291
Sys.get_process_title()

0 commit comments

Comments
 (0)