feat(ble/nimble): support runtime allocation for mempool

This commit is contained in:
chenjianhua
2025-10-28 17:38:28 +08:00
committed by Rahul Tank
parent 07a9d40a75
commit 18b82d2959
4 changed files with 41 additions and 1 deletions

View File

@@ -485,6 +485,26 @@ menu "Memory Settings"
default 1
help
This is the service data unit buffer count for l2cap coc.
config BT_NIMBLE_MEMPOOL_RUNTIME_ALLOC
bool "Support on-demand runtime memory allocation for mempool"
depends on BT_NIMBLE_ENABLED && !SOC_ESP_NIMBLE_CONTROLLER
default n
help
When this option is enabled, mempool does not require pre-allocating memory.
Instead, memory for each block will be dynamically allocated and released
during mempool usage. This can significantly reduce memory consumption
after mempool initialization, but may have some impact on performance.
config BT_NIMBLE_MEMPOOL_BLOCK_REUSED
bool "Support block reuse for mempool runtime memory allocation"
depends on BT_NIMBLE_MEMPOOL_RUNTIME_ALLOC
default n
help
When this option is enabled, dynamically allocated blocks will not be freed
but will be reused instead. This ensures virtually no impact on performance
while reducing the memory consumption of the mempool.
endmenu #Memory
menu "BLE 5.x Features"

View File

@@ -96,7 +96,11 @@ int ble_hci_trans_hs_cmd_tx(uint8_t *cmd)
rc = BLE_HS_ETIMEOUT_HCI;
}
#if MYNEWT_VAL(MP_RUNTIME_ALLOC)
ble_transport_free(BLE_HCI_CMD, cmd);
#else
ble_transport_free(cmd);
#endif
return rc;
}

View File

@@ -2214,4 +2214,20 @@
#endif
#endif
#ifndef MYNEWT_VAL_MP_RUNTIME_ALLOC
#ifdef CONFIG_BT_NIMBLE_MEMPOOL_RUNTIME_ALLOC
#define MYNEWT_VAL_MP_RUNTIME_ALLOC (1)
#else
#define MYNEWT_VAL_MP_RUNTIME_ALLOC (0)
#endif
#endif
#ifndef MYNEWT_VAL_MP_BLOCK_REUSED
#ifdef CONFIG_BT_NIMBLE_MEMPOOL_BLOCK_REUSED
#define MYNEWT_VAL_MP_BLOCK_REUSED (1)
#else
#define MYNEWT_VAL_MP_BLOCK_REUSED (0)
#endif
#endif
#endif