package hack_parallel
Source file memory.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75(** Copyright (c) 2016-present, Facebook, Inc. Modified work Copyright (c) 2018-2019 Rijnard van Tonder This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree. *) include SharedMemory type bytes = int type configuration = { heap_handle: Hack_parallel_intf.Std.SharedMem.handle; minor_heap_size: bytes; } let configuration: configuration option ref = ref None let initial_heap_size = 4096 * 1024 * 1024 (* 4 GB *) let worker_garbage_control = { (Gc.get ()) with Gc.minor_heap_size = 256 * 1024; (* 256 KB *) space_overhead = 100; } let initialize () = match !configuration with | None -> let minor_heap_size = 4 * 1024 * 1024 in (* 4 MB *) let space_overhead = 50 in (* Only sets the GC for the master process - the parallel workers use GC settings with less overhead. *) Gc.set { (Gc.get ()) with Gc.minor_heap_size; space_overhead; }; let = let open SharedMemory in { global_size = initial_heap_size; heap_size = initial_heap_size; dep_table_pow = 19; hash_table_pow = 21; shm_dirs = ["/dev/shm"; "/ocaml_parallel"]; shm_min_avail = 1024 * 1024 * 512; (* 512 MB *) log_level = 0; } in let heap_handle = SharedMemory.init shared_mem_config in configuration := Some { heap_handle; minor_heap_size }; { heap_handle; minor_heap_size } | Some configuration -> configuration let get_heap_handle () = let { heap_handle; _ } = initialize () in heap_handle let heap_use_ratio () = Core_kernel.Float.of_int (SharedMemory.heap_size ()) /. Core_kernel.Float.of_int initial_heap_size let slot_use_ratio () = let { SharedMemory.used_slots; slots; _ } = SharedMemory.hash_stats () in Core_kernel.Float.of_int used_slots /. Core_kernel.Float.of_int slots