mirror of
https://github.com/stakwork/sphinx-key.git
synced 2026-02-08 01:05:09 +01:00
memory: track biggest free block instead of total RAM
This accounts for memory fragmentation Tested on multiple runs - restarts all good.
This commit is contained in:
@@ -225,9 +225,10 @@ pub fn make_event_loop(
|
||||
fn restart_esp_if_memory_low() {
|
||||
unsafe {
|
||||
let size = esp_idf_sys::heap_caps_get_free_size(4);
|
||||
let threshold = 65000;
|
||||
log::info!("Available DRAM: {}, Restart Threshold: {}", size, threshold);
|
||||
if size < threshold {
|
||||
let block = esp_idf_sys::heap_caps_get_largest_free_block(4);
|
||||
let threshold = 35000;
|
||||
log::info!("Available DRAM: {}, Max block: {}, Restart Threshold: {}", size, block, threshold);
|
||||
if block < threshold {
|
||||
log::info!("Restarting esp!");
|
||||
esp_idf_sys::esp_restart();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user