tools/oxenstored: Replace hand rolled GC with weak GC references
authorEdwin Török <edvin.torok@citrix.com>
Fri, 8 Jan 2021 11:57:37 +0000 (11:57 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 22 Jan 2021 18:01:34 +0000 (18:01 +0000)
commit5e115dcf76f61543fb734baf4a60fc1902398113
tree8a49cab06509e792b53911a2affc8e621956e86d
parent4522321ced5ddbda5e74e20c52b0b88f96914fb5
tools/oxenstored: Replace hand rolled GC with weak GC references

The code here is attempting to reduce memory usage by sharing common
substrings in the tree: it replaces strings with ints, and keeps a string->int
map that gets manually garbage collected using a hand-rolled mark and sweep
algorithm.

This is unnecessary: OCaml already has a mark-and-sweep Garbage Collector
runtime, and sharing of common strings in tree nodes can be achieved through
Weak references: if the string hasn't been seen yet it gets added to the Weak
reference table, and if it has we use the entry from the table instead, thus
storing a string only once.  When the string is no longer referenced OCaml's
GC will drop it from the weak table: there is no need to manually do a
mark-and-sweep, or to tell OCaml when to drop it.

Signed-off-by: Edwin Török <edvin.torok@citrix.com>
Acked-by: Christian Lindig <christian.lindig@citrix.com>
tools/ocaml/xenstored/connection.ml
tools/ocaml/xenstored/history.ml
tools/ocaml/xenstored/store.ml
tools/ocaml/xenstored/symbol.ml
tools/ocaml/xenstored/symbol.mli
tools/ocaml/xenstored/xenstored.ml