-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmemory.mli
More file actions
248 lines (200 loc) · 8.49 KB
/
memory.mli
File metadata and controls
248 lines (200 loc) · 8.49 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
(**
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the "hack" directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*)
(*****************************************************************************)
(* The heap shared across all the processes.
*
* The Heap is not exposed directly to the user (cf shared.mli),
* because we don't want to mix values of different types. Instead, we want
* to use a functor.
*)
(*****************************************************************************)
type config = {
global_size : int;
heap_size : int;
dep_table_pow : int;
hash_table_pow : int;
shm_dirs : string list;
shm_min_avail : int;
log_level : int;
}
type handle = Hack_parallel_intf.Std.SharedMem.handle
exception Out_of_shared_memory
exception Hash_table_full
exception Dep_table_full
exception Heap_full
exception Sql_assertion_failure of int
exception C_assertion_failure of string
val get_heap_handle: unit -> handle
(*****************************************************************************)
(* Initializes the shared memory. Must be called before forking! *)
(*****************************************************************************)
val init: config -> handle
(*****************************************************************************)
(* Connect a slave to the shared heap *)
(*****************************************************************************)
val connect: handle -> unit
(*****************************************************************************)
(* The shared memory garbage collector. It must be called every time we
* free data (cf hh_shared.c for the underlying C implementation).
*)
(*****************************************************************************)
val collect: [ `gentle | `aggressive | `always_TEST ] -> unit
(*****************************************************************************)
(* Must be called after the initialization of the hack server is over.
* (cf serverInit.ml).
*)
(*****************************************************************************)
val init_done: unit -> unit
(*****************************************************************************)
(* Serializes the dependency table and writes it to a file *)
(*****************************************************************************)
val save_dep_table_sqlite: string -> string -> int
(*****************************************************************************)
(* Loads the dependency table by reading from a file *)
(*****************************************************************************)
val load_dep_table_sqlite: string -> bool -> int
(*****************************************************************************)
(* Serializes & loads the hash table directly into memory *)
(*****************************************************************************)
val save_table: string -> unit
val load_table: string -> unit
(*****************************************************************************)
(* Serializes the hash table to sqlite *)
(*****************************************************************************)
val save_table_sqlite: string -> int
val save_table_keys_sqlite: string -> string array -> int
(*****************************************************************************)
(* Loads the hash table by reading from a file *)
(*****************************************************************************)
val load_table_sqlite: string -> bool -> int
(*****************************************************************************)
(* Cleans up the artifacts generated by SQL *)
(*****************************************************************************)
val cleanup_sqlite: unit -> unit
(*****************************************************************************)
(* The size of the dynamically allocated shared memory section *)
(*****************************************************************************)
val heap_size : unit -> int
(*****************************************************************************)
(* Part of the heap not reachable from hashtable entries. *)
(*****************************************************************************)
val wasted_heap_size: unit -> int
(*****************************************************************************)
(* Stats of the statically sized hash / dep tables *)
(*****************************************************************************)
type table_stats = {
nonempty_slots : int;
used_slots : int;
slots : int;
}
val dep_stats : unit -> table_stats
val hash_stats : unit -> table_stats
val is_heap_overflow: unit -> bool
(*****************************************************************************)
(* Cache invalidation. *)
(*****************************************************************************)
val invalidate_caches: unit -> unit
(* Size of value in GC heap *)
val value_size: Obj.t -> int
(*****************************************************************************)
(* The signature of a shared memory hashtable.
* To create one: SharedMem.NoCache(struct type = my_type_of_value end).
* The call to Make will create a hashtable in shared memory (visible to
* all the workers).
* Use NoCache/WithCache if you want caching or not.
* If you do, bear in mind that the cache must be maintained by the caller.
* So you will have to invalidate the caches yourself.
*)
(*****************************************************************************)
module type NoCache = sig
type key
type t
module KeySet : Set.S with type elt = key
module KeyMap : MyMap.S with type key = key
(* Safe for concurrent writes, the first writer wins, the second write
* is dismissed.
*)
val add : key -> t -> unit
(* Safe for concurrent reads. Safe for interleaved reads and mutations,
* provided the code runs on Intel architectures.
*)
val get : key -> t option
val get_old : key -> t option
val get_old_batch : KeySet.t -> t option KeyMap.t
val remove_old_batch : KeySet.t -> unit
val find_unsafe : key -> t
val get_batch : KeySet.t -> t option KeyMap.t
val remove_batch : KeySet.t -> unit
val string_of_key : key -> string
(* Safe for concurrent access. *)
val mem : key -> bool
val mem_old : key -> bool
(* This function takes the elements present in the set and keep the "old"
* version in a separate heap. This is useful when we want to compare
* what has changed. We will be in a situation for type-checking
* (cf typing/typing_redecl_service.ml) where we want to compare the type
* of a class in the previous environment vs the current type.
*)
val oldify_batch : KeySet.t -> unit
(* Reverse operation of oldify *)
val revive_batch : KeySet.t -> unit
module LocalChanges : sig
val has_local_changes : unit -> bool
val push_stack : unit -> unit
val pop_stack : unit -> unit
val revert_batch : KeySet.t -> unit
val commit_batch : KeySet.t -> unit
val revert_all : unit -> unit
val commit_all : unit -> unit
end
end
module type WithCache = sig
include NoCache
val write_through : key -> t -> unit
val get_no_cache: key -> t option
end
module type UserKeyType = sig
type t
val to_string : t -> string
val compare : t -> t -> int
end
module NoCache :
functor (UserKeyType : UserKeyType) ->
functor (Value:Value.Type) ->
NoCache with type t = Value.t
and type key = UserKeyType.t
and module KeySet = Set.Make (UserKeyType)
and module KeyMap = MyMap.Make (UserKeyType)
module WithCache :
functor (UserKeyType : UserKeyType) ->
functor (Value:Value.Type) ->
WithCache with type t = Value.t
and type key = UserKeyType.t
and module KeySet = Set.Make (UserKeyType)
and module KeyMap = MyMap.Make (UserKeyType)
module type CacheType = sig
type key
type value
val add: key -> value -> unit
val get: key -> value option
val remove: key -> unit
val clear: unit -> unit
val string_of_key : key -> string
val get_size : unit -> int
end
module LocalCache :
functor (UserKeyType : UserKeyType) ->
functor (Value : Value.Type) ->
CacheType with type key = UserKeyType.t
and type value = Value.t
(* Between 0.0 and 1.0 *)
val heap_use_ratio: unit -> float
val slot_use_ratio: unit -> float
val worker_garbage_control: Gc.control