Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32 SD Card Memory Allocation Inefficient & Crash Prone, Fix Suggested (IDFGH-4794) #6596

Closed
SWillSZ opened this issue Feb 23, 2021 · 2 comments
Assignees
Labels
Resolution: Cannot Reproduce Issue cannot be reproduced Status: Done Issue is done internally

Comments

@SWillSZ
Copy link

SWillSZ commented Feb 23, 2021

Hello,
I have found a small change to sdmmc_cmd.c which should lead to performance increases and decreased probability of crashes. If you look into sdmmc_read_sectors, you will notice the following:

tmp_buf_read = heap_caps_malloc(block_size, MALLOC_CAP_DMA);

followed by
free(tmp_buf)

This DMA memory is allocated / deallocated every single time a SD card sector is read from. For applications similar to video streaming, this can be many, many times per second. When an application is low on DMA memory, this constant allocation / deallocation will often end up triggering

if (tmp_buf == NULL) { return ESP_ERR_NO_MEM; }

In the vast majority of cases, higher level functions call sdmmc_read_sectors with a block_size of 512 bytes. Taking this into account, it is far faster to allocate 512 bytes of DMA memory one time globally, and then use it each time sdmmc_read_sectors is called (the same 512 DMA bytes can be used for sdmmc_write_sectors). After making this change in sdmmc_cmd.c, my issues vanished

@github-actions github-actions bot changed the title ESP32 SD Card Memory Allocation Inefficient & Crash Prone, Fix Suggested ESP32 SD Card Memory Allocation Inefficient & Crash Prone, Fix Suggested (IDFGH-4794) Feb 23, 2021
@espressif-bot espressif-bot added Status: Selected for Development Issue is selected for development Status: In Progress Work is in progress and removed Status: Selected for Development Issue is selected for development labels Apr 13, 2023
@adokitkat
Copy link
Collaborator

Hello, do you still have any information on how big was the improvement? I am trying to do the same (on IDF v5.0 and ESP32-WROVER-KIT) however I don't seem to get any speed up from this.

@espressif-bot espressif-bot added Status: Selected for Development Issue is selected for development and removed Status: In Progress Work is in progress labels Apr 26, 2023
@adokitkat
Copy link
Collaborator

Closing because of no improvements detected and user not responding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Cannot Reproduce Issue cannot be reproduced Status: Done Issue is done internally
Projects
None yet
Development

No branches or pull requests

3 participants