From 865691b535e9bea7578dd047066c7fdd8db73dab Mon Sep 17 00:00:00 2001 From: Fernando Gasperi Jabalera Date: Wed, 19 Feb 2020 07:12:24 -0800 Subject: [PATCH] [scheduler][restart] Use symlinks as locks in ProcLocker Summary: Change the ProcLocker implementation to use symlinks instead of files. Tests have indicated that they may use less resources. Reviewed By: ngorogiannis Differential Revision: D19822048 fbshipit-source-id: 991ababf2 --- infer/src/backend/ProcLocker.ml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/infer/src/backend/ProcLocker.ml b/infer/src/backend/ProcLocker.ml index fa2c1efb3..b3b2ee939 100644 --- a/infer/src/backend/ProcLocker.ml +++ b/infer/src/backend/ProcLocker.ml @@ -23,7 +23,11 @@ let record_sys_time_of ~f ~log_f = let locks_dir = Config.procnames_locks_dir -let setup () = Utils.rmtree locks_dir ; Utils.create_dir locks_dir +let locks_target = locks_dir ^/ "locks_target" + +let create_file filename = Unix.openfile ~mode:[O_CREAT; O_RDONLY] filename |> Unix.close + +let setup () = Utils.rmtree locks_dir ; Utils.create_dir locks_dir ; create_file locks_target let clean () = () @@ -38,6 +42,6 @@ let unlock pname = let try_lock pname = record_sys_time_of ~log_f:log_lock_systime ~f:(fun () -> try - Unix.openfile ~mode:[O_CREAT; O_EXCL; O_RDONLY] (filename_from pname) |> Unix.close ; + Unix.symlink ~target:locks_target ~link_name:(filename_from pname) ; true with Unix.Unix_error (Unix.EEXIST, _, _) -> false )