Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run garbage collection once when the main process is waiting for #5396

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ users)
## Shell

## Internal
* Run `Gc.compact` in OpamParallel, when the main process is waiting for the children processes for the first time [#5396 @kkeundotnet]
kit-ty-kate marked this conversation as resolved.
Show resolved Hide resolved

## Internal: Windows

Expand Down Expand Up @@ -127,3 +128,4 @@ users)
## opam-format

## opam-core
* `OpamParallel.*.{map,reduce,iter}`: Run `Gc.compact` when the main process is waiting for the children processes for the first time [#5396 @kkeundotnet]
20 changes: 18 additions & 2 deletions src/core/opamParallel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ module type SIG = sig
exception Cyclic of G.V.t list list
end

let gc_compact () =
let get_heap () =
let {Gc.heap_words; _} = Gc.quick_stat () in
heap_words * Sys.word_size / 8 / 1024 / 1024
in
let before = get_heap () in
Gc.compact ();
let after = get_heap () in
log "GC compact (heap %d MB -> %d MB)" before after

module Make (G : G) = struct

module G = G
Expand Down Expand Up @@ -92,6 +102,8 @@ module Make (G : G) = struct
default :: defined
in

let gc_compacted = ref false in

if G.has_cycle g then (
let sccs = G.scc_list g in
let sccs = List.filter (function _::_::_ -> true | _ -> false) sccs in
Expand Down Expand Up @@ -264,8 +276,12 @@ module Make (G : G) = struct
(get_slots nslots n)
in
run_seq_command nslots ready n cmd
else
else (
(* Wait for a process to end *)
if not !gc_compacted then (
gc_compact ();
gc_compacted := true
);
let processes =
M.fold (fun n (p,x,_) acc -> (p,(n,x)) :: acc) running []
in
Expand All @@ -285,7 +301,7 @@ module Make (G : G) = struct
OpamProcess.cleanup result;
fail n e in
OpamProcess.cleanup result;
run_seq_command nslots ready n next
run_seq_command nslots ready n next )
in
let roots =
G.fold_vertex
Expand Down
Loading