trigger the GC earlier (at < 50% free space)

print memory usage every 10 minutes
This commit is contained in:
palainp 2022-09-05 10:01:15 +02:00 committed by Hannes Mehnert
parent c643f97700
commit 9b1b30aa2b
2 changed files with 19 additions and 3 deletions

View File

@ -5,5 +5,5 @@ docker build -t qubes-mirage-firewall .
echo Building Firewall...
docker run --rm -i -v `pwd`:/home/opam/qubes-mirage-firewall qubes-mirage-firewall
echo "SHA2 of build: $(sha256sum ./dist/qubes-firewall.xen)"
echo "SHA2 last known: 588e921b9d78a99f6f49d468a7b68284c50dabeba95698648ea52e99b381723b"
echo "SHA2 last known: f77d17444edf299c64f12a62b6a9e2f598d166caf1bb7582dae4cab46f1dcb6d"
echo "(hashes should match for released versions)"

View File

@ -36,19 +36,35 @@ let report_mem_usage stats =
)
)
let print_mem_usage =
let rec aux () =
let stats = Xen_os.Memory.quick_stat () in
let { Xen_os.Memory.free_words; heap_words; _ } = stats in
let mem_total = heap_words * wordsize_in_bytes in
let mem_free = free_words * wordsize_in_bytes in
Log.info (fun f -> f "Memory usage: free %a / %a (%.2f %%)"
Fmt.bi_byte_size mem_free
Fmt.bi_byte_size mem_total
(fraction_free stats *. 100.0));
Xen_os.Time.sleep_ns (Duration.of_f 600.0) >>= fun () ->
aux ()
in
aux ()
let init () =
Gc.full_major ();
let stats = Xen_os.Memory.quick_stat () in
print_mem_usage ;
report_mem_usage stats
let status () =
let stats = Xen_os.Memory.quick_stat () in
if fraction_free stats > 0.4 then `Ok
if fraction_free stats > 0.5 then `Ok
else (
Gc.full_major ();
Xen_os.Memory.trim ();
let stats = Xen_os.Memory.quick_stat () in
report_mem_usage stats;
if fraction_free stats < 0.4 then `Memory_critical
if fraction_free stats < 0.6 then `Memory_critical
else `Ok
)