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

[v5.1] [Heap Trace Standalone] support external memory for hash map (IDFGH-9845) #11172

Closed
chipweinberger opened this issue Apr 10, 2023 · 9 comments
Assignees
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally Type: Feature Request Feature request for IDF

Comments

@chipweinberger
Copy link
Contributor

chipweinberger commented Apr 10, 2023

@SoucheSouche

Thanks for all your work on #10793.

I noticed that the hash map no longer supports external memory. I wont be able to use the hash map in my project without it as I don't have very much spare internal RAM. =(

Can you please add support for external ram?

    config HEAP_TRACE_HASH_MAP
        bool "Use hash map mechanism to access heap trace records"
        depends on HEAP_TRACING_STANDALONE
        default n
        help
            ....
            External ram can be used for this map if both CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY 
            and HEAP_TRACE_HASH_MAP_USE_EXTRAM are enabled

    config HEAP_TRACE_HASH_MAP_USE_EXTRAM
        depends on CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY
        depends on HEAP_TRACE_HASH_MAP
        default n
static 
#if HEAP_TRACE_HASH_MAP_USE_EXTRAM
EXT_RAM_BSS_ATTR
#endif
heap_trace_hash_list_t hash_map[(size_t)CONFIG_HEAP_TRACE_HASH_MAP_SIZE];
@chipweinberger chipweinberger added the Type: Feature Request Feature request for IDF label Apr 10, 2023
@github-actions github-actions bot changed the title [v5.1] [Heap Trace Standalone] support external memory for hash map [v5.1] [Heap Trace Standalone] support external memory for hash map (IDFGH-9845) Apr 10, 2023
@espressif-bot espressif-bot added the Status: Opened Issue is new label Apr 10, 2023
@chipweinberger
Copy link
Contributor Author

chipweinberger commented Apr 11, 2023

Also, while we are at it, I would set the maximum hashmap size to 200k, not 10k.

After boot, I can have 20k live allocations, so I need ~30k hashmap.

@chipweinberger
Copy link
Contributor Author

chipweinberger commented Apr 11, 2023

Also, IMO, the map should not be allocated until you initialize heap trace standalone, perhaps with a log statement saying how much memory is being allocated.

No need to waste memory doing nothing.

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

Hi @chipweinberger, I started working on your follow up issues (this one and #11173) today. I will let you know when they are ready and reviewed.

Maybe one remark on your comment about the hashmap size. With a hashmap array of 10K entries, if you have 20K allocations, if we consider the repartition of the calculated hashes to be homogenous across the range of array entries, it means that each list in the array would have 2 elements. I can increase the maximum number of lists in the hashmap array but in your case for example, with an array of 30k entries, you will statistically only use 66% of it given the 20k of live allocations you mentioned. In addition, each used entries will have only 1 element in the list which will probably result in lower perf. With less entries and more elements in each list, your perf will be better when using the HEAP_TRACE_LEAKS.

@chipweinberger
Copy link
Contributor Author

chipweinberger commented Apr 12, 2023

With less entries and more elements in each list, your perf will be better when using the HEAP_TRACE_LEAKS.

This would be surprising to me. List traversal is slower than a single array lookup.

Still, I think 10K is too low as a maximum. Perhaps 50K at least...

@SoucheSouche
Copy link
Collaborator

I will increase the size to 100K and fix the external memory issue.

Also, another heap related feature will be merged soon and will allow you to store the entire heap component in flash thus saving quite a bit of internal memory but lowering the overall performances of the component.

@SoucheSouche
Copy link
Collaborator

@chipweinberger, the feature was reviewed and approved :) So it should be merged into master today hopefully. In the end I removed the limitation concerning the size of the hash_map.

@chipweinberger
Copy link
Contributor Author

Great! awesome.

@chipweinberger
Copy link
Contributor Author

chipweinberger commented Apr 14, 2023

Was I also able to convince you to allocate the ram at init time?

That would be ideal imo for enabling leak diagnostics at runtime (my use case).

@SoucheSouche
Copy link
Collaborator

@chipweinberger sorry but the memory will be allocated at compile time.

@espressif-bot espressif-bot added Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally Resolution: Done Issue is done internally and removed Status: In Progress Work is in progress Resolution: NA Issue resolution is unavailable labels Apr 19, 2023
espressif-bot pushed a commit that referenced this issue Apr 25, 2023
… RAM bss section when possible

- Remove the size limit for the hash_map array from the CONFIG_HEAP_TRACE_HASH_MAP_SIZE
- Add test case for heap tracing using hashmap
- Update heap_debug.rst to document the newly added configurations in the heap component

Closes #11172
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally Type: Feature Request Feature request for IDF
Projects
None yet
Development

No branches or pull requests

3 participants