Skip to content

Commit 2694f8c

Browse files
Monitor for low free memory during sysimage generation (#740)
Fixes #739
1 parent 376e3bf commit 2694f8c

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/PackageCompiler.jl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,28 @@ end
115115
# Misc utils #
116116
##############
117117

118+
macro monitor_oom(ex)
119+
quote
120+
lowest_free_mem = Sys.free_memory()
121+
mem_monitor = Timer(0, interval = 1) do t
122+
lowest_free_mem = min(lowest_free_mem, Sys.free_memory())
123+
end
124+
try
125+
$(esc(ex))
126+
catch
127+
if lowest_free_mem < 512 * 1024 * 1024 # Less than 512 MB
128+
@warn """
129+
Free system memory dropped to $(Base.format_bytes(lowest_free_mem)) during sysimage compilation.
130+
If the reason the subprocess errored isn't clear, it may have been OOM-killed.
131+
"""
132+
end
133+
rethrow()
134+
finally
135+
close(mem_monitor)
136+
end
137+
end
138+
end
139+
118140
const WARNED_CPP_COMPILER = Ref{Bool}(false)
119141

120142
function get_compiler_cmd(; cplusplus::Bool=false)
@@ -361,7 +383,7 @@ function create_sysimg_object_file(object_file::String,
361383
@debug "running $cmd"
362384
non = incremental ? "" : "non"
363385
spinner = TerminalSpinners.Spinner(msg = "PackageCompiler: compiling $(non)incremental system image")
364-
TerminalSpinners.@spin spinner run(cmd)
386+
@monitor_oom TerminalSpinners.@spin spinner run(cmd)
365387
return
366388
end
367389

0 commit comments

Comments
 (0)