qubes-mirage-firewall/memory_pressure.ml
2015-12-30 11:07:17 +00:00

17 lines
489 B
OCaml

(* Copyright (C) 2015, Thomas Leonard <thomas.leonard@unikernel.com>
See the README file for details. *)
let total_pages = OS.MM.Heap_pages.total () |> float_of_int
let status () =
let used = OS.MM.Heap_pages.used () |> float_of_int in
let frac = used /. total_pages in
if frac < 0.9 then `Ok
else (
Gc.full_major ();
let used = OS.MM.Heap_pages.used () |> float_of_int in
let frac = used /. total_pages in
if frac > 0.9 then `Memory_critical
else `Ok
)