qubes-mirage-firewall/memory_pressure.ml

24 lines
671 B
OCaml
Raw Normal View History

2015-12-30 04:52:24 -05:00
(* Copyright (C) 2015, Thomas Leonard <thomas.leonard@unikernel.com>
See the README file for details. *)
2016-01-02 10:59:59 -05:00
let src = Logs.Src.create "memory_pressure" ~doc:"Memory pressure monitor"
module Log = (val Logs.src_log src : Logs.LOG)
let fraction_free stats =
let { Xen_os.Memory.free_words; heap_words; _ } = stats in
float free_words /. float heap_words
2016-01-02 10:59:59 -05:00
let init () =
Gc.full_major ()
2015-12-30 04:52:24 -05:00
let status () =
let stats = Xen_os.Memory.quick_stat () in
if fraction_free stats > 0.5 then `Ok
2015-12-30 04:52:24 -05:00
else (
Gc.full_major ();
Xen_os.Memory.trim ();
let stats = Xen_os.Memory.quick_stat () in
if fraction_free stats < 0.6 then `Memory_critical
else `Ok
2015-12-30 04:52:24 -05:00
)