A cross-platform OCaml module for reporting memory usage, with a focus on distinguishing private memory (allocated by the process itself) from shared memory (e.g., shared libraries, memory-mapped files).
The module reports both system-wide and per-process memory statistics:
Field | Description |
|---|---|
| Total RAM installed on the system |
| Total virtual memory (RAM + swap) |
| RAM currently in use system-wide |
| Virtual memory in use system-wide |
| Virtual address space of the process |
| Resident set size (RSS) - pages in RAM |
| Private pages unique to this process (USS) |
| Process pages swapped to disk |
The key metric is process_private_memory which represents memory that would be freed if this process terminates, excluding shared libraries and other shared mappings.
let () =
let info = Mem_usage.info () in
Printf.printf "Process private memory: %s\n"
(Mem_usage.prettify_bytes ~binary:true info.process_private_memory)Output:
Process private memory: 1.25 MiBopam install mem_usageTo install from source:
git clone https://github.com/savonet/ocaml-mem_usage.git
cd ocaml-mem_usage
opam install .MIT