mirror of
https://github.com/mirage/qubes-mirage-firewall.git
synced 2024-12-29 00:56:13 -05:00
3dbb9ecb27
For me, this mostly hangs at: ``` 2020-10-26 11:16:31 -00:00: INF [qubes.rexec] waiting for client... 2020-10-26 11:16:31 -00:00: INF [qubes.gui] waiting for client... 2020-10-26 11:16:31 -00:00: INF [qubes.db] connecting to server... ``` Sometimes it gets a bit further: ``` 2020-10-26 11:14:19 -00:00: INF [qubes.rexec] waiting for client... 2020-10-26 11:14:19 -00:00: INF [qubes.gui] waiting for client... 2020-10-26 11:14:19 -00:00: INF [qubes.db] connecting to server... 2020-10-26 11:14:19 -00:00: INF [qubes.db] connected 2020-10-26 11:14:19 -00:00: INF [qubes.rexec] client connected, using protocol version 2 2020-10-26 11:14:19 -00:00: INF [qubes.gui] client connected (screen size: 3840x2160 depth: 24 mem: 32401x) 2020-10-26 11:14:19 -00:00: INF [unikernel] GUI agent connected ```
54 lines
1.5 KiB
OCaml
54 lines
1.5 KiB
OCaml
(* Copyright (C) 2015, Thomas Leonard <thomas.leonard@unikernel.com>
|
|
See the README file for details. *)
|
|
|
|
open Lwt
|
|
|
|
let src = Logs.Src.create "memory_pressure" ~doc:"Memory pressure monitor"
|
|
module Log = (val Logs.src_log src : Logs.LOG)
|
|
|
|
let wordsize_in_bytes = Sys.word_size / 8
|
|
|
|
let fraction_free stats =
|
|
let { OS.Memory.free_words; heap_words; _ } = stats in
|
|
float free_words /. float heap_words
|
|
|
|
let meminfo stats =
|
|
let { 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 "Writing meminfo: free %a / %a (%.2f %%)"
|
|
Fmt.bi_byte_size mem_free
|
|
Fmt.bi_byte_size mem_total
|
|
(fraction_free stats *. 100.0));
|
|
Printf.sprintf "MemTotal: %d kB\n\
|
|
MemFree: %d kB\n\
|
|
Buffers: 0 kB\n\
|
|
Cached: 0 kB\n\
|
|
SwapTotal: 0 kB\n\
|
|
SwapFree: 0 kB\n" (mem_total / 1024) (mem_free / 1024)
|
|
|
|
let report_mem_usage stats =
|
|
Lwt.async (fun () ->
|
|
let open OS in
|
|
Xs.make () >>= fun xs ->
|
|
Xs.immediate xs (fun h ->
|
|
Xs.write h "memory/meminfo" (meminfo stats)
|
|
)
|
|
)
|
|
|
|
let init () =
|
|
Gc.full_major ();
|
|
let stats = OS.Memory.quick_stat () in
|
|
report_mem_usage stats
|
|
|
|
let status () =
|
|
let stats = OS.Memory.quick_stat () in
|
|
if fraction_free stats > 0.1 then `Ok
|
|
else (
|
|
Gc.full_major ();
|
|
let stats = OS.Memory.quick_stat () in
|
|
report_mem_usage stats;
|
|
if fraction_free stats < 0.1 then `Memory_critical
|
|
else `Ok
|
|
)
|