From 9a32c3b2273161ef4aa166e246a07e73cfa083d3 Mon Sep 17 00:00:00 2001 From: Matthew Leach Date: Tue, 13 Oct 2026 11:11:48 +0100 Subject: [PATCH] libkernel: memory: heap: fix stress test The current stress test uses a fixed size & alignment, not very stressful. Change it to be a dynamic size with occasional huge allocations as per the comment. Also randomise the alignment. --- libkernel/src/memory/allocators/slab/heap.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libkernel/src/memory/allocators/slab/heap.rs b/libkernel/src/memory/allocators/slab/heap.rs index 62452380..6653154e 100644 --- a/libkernel/src/memory/allocators/slab/heap.rs +++ b/libkernel/src/memory/allocators/slab/heap.rs @@ -302,16 +302,21 @@ mod tests { let mut allocations: Vec<(*mut u8, core::alloc::Layout, u8)> = Vec::new(); for _ in 0..ops_per_thread { - // Randomly decide to Alloc (70%) or Free (30%) + // Randomly decide to Alloc (60%) or Free (40%) // Bias towards Alloc to build up memory pressure if rng.random_bool(0.6) || allocations.is_empty() { // Allocation path // Random size: biased to small (slab), occasional huge - let size = 1024; + let size = if rng.random_bool(0.01) { + // huge alloc. + rng.random_range(4096..=16536) + } else { + rng.random_range(1..=1024) + }; // Random alignment (power of 2) - let align = 1024; + let align = 1 << rng.random_range(1..=8_usize); let layout = core::alloc::Layout::from_size_align(size, align).unwrap(); unsafe {