1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! Heap memory size reporting for graph data structures.
//!
//! The [`GraphMemorySize`] trait provides a uniform way to estimate heap
//! memory owned by graph components. Implementations sum
//! `Vec::capacity() * size_of::<T>()` for all heap-allocated collections,
//! plus any `Box`/`Arc`/`HashMap` overhead.
//!
//! Used by the `sqryd` daemon's admission controller and workspace
//! retention reaper to enforce memory budgets.
/// Approximate per-bucket overhead for `HashMap` entries.
///
/// Rust's `hashbrown` stores one control byte per bucket plus alignment
/// padding. 8 bytes per bucket is a conservative estimate that accounts
/// for the control byte array, growth factor headroom, and pointer-sized
/// alignment on 64-bit targets.
pub const HASHMAP_ENTRY_OVERHEAD: usize = 8;
/// Approximate per-node overhead for `BTreeMap` entries.
///
/// `BTreeMap` stores entries in B-tree nodes (typically 11 entries per
/// internal node). Each node carries child pointers and metadata. 64
/// bytes per logical entry is a rough estimate that accounts for node
/// overhead amortised across entries.
pub const BTREEMAP_ENTRY_OVERHEAD: usize = 64;
/// Trait for reporting heap memory usage of graph data structures.
///
/// Implementations should sum `Vec::capacity() * size_of::<T>()` for all
/// heap-allocated collections, plus any `Box`/`Arc` overhead. Only heap
/// bytes are counted; stack/inline bytes are excluded.
///
/// # Contract
///
/// - Returns an *estimate*, not an exact count. Allocator metadata,
/// alignment padding, and `Arc` control blocks are not included.
/// - Must be safe to call concurrently from multiple readers.
/// - Should complete in O(number of collections), not O(number of elements).