Skip to content

Commit d5b0260

Browse files
committed
Copy input files to RAM before running the provers
This ensures that we don't benchmark the time it takes to load the problem from disk, and helps minimise noise in situations of high disk contention, and other noise from the filesystem cache. We are still limited by the RAM bandwidth but… what can you do. This is only effective on Unix (more precisely, on Unix systems where `/dev/shm` is actually in RAM); on Windows the default temporary directory will be used. To enable the same behavior on Windows, pass a RAM disk as `--ramdisk` argument. To disable the behavior on Linux, you can pass a directory that is not in RAM to the `--ramdisk` argument. The files will still be copied.
1 parent 1fbb17e commit d5b0260

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/core/Misc.ml

+38
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,44 @@ let with_ram_file prefix suffix f =
511511
try Sys.remove fname with Sys_error _ -> ())
512512
(fun () -> f fname)
513513

514+
let with_copy_to_ram fname f =
515+
if has_ramdisk () then (
516+
let suffix = Filename.basename fname in
517+
let fname =
518+
CCIO.with_in ~flags:[ Open_binary ] fname @@ fun ic ->
519+
let fname, oc = open_ram_file "" suffix in
520+
Fun.protect
521+
~finally:(fun () -> close_out oc)
522+
(fun () ->
523+
CCIO.with_out ~flags:[ Open_binary ] fname @@ fun oc ->
524+
CCIO.copy_into ~bufsize:(64 * 1024) ic oc;
525+
fname)
526+
in
527+
Fun.protect
528+
~finally:(fun () -> try Sys.remove fname with Sys_error _ -> ())
529+
(fun () -> f fname)
530+
) else
531+
f fname
532+
533+
let with_copy_from_ram fname f =
534+
if has_ramdisk () then (
535+
let suffix = Filename.basename fname in
536+
let ram_fname, oc = open_ram_file "" suffix in
537+
Fun.protect
538+
~finally:(fun () ->
539+
( CCIO.with_in ~flags:[ Open_binary ] ram_fname @@ fun ic ->
540+
CCIO.copy_into ~bufsize:(64 * 1024) ic oc );
541+
close_out oc;
542+
Sys.remove ram_fname)
543+
(fun () -> f ram_fname)
544+
) else
545+
f fname
546+
547+
let with_copy_from_ram_opt fname f =
548+
match fname with
549+
| Some fname -> with_copy_from_ram fname (fun fname -> f (Some fname))
550+
| None -> f None
551+
514552
let with_affinity cpu f =
515553
let aff = Processor.Affinity.get_ids () in
516554
Processor.Affinity.set_ids [ cpu ];

src/core/Prover.ml

+2
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ module Set = CCSet.Make (As_key)
199199
200200
let run ?env ?proof_file ~limits ~file (self : t) : Run_proc_result.t =
201201
Log.debug (fun k -> k "(@[Prover.run %s %a@])" self.name Limit.All.pp limits);
202+
Misc.with_copy_to_ram file @@ fun file ->
203+
Misc.with_copy_from_ram_opt proof_file @@ fun proof_file ->
202204
let cmd = make_command ?env ?proof_file ~limits self ~file in
203205
(* Give one more second to the ulimit timeout to account for the startup
204206
time and the time elasped between starting ulimit and starting the prover *)

0 commit comments

Comments
 (0)