{"record":{"id":"888964f52b21f1c6","repo":"embassy-rs/embassy","slug":"out-of-memory","errorCode":null,"errorMessage":"out of memory","messagePattern":"out of memory","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-net-nrf91/src/lib.rs","lineNumber":60,"sourceCode":"pub fn on_ipc_irq() {\n    trace!(\"irq\");\n\n    pac::IPC_NS.inten().write(|_| ());\n    WAKER.wake();\n}\n\nstruct Allocator<'a> {\n    start: *mut u8,\n    end: *mut u8,\n    _phantom: PhantomData<&'a mut u8>,\n}\n\nimpl<'a> Allocator<'a> {\n    fn alloc_bytes(&mut self, size: usize) -> &'a mut [MaybeUninit<u8>] {\n        // safety: both pointers come from the same allocation.\n        let available_size = unsafe { self.end.offset_from(self.start) } as usize;\n        if size > available_size {\n            panic!(\"out of memory\")\n        }\n\n        // safety: we've checked above this doesn't go out of bounds.\n        let p = self.start;\n        self.start = unsafe { p.add(size) };\n\n        // safety: we've checked the pointer is in-bounds.\n        unsafe { slice::from_raw_parts_mut(p as *mut _, size) }\n    }\n\n    fn alloc<T>(&mut self) -> &'a mut MaybeUninit<T> {\n        let align = mem::align_of::<T>();\n        let size = mem::size_of::<T>();\n\n        let align_size = match (self.start as usize) % align {\n            0 => 0,\n            n => align - n,\n        };","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-net-nrf91/src/lib.rs#L42-L78","documentation":"The nrf91 driver's internal bump Allocator panicked because alloc_bytes() was asked for a chunk larger than the remaining bytes between its start and end pointers. The driver pre-allocates a fixed memory pool for packet buffers, and a requested allocation exceeded the whole (remaining) pool. This is a build/config sizing problem: the static pool is too small for the requested buffers.","triggerScenarios":"Calling the allocator path (e.g., constructing the Tcxo/AT or packet buffers) with size > available_size, i.e. the request exceeds the entire reserved memory region — typically on first allocation with an oversized configured buffer count/size.","commonSituations":"Configuring the driver with buffer sizes/counts that exceed the RAM budget set when creating the Allocator; upgrading the driver and its default packet size growing beyond a hand-tuned pool size; low-RAM targets (nrf9160 has limited RAM) where users shrink the pool too aggressively.","solutions":["Increase the memory pool size passed when constructing the Allocator (and free up RAM elsewhere) so it can hold all configured buffers","Reduce configured buffer count or MTU in the driver config so total required bytes fit the pool","Compute the required pool size (buffers * buffer_size, plus allocator alignment) and size the static region accordingly","Check for regressions after upgrading embassy-net-nrf91; review its changelog for changed default buffer sizes"],"exampleFix":"// before\nlet mut mem = [0u8; 4096];\nlet allocator = Allocator::new(&mut mem);\n// after\nlet mut mem = [0u8; 16384]; // fits buffers requested by config\nlet allocator = Allocator::new(&mut mem);","handlingStrategy":"validation","validationCode":"fn validate_pool(mem_len: usize, buffers: usize, buffer_size: usize) {\n    let required = buffers * buffer_size;\n    assert!(mem_len >= required, \"pool {} < required {}\", mem_len, required);\n}","typeGuard":null,"tryCatchPattern":"// panic-based; validate sizes at startup instead\n// assert!(mem.len() >= expected_total, \"nrf91 memory pool too small\");","preventionTips":["Size the memory pool as buffers * buffer_size plus alignment headroom","Recheck pool sizing after every driver version upgrade (defaults may change)","Reduce buffer count/MTU when targeting low-RAM nrf9160 builds","Log allocator usage at startup to confirm headroom before entering steady state"],"tags":["embedded","memory","allocator","panic","nrf91"],"backgroundTag":"value-out-of-range","analyzedSha":"463a07b963419a1bfe61d5d597c44acb810afb8b","analyzedAt":"2026-09-10T13:38:26.660Z","contentChangedAt":"2026-09-10T13:38:26.660Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}