TLSF memory allocator. Less free flash, moar free ram. (#3572)

* add tlsf as submodule
* libs: tlsf
* Furi: tlsf as allocator
* Furi: heap walker
* shmal fixshesh
* f18: tlsf
* PVS: ignore tlsf
* I like to moving
* merge upcoming changes
* memmgr: alloc aligned, realloc
* Furi: distinct name for auxiliary memory pool
* Furi: put idle and timer thread to mem2
* Furi: fix smal things in allocator
* Furi: remove aligned_free. Use free instead.
* aligned_malloc -> aligned_alloc
* aligned_alloc, parameters order
* aligned_alloc: check that alignment is correct
* unit test: malloc
* unit tests: realloc and test with memory fragmentation
* unit tests: aligned_alloc
* update api
* updater: properly read large update file

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
Sergei Gavrilov
2024-05-16 01:47:21 +10:00
committed by MX
parent 6d1a5c71e6
commit 5dddb075ac
21 changed files with 628 additions and 645 deletions

View File

@@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,61.3,,
Version,+,62.0,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,,
Header,+,applications/services/cli/cli_vcp.h,,
@@ -515,9 +515,7 @@ Function,-,acosh,double,double
Function,-,acoshf,float,float
Function,-,acoshl,long double,long double
Function,-,acosl,long double,long double
Function,-,aligned_alloc,void*,"size_t, size_t"
Function,+,aligned_free,void,void*
Function,+,aligned_malloc,void*,"size_t, size_t"
Function,+,aligned_alloc,void*,"size_t, size_t"
Function,-,arc4random,__uint32_t,
Function,-,arc4random_buf,void,"void*, size_t"
Function,-,arc4random_uniform,__uint32_t,__uint32_t
@@ -1984,7 +1982,8 @@ Function,+,memchr,void*,"const void*, int, size_t"
Function,+,memcmp,int,"const void*, const void*, size_t"
Function,+,memcpy,void*,"void*, const void*, size_t"
Function,-,memmem,void*,"const void*, size_t, const void*, size_t"
Function,-,memmgr_alloc_from_pool,void*,size_t
Function,+,memmgr_aux_pool_alloc,void*,size_t
Function,+,memmgr_aux_pool_get_free,size_t,
Function,+,memmgr_get_free_heap,size_t,
Function,+,memmgr_get_minimum_free_heap,size_t,
Function,+,memmgr_get_total_heap,size_t,
@@ -1992,8 +1991,7 @@ Function,+,memmgr_heap_disable_thread_trace,void,FuriThreadId
Function,+,memmgr_heap_enable_thread_trace,void,FuriThreadId
Function,+,memmgr_heap_get_max_free_block,size_t,
Function,+,memmgr_heap_get_thread_memory,size_t,FuriThreadId
Function,+,memmgr_heap_printf_free_blocks,void,
Function,-,memmgr_pool_get_free,size_t,
Function,+,memmgr_heap_walk_blocks,void,"BlockWalker, void*"
Function,-,memmgr_pool_get_max_block,size_t,
Function,+,memmove,void*,"void*, const void*, size_t"
Function,-,mempcpy,void*,"void*, const void*, size_t"
1 entry status name type params
2 Version + 61.3 62.0
3 Header + applications/services/bt/bt_service/bt.h
4 Header + applications/services/cli/cli.h
5 Header + applications/services/cli/cli_vcp.h
515 Function - acoshf float float
516 Function - acoshl long double long double
517 Function - acosl long double long double
518 Function - + aligned_alloc void* size_t, size_t
Function + aligned_free void void*
Function + aligned_malloc void* size_t, size_t
519 Function - arc4random __uint32_t
520 Function - arc4random_buf void void*, size_t
521 Function - arc4random_uniform __uint32_t __uint32_t
1982 Function + memcmp int const void*, const void*, size_t
1983 Function + memcpy void* void*, const void*, size_t
1984 Function - memmem void* const void*, size_t, const void*, size_t
1985 Function - + memmgr_alloc_from_pool memmgr_aux_pool_alloc void* size_t
1986 Function + memmgr_aux_pool_get_free size_t
1987 Function + memmgr_get_free_heap size_t
1988 Function + memmgr_get_minimum_free_heap size_t
1989 Function + memmgr_get_total_heap size_t
1991 Function + memmgr_heap_enable_thread_trace void FuriThreadId
1992 Function + memmgr_heap_get_max_free_block size_t
1993 Function + memmgr_heap_get_thread_memory size_t FuriThreadId
1994 Function + memmgr_heap_printf_free_blocks memmgr_heap_walk_blocks void BlockWalker, void*
Function - memmgr_pool_get_free size_t
1995 Function - memmgr_pool_get_max_block size_t
1996 Function + memmove void* void*, const void*, size_t
1997 Function - mempcpy void* void*, const void*, size_t

View File

@@ -13,6 +13,7 @@
"print",
"flipper18",
"furi",
"tlsf",
"freertos",
"stm32wb",
"hwdrivers",
@@ -68,4 +69,4 @@
"ibutton",
"infrared"
]
}
}

View File

@@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,61.3,,
Version,+,62.0,,
Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,,
@@ -590,9 +590,7 @@ Function,-,acosh,double,double
Function,-,acoshf,float,float
Function,-,acoshl,long double,long double
Function,-,acosl,long double,long double
Function,-,aligned_alloc,void*,"size_t, size_t"
Function,+,aligned_free,void,void*
Function,+,aligned_malloc,void*,"size_t, size_t"
Function,+,aligned_alloc,void*,"size_t, size_t"
Function,-,arc4random,__uint32_t,
Function,-,arc4random_buf,void,"void*, size_t"
Function,-,arc4random_uniform,__uint32_t,__uint32_t
@@ -2438,7 +2436,8 @@ Function,+,memchr,void*,"const void*, int, size_t"
Function,+,memcmp,int,"const void*, const void*, size_t"
Function,+,memcpy,void*,"void*, const void*, size_t"
Function,-,memmem,void*,"const void*, size_t, const void*, size_t"
Function,-,memmgr_alloc_from_pool,void*,size_t
Function,+,memmgr_aux_pool_alloc,void*,size_t
Function,+,memmgr_aux_pool_get_free,size_t,
Function,+,memmgr_get_free_heap,size_t,
Function,+,memmgr_get_minimum_free_heap,size_t,
Function,+,memmgr_get_total_heap,size_t,
@@ -2446,8 +2445,7 @@ Function,+,memmgr_heap_disable_thread_trace,void,FuriThreadId
Function,+,memmgr_heap_enable_thread_trace,void,FuriThreadId
Function,+,memmgr_heap_get_max_free_block,size_t,
Function,+,memmgr_heap_get_thread_memory,size_t,FuriThreadId
Function,+,memmgr_heap_printf_free_blocks,void,
Function,-,memmgr_pool_get_free,size_t,
Function,+,memmgr_heap_walk_blocks,void,"BlockWalker, void*"
Function,-,memmgr_pool_get_max_block,size_t,
Function,+,memmove,void*,"void*, const void*, size_t"
Function,-,mempcpy,void*,"void*, const void*, size_t"
1 entry status name type params
2 Version + 61.3 62.0
3 Header + applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h
4 Header + applications/services/bt/bt_service/bt.h
5 Header + applications/services/cli/cli.h
590 Function - acoshf float float
591 Function - acoshl long double long double
592 Function - acosl long double long double
593 Function - + aligned_alloc void* size_t, size_t
Function + aligned_free void void*
Function + aligned_malloc void* size_t, size_t
594 Function - arc4random __uint32_t
595 Function - arc4random_buf void void*, size_t
596 Function - arc4random_uniform __uint32_t __uint32_t
2436 Function + memcmp int const void*, const void*, size_t
2437 Function + memcpy void* void*, const void*, size_t
2438 Function - memmem void* const void*, size_t, const void*, size_t
2439 Function - + memmgr_alloc_from_pool memmgr_aux_pool_alloc void* size_t
2440 Function + memmgr_aux_pool_get_free size_t
2441 Function + memmgr_get_free_heap size_t
2442 Function + memmgr_get_minimum_free_heap size_t
2443 Function + memmgr_get_total_heap size_t
2445 Function + memmgr_heap_enable_thread_trace void FuriThreadId
2446 Function + memmgr_heap_get_max_free_block size_t
2447 Function + memmgr_heap_get_thread_memory size_t FuriThreadId
2448 Function + memmgr_heap_printf_free_blocks memmgr_heap_walk_blocks void BlockWalker, void*
Function - memmgr_pool_get_free size_t
2449 Function - memmgr_pool_get_max_block size_t
2450 Function + memmove void* void*, const void*, size_t
2451 Function - mempcpy void* void*, const void*, size_t

View File

@@ -19,7 +19,7 @@ static SectorCache* cache = NULL;
void sector_cache_init(void) {
if(cache == NULL) {
cache = memmgr_alloc_from_pool(sizeof(SectorCache));
cache = memmgr_aux_pool_alloc(sizeof(SectorCache));
}
if(cache != NULL) {

View File

@@ -78,21 +78,21 @@ static bool flipper_update_load_stage(const FuriString* work_dir, UpdateManifest
furi_string_free(loader_img_path);
void* img = malloc(stat.fsize);
uint32_t bytes_read = 0;
uint32_t read_total = 0;
uint16_t read_current = 0;
const uint16_t MAX_READ = 0xFFFF;
uint32_t crc = 0;
do {
uint16_t size_read = 0;
if(f_read(&file, img + bytes_read, MAX_READ, &size_read) != FR_OK) { //-V769
if(f_read(&file, img + read_total, MAX_READ, &read_current) != FR_OK) { //-V769
break;
}
crc = crc32_calc_buffer(crc, img + bytes_read, size_read);
bytes_read += size_read;
} while(bytes_read == MAX_READ);
crc = crc32_calc_buffer(crc, img + read_total, read_current);
read_total += read_current;
} while(read_current == MAX_READ);
do {
if((bytes_read != stat.fsize) || (crc != manifest->staged_loader_crc)) {
if((read_total != stat.fsize) || (crc != manifest->staged_loader_crc)) {
break;
}

View File

@@ -22,6 +22,7 @@
"print",
"flipper7",
"furi",
"tlsf",
"freertos",
"stm32wb",
"hwdrivers",
@@ -55,4 +56,4 @@
"bit_lib",
"datetime"
]
}
}