Skip to content

Commit

Permalink
sysinfo: fix the unit of maxrss on FreeBSD
Browse files Browse the repository at this point in the history
The value from rusage.ru_maxrss is in kilobytes.

Ref #22997
(cherry picked from commit f60636f)
  • Loading branch information
iblislin authored and ararslan committed May 8, 2018
1 parent e5ae504 commit e22b1f4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions base/sysinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ function set_process_title(title::AbstractString)
Base.uv_error("set_process_title", err)
end

"""
Sys.maxrss()
Get the maximum resident set size utilized in bytes.
See also:
- man page of getrusage(2) on Linux and FreeBSD.
- windows api `GetProcessMemoryInfo`
"""
maxrss() = ccall(:jl_maxrss, Csize_t, ())

if is_windows()
Expand Down
4 changes: 3 additions & 1 deletion src/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -776,11 +776,13 @@ JL_DLLEXPORT size_t jl_maxrss(void)
GetProcessMemoryInfo( GetCurrentProcess( ), &counter, sizeof(counter) );
return (size_t)counter.PeakWorkingSetSize;

// FIXME: `rusage` is available on OpenBSD, DragonFlyBSD and NetBSD as well.
// All of them return `ru_maxrss` in kilobytes.
#elif defined(_OS_LINUX_) || defined(_OS_DARWIN_) || defined (_OS_FREEBSD_)
struct rusage rusage;
getrusage( RUSAGE_SELF, &rusage );

#if defined(_OS_LINUX_)
#if defined(_OS_LINUX_) || defined(_OS_FREEBSD_)
return (size_t)(rusage.ru_maxrss * 1024);
#else
return (size_t)rusage.ru_maxrss;
Expand Down

0 comments on commit e22b1f4

Please sign in to comment.