tlsf: Add tracking of added tlsf memory pools
PATCH v2 1/1 tlsf: Add tracking of added tlsf memory pools
When configured to use the TLSF allocator, the malloc_stats function only walks the initial memory pool, as that is the only pool it is aware of, and TLSF doesn't link pools together in a way that the walker can follow.
Add a wrapper function around tlsf_add_pool to add additional tracking of added pools, so that they can be walked by the malloc_stats function and meminfo can report accurate heap utilization.
---
Changes in v2:
- Removed malloc_remove_pool (Sasha)
- Reworked tlsf initialization into malloc_add_pool
--- common/memory.c | 7 +------ common/tlsf_malloc.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- include/malloc.h | 4 ++++ 3 files changed, 49 insertions(+), 8 deletions(-)
common/memory.c +1 -6
@@ -34,11 +34,6 @@ unsigned long mem_malloc_end(void)return malloc_end; } -#ifdef CONFIG_MALLOC_TLSF -#include <tlsf.h> -tlsf_t tlsf_mem_pool; -#endif -int mem_malloc_initialized;int mem_malloc_is_initialized (void )
@@ -52,7 +47,7 @@ void mem_malloc_init(void *start, void *end) malloc_end = (unsigned long )end; malloc_brk = malloc_start;#ifdef CONFIG_MALLOC_TLSF - tlsf_mem_pool =tlsf_create_with_pool (start, end - start +1 ); +malloc_add_pool (start, end - start +1 );#endif mem_malloc_initialized =1 ; }
common/tlsf_malloc.c +44 -2
63 lines not on this page · raw message
include/malloc.h +4 -0
@@ -21,6 +21,10 @@#define ZERO_OR_NULL_PTR (x) ((unsigned long)(x) <= \ (unsigned long)ZERO_SIZE_PTR) +#ifdef CONFIG_MALLOC_TLSF +void *malloc_add_pool (void *mem,size_t bytes); +#endif +#if IN_PROPER void *malloc (size_t )__alloc_size(1) ;size_t malloc_usable_size (void *);
---
base-commit: b4c0c4615ace1795aa75ced21caa1e78b665cde0
change-id: 20250131-tlsf-addpool-5f42029b582c
Best regards,
Signature · 1 line
David Dgien <[email protected]>
Sascha Hauer
AppliedQuoted 10 lines · On Sun, 06 Apr 2025 22:24:40 -0400, David Dgien via B4 Relay wrote:
When configured to use the TLSF allocator, the
malloc_statsfunction only walks the initial memory pool, as that is the only pool it is aware of, and TLSF doesn't link pools together in a way that the walker can follow.Add a wrapper function around
tlsf_add_poolto add additional tracking of added pools, so that they can be walked by themalloc_statsfunction and meminfo can report accurate heap utilization.[...]
Applied, thanks!
[1/1] tlsf: Add tracking of added tlsf memory pools
https://git.pengutronix.de/cgit/barebox/commit/?id=a17c188826cf (link may not be stable)
Best regards,
Signature · 1 line
Sascha Hauer <[email protected]>