mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-11 22:22:25 +00:00
Undo: tests for the default history budget with no memory reading, 0, small and large memory
history_budget_for takes the memory reading itself, so the 1 GiB fallback for no reading or 0 is tested with the quarter, the 64 MiB floor and a reading of 2 GiB, as a cgroup limit lower than the installed memory gives. The budget is unchanged.
This commit is contained in:
@@ -154,11 +154,12 @@ pub fn default_history_budget() -> usize {
|
||||
return 256 << 20;
|
||||
}
|
||||
static BUDGET: std::sync::OnceLock<usize> = std::sync::OnceLock::new();
|
||||
*BUDGET.get_or_init(|| vectorcraft_render::physical_memory().filter(|&m| m > 0).map_or(1 << 30, history_budget_for))
|
||||
*BUDGET.get_or_init(|| history_budget_for(vectorcraft_render::physical_memory()))
|
||||
}
|
||||
|
||||
/// The default [`History::byte_budget`] on a machine with `memory` bytes installed: a quarter of it,
|
||||
/// at least 64 MiB, and at most a quarter of the address space (on 32-bit builds).
|
||||
pub(crate) fn history_budget_for(memory: u64) -> usize {
|
||||
usize::try_from(memory / 4).unwrap_or(usize::MAX).clamp(64 << 20, usize::MAX / 4)
|
||||
/// The default [`History::byte_budget`] for a reading of `memory` bytes installed: a quarter of it,
|
||||
/// at least 64 MiB, and at most a quarter of the address space (on 32-bit builds); 1 GiB when the
|
||||
/// reading is `None` or 0.
|
||||
pub(crate) fn history_budget_for(memory: Option<u64>) -> usize {
|
||||
memory.filter(|&m| m > 0).map_or(1 << 30, |m| usize::try_from(m / 4).unwrap_or(usize::MAX).clamp(64 << 20, usize::MAX / 4))
|
||||
}
|
||||
|
||||
@@ -78,18 +78,24 @@ fn within_the_budget_the_step_limit_still_counts() {
|
||||
#[test]
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
fn the_default_budget_is_a_quarter_of_installed_memory() {
|
||||
assert_eq!(history_budget_for(16 << 30), 4 << 30);
|
||||
assert_eq!(history_budget_for(64 << 30), 16 << 30, "no fixed ceiling");
|
||||
assert_eq!(history_budget_for(2 << 30), 512 << 20);
|
||||
assert_eq!(history_budget_for(128 << 20), 64 << 20, "at least 64 MiB");
|
||||
assert_eq!(history_budget_for(Some(16 << 30)), 4 << 30);
|
||||
assert_eq!(history_budget_for(Some(64 << 30)), 16 << 30, "no fixed ceiling");
|
||||
// On Linux `physical_memory` returns a cgroup memory limit lower than the installed memory in
|
||||
// its place (the `cgroup_limit_*` tests in vectorcraft-render), so a 2 GiB limit on a 64 GiB
|
||||
// machine gives the budget of 2 GiB installed.
|
||||
assert_eq!(history_budget_for(Some(2 << 30)), 512 << 20, "2 GiB, or a 2 GiB cgroup limit");
|
||||
assert_eq!(history_budget_for(Some(128 << 20)), 64 << 20, "at least 64 MiB");
|
||||
assert_eq!(history_budget_for(Some(1)), 64 << 20, "at least 64 MiB");
|
||||
assert_eq!(history_budget_for(Some(0)), 1 << 30, "a reading of 0 is the 1 GiB fallback");
|
||||
assert_eq!(history_budget_for(None), 1 << 30, "no reading is the 1 GiB fallback");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(target_os = "linux", windows, target_os = "macos", target_os = "freebsd"))]
|
||||
fn the_default_budget_follows_the_installed_memory_read() {
|
||||
// Where the memory can't be read (a sandbox that hides it), the budget is the 1 GiB fallback.
|
||||
let memory = vectorcraft_render::physical_memory().filter(|&m| m > 0);
|
||||
assert_eq!(default_history_budget(), memory.map_or(1 << 30, history_budget_for), "{memory:?}");
|
||||
let memory = vectorcraft_render::physical_memory();
|
||||
assert_eq!(default_history_budget(), history_budget_for(memory), "{memory:?}");
|
||||
assert_eq!(History::default().byte_budget, default_history_budget());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user