Skip to content

Commit

Permalink
Expose constrained memory as Sys.(total|free)_memory; add Sys.physica…
Browse files Browse the repository at this point in the history
…l_(total_free)_memory.
  • Loading branch information
maleadt committed Sep 19, 2022
1 parent 25a33b7 commit e01ce3a
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions base/sysinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export BINDIR,
loadavg,
free_memory,
total_memory,
physical_free_memory,
physical_total_memory,
isapple,
isbsd,
isdragonfly,
Expand Down Expand Up @@ -246,19 +248,44 @@ function loadavg()
return loadavg_
end

"""
Sys.free_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()`.
"""
free_physical_memory() = ccall(:uv_get_free_memory, UInt64, ())

"""
Sys.total_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()`.
"""
total_physical_memory() = ccall(:uv_get_total_memory, UInt64, ())

"""
Sys.free_memory()
Get the total free memory in RAM in bytes.
"""
free_memory() = ccall(:uv_get_free_memory, UInt64, ())
free_memory() = ccall(:uv_get_available_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 == 0
return total_physical_memory()
else
return memory
end
end

"""
Sys.get_process_title()
Expand Down

0 comments on commit e01ce3a

Please sign in to comment.