Memory consumption of bluetooth is enormous
Re: Memory consumption of bluetooth is enormous
do you have any comments on what 'lowest possible values' might mean? or thoughts on a process to determine?
Last edited by rwel59 on Fri Jan 19, 2018 1:53 am, edited 1 time in total.
Re: Memory consumption of bluetooth is enormous
any thoughts on what 'lowest possible values' might mean or how one might go about determining them?
Re: Memory consumption of bluetooth is enormous
Regarding this item:rwel59 wrote:any thoughts on what 'lowest possible values' might mean or how one might go about determining them?
Each of these numeric config parameters has a min/max value. In menuconfig, you can press "?" when any item is highlighted to view the help (which includes a description and the min/max range). Press Esc to exit the help. You can also read through the options here:chegewara wrote:If you are using wifi then in menuconfig->wifi start with the lowest settings, it gives another 30-ish kB (by default settings are setup very high)
http://esp-idf.readthedocs.io/en/v3.0-r ... html#wi-fi
Setting the minimum for each value will reduce the memory usage (although for some items it's the worst-case memory usage not the initial memory usage). The documentation for each item will help you decide what is worth tweaking.
Note that setting minimum values will impact WiFi throughput depending on circumstances (again, the help gives some description as to each item). The defaults are chosen to be a tradeoff between performance and memory usage.
If you don't use SSL/TLS then you don't need to worry about this parameter at all, as it's only used if you create a TLS session.chegewara wrote:- if you dont use SSL menuconfig->mbedTLS->TLS maximum message content length is set to 16kB, why? set it to lowest possible, another 15kB
The max message content length defaults to 16kB because TLS specifies a maximum 16kB message size. This is actually 32kB of RAM per TLS connection, as there are two buffers per connection - RX and TX.
If both ESP-IDF and the other end of your TLS connection is configured to support the TLS Maximum Fragment Length Negotiation Extension, then you can safely set this to a smaller value with no risk of problems (except maybe slower throughput if you move a lot of bulk data). However, most common cloud providers don't enable this extension on their TLS gateways.
Even if you can't use maximum fragment length negotiation, you can set the maximum message content length smaller if you know for certain that the other end of the connection will never try to send more than this many bytes at a single time. However if the other end does happen to send a TLS message which doesn't fit in the available RX buffer, the TLS connection will fail and need to be re-established.
In this case, the minimum size is usually determined by the usage in the TLS handshake phase. This depends on which TLS cipher is negotiated for the connection, which in turn depends on the mbedTLS configuration and the other end's TLS configuration. I suggest determining this experimentally, maybe start with 4096 bytes and increase/decrease. Remember to leave some headroom if there's a chance you'll need to switch ciphers in the future.
This is also summarised in the help for the config item: http://esp-idf.readthedocs.io/en/v3.0-r ... ontent-len
Re: Memory consumption of bluetooth is enormous
Great tip! Run-time allocation is a life saver! This seems to be freeing ~70kB of heap.ESP_Angus wrote:It is possible to release some of the RAM used by the Bluetooth stack if running with BLE only.
In IDF v2.1, this is done by setting "Release DRAM from Classic BT controller" under Component Config -> Bluetooth -> Bluedroid Bluetooth Stack.
In current master & IDF v3.0, this is done via esp_bt_controller_mem_release() function call: https://esp-idf.readthedocs.io/en/lates ... _bt_mode_t
Re: Memory consumption of bluetooth is enormous
Holy Moly! Glad I saw this. I was struggling with 55K of internal mem. Now I have 140K!!!
John A
John A
-
- Posts: 54
- Joined: Wed Aug 15, 2018 8:56 am
Re: Memory consumption of bluetooth is enormous
Hi,
Thank for your advice. I'm a newbie of using BT of ESP32
I'm using BluetoothSerial, I don't know what the BT mode is, BLE or Classic?
I can only find in the library.
So can I release some memory for BluetoothSerial by using
or ?
Thank for your advice. I'm a newbie of using BT of ESP32
I'm using BluetoothSerial, I don't know what the BT mode is, BLE or Classic?
I can only find
Code: Select all
esp_spp_init(ESP_SPP_MODE_CB)
So can I release some memory for BluetoothSerial by using
Code: Select all
esp_bt_mem_release(mode)
Code: Select all
esp_bt_controller_mem_release
Re: Memory consumption of bluetooth is enormous
Very informative, much appreciated. Thanks a lot!ESP_Angus wrote: ↑Fri Jan 19, 2018 2:52 amThe max message content length defaults to 16kB because TLS specifies a maximum 16kB message size. This is actually 32kB of RAM per TLS connection, as there are two buffers per connection - RX and TX.
If both ESP-IDF and the other end of your TLS connection is configured to support the TLS Maximum Fragment Length Negotiation Extension, then you can safely set this to a smaller value with no risk of problems (except maybe slower throughput if you move a lot of bulk data). However, most common cloud providers don't enable this extension on their TLS gateways.
Even if you can't use maximum fragment length negotiation, you can set the maximum message content length smaller if you know for certain that the other end of the connection will never try to send more than this many bytes at a single time. However if the other end does happen to send a TLS message which doesn't fit in the available RX buffer, the TLS connection will fail and need to be re-established.
-
- Posts: 1
- Joined: Thu Jun 17, 2021 4:37 am
Re: Memory consumption of bluetooth is enormous
Hi All,
We are developing an application using esp-mdf. In application we need BT only during provisioning, once it is done, we don't need BT and we would like to free up all the memory used by BT as we are running out of heap memory.
It seems BT is allocated 56K memory during compile time.
file=esp-idf/components/bt/bt.c
Calling the following API does free up the dram regions but one chunk of memory (30k) is never freed.
esp_bt_mem_release(ESP_BT_MODE_BTDM);
Specifically, the following chunk is not freed.
And the reason is if condition at Line#1038:
For " ESP_BT_MODE_CLASSIC_BT ", the above piece of code, hits "//skip the share mode, idle mode and another mode".
Is there a way to free up that 30k chunk?
0x3ffb2730 - 0x3ffb6388 (???) = 3c58
As per the documentation, we should get about 70k memory but we are not able to get it. Are we missing anything here? Is there a way to get all the BT memory?
BR.
We are developing an application using esp-mdf. In application we need BT only during provisioning, once it is done, we don't need BT and we would like to free up all the memory used by BT as we are running out of heap memory.
It seems BT is allocated 56K memory during compile time.
file=esp-idf/components/bt/bt.c
Code: Select all
343 /* the mode column will be modified by release function to indicate the available region */
344 static btdm_dram_available_region_t btdm_dram_available_region[] = {
345 //following is .data
346 {ESP_BT_MODE_BTDM, SOC_MEM_BT_DATA_START, SOC_MEM_BT_DATA_END },
347 //following is memory which HW will use
348 {ESP_BT_MODE_BTDM, SOC_MEM_BT_EM_BTDM0_START, SOC_MEM_BT_EM_BTDM0_END },
349 {ESP_BT_MODE_BLE, SOC_MEM_BT_EM_BLE_START, SOC_MEM_BT_EM_BLE_END },
350 {ESP_BT_MODE_BTDM, SOC_MEM_BT_EM_BTDM1_START, SOC_MEM_BT_EM_BTDM1_END },
351 {ESP_BT_MODE_CLASSIC_BT, SOC_MEM_BT_EM_BREDR_START, SOC_MEM_BT_EM_BREDR_REAL_END},
352 //following is .bss
353 {ESP_BT_MODE_BTDM, SOC_MEM_BT_BSS_START, SOC_MEM_BT_BSS_END },
354 {ESP_BT_MODE_BTDM, SOC_MEM_BT_MISC_START, SOC_MEM_BT_MISC_END },
355 };
esp_bt_mem_release(ESP_BT_MODE_BTDM);
Specifically, the following chunk is not freed.
Code: Select all
351 {ESP_BT_MODE_CLASSIC_BT, SOC_MEM_BT_EM_BREDR_START, SOC_MEM_BT_EM_BREDR_REAL_END},
And the reason is if condition at Line#1038:
- 1022 esp_err_t esp_bt_controller_mem_release(esp_bt_mode_t mode)
- 1023 {
- 1024 bool update = true;
- 1025 intptr_t mem_start=(intptr_t) NULL, mem_end=(intptr_t) NULL;
- 1026
- 1027 if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_IDLE) {
- 1028 return ESP_ERR_INVALID_STATE;
- 1029 }
- 1030
- 1031 //already released
- 1032 if (!(mode & btdm_dram_available_region[0].mode)) {
- 1033 return ESP_ERR_INVALID_STATE;
- 1034 }
- 1035
- 1036 for (int i = 0; i < sizeof(btdm_dram_available_region)/sizeof(btdm_dram_available_region_t); i++) {
- 1037 //skip the share mode, idle mode and other mode
- 1038 if (btdm_dram_available_region[i].mode == ESP_BT_MODE_IDLE
- 1039 || (mode & btdm_dram_available_region[i].mode) != btdm_dram_available_region[i].mode) {
- 1040 //clear the bit of the mode which will be released
- 1041 btdm_dram_available_region[i].mode &= ~mode;
- 1042 continue;
- 1043 } else {
- 1044 //clear the bit of the mode which will be released
- 1045 btdm_dram_available_region[i].mode &= ~mode;
- 1046 }
Is there a way to free up that 30k chunk?
0x3ffb2730 - 0x3ffb6388 (???) = 3c58
As per the documentation, we should get about 70k memory but we are not able to get it. Are we missing anything here? Is there a way to get all the BT memory?
BR.
-
- Posts: 4
- Joined: Tue Jun 22, 2021 3:33 am
Re: Memory consumption of bluetooth is enormous
Classic Bluetooth controller memory can be freed, but this means you can't use classic Bluetooth mode.
-
- Posts: 4
- Joined: Tue Jun 22, 2021 3:33 am
Re: Memory consumption of bluetooth is enormous
Classic Bluetooth controller memory can be freed, but this means you can't use classic Bluetooth mode.
- Attachments
-
- 屏幕截图 2021-06-22 114320.png (140.51 KiB) Viewed 8507 times
Who is online
Users browsing this forum: No registered users and 142 guests