Skip to main content

kevy_embedded/
config_tier_builders.rs

1//! The transparent-tiering knobs of [`Config`] (child module via
2//! `#[path]`, split from `config.rs` for the 500-LOC house rule;
3//! behaviour unchanged).
4
5#[cfg(feature = "tier")]
6use super::TierBudgetSpec;
7use super::Config;
8
9impl Config {
10    /// Enable transparent tiering with a RAM budget of `bytes`: values
11    /// past the demote watermark spill to the cold tier on disk
12    /// (`<data_dir>/tier/`) and page back in on access — every command
13    /// keeps its exact semantics. Requires [`Self::with_persist`]; a
14    /// memory-only store fails at open with a named error.
15    #[cfg(feature = "tier")]
16    #[must_use]
17    pub fn with_tier_budget(mut self, bytes: u64) -> Self {
18        self.tier_budget = Some(TierBudgetSpec::Bytes(bytes));
19        self
20    }
21
22    /// Enable transparent tiering with the `auto` budget: 0.70 × the
23    /// detected memory bound (cgroup v2 limit / `MemAvailable` on
24    /// Linux, `hw.memsize` on macOS), re-probed on every reaper tick.
25    /// Open fails with a named error when no bound is detectable.
26    #[cfg(feature = "tier")]
27    #[must_use]
28    pub fn with_tier_budget_auto(mut self) -> Self {
29        self.tier_budget = Some(TierBudgetSpec::Auto);
30        self
31    }
32
33    /// Cap the largest spillable value (bytes; 0 = unlimited). Bounds
34    /// the embedded cold-read lock-hold time; default 256 KiB.
35    #[must_use]
36    pub fn with_max_spill_value(mut self, bytes: u64) -> Self {
37        self.max_spill_value = bytes;
38        self
39    }
40
41    /// Enable transparent tiering with a percent-of-detected-bound
42    /// budget (`p` in 1..=100 — validated at open with a named error,
43    /// like every other config refusal).
44    #[cfg(feature = "tier")]
45    #[must_use]
46    pub fn with_tier_budget_percent(mut self, p: u8) -> Self {
47        self.tier_budget = Some(TierBudgetSpec::Percent(p));
48        self
49    }
50}