diff --git a/include/nuttx/mm/mempool.h b/include/nuttx/mm/mempool.h index 2f4648035f..4391633ecd 100644 --- a/include/nuttx/mm/mempool.h +++ b/include/nuttx/mm/mempool.h @@ -90,9 +90,6 @@ struct mempool_s size_t expandsize; /* The size of expand block every time for mempool */ bool wait; /* The flag of need to wait when mempool is empty */ FAR void *priv; /* This pointer is used to store the user's private data */ - bool calibrate; /* The flag is use expend memory calibration - * real memory usage - */ mempool_alloc_t alloc; /* The alloc function for mempool */ mempool_free_t free; /* The free function for mempool */ @@ -320,7 +317,6 @@ void mempool_procfs_unregister(FAR struct mempool_procfs_entry_s *entry); * arg - The alloc & free memory fuctions used arg. * expandsize - The expend mempry for all pools in multiples pool. * dict_expendsize - The expend size for multiple dictnoary. - * calibrate - Whether to calibrate when counting memory usage. * Returned Value: * Return an initialized multiple pool pointer on success, * otherwise NULL is returned. @@ -335,7 +331,7 @@ mempool_multiple_init(FAR const char *name, mempool_multiple_alloc_t alloc, mempool_multiple_free_t free, FAR void *arg, size_t expandsize, - size_t dict_expendsize, bool calibrate); + size_t dict_expendsize); /**************************************************************************** * Name: mempool_multiple_alloc diff --git a/include/nuttx/mm/mm.h b/include/nuttx/mm/mm.h index 3ca86d1e47..8cd6d49ff0 100644 --- a/include/nuttx/mm/mm.h +++ b/include/nuttx/mm/mm.h @@ -98,8 +98,9 @@ # endif #endif -#define MM_BACKTRACE_FREE_PID ((pid_t)-2) -#define MM_BACKTRACE_ALLOC_PID ((pid_t)-1) +#define MM_BACKTRACE_MEMPOOL_PID ((pid_t)-3) +#define MM_BACKTRACE_FREE_PID ((pid_t)-2) +#define MM_BACKTRACE_ALLOC_PID ((pid_t)-1) /**************************************************************************** * Public Types diff --git a/mm/mempool/mempool.c b/mm/mempool/mempool.c index 182b3b1193..ee65d94b74 100644 --- a/mm/mempool/mempool.c +++ b/mm/mempool/mempool.c @@ -405,11 +405,6 @@ int mempool_info_task(FAR struct mempool_s *pool, info->aordblks += count; info->uordblks += count * pool->blocksize; - if (pool->calibrate) - { - info->aordblks -= pool->nexpend; - info->uordblks -= pool->totalsize; - } } else if (info->pid == MM_BACKTRACE_ALLOC_PID) { diff --git a/mm/mempool/mempool_multiple.c b/mm/mempool/mempool_multiple.c index e80cb8c2fb..d053715eee 100644 --- a/mm/mempool/mempool_multiple.c +++ b/mm/mempool/mempool_multiple.c @@ -257,7 +257,6 @@ mempool_multiple_get_dict(FAR struct mempool_multiple_s *mpool, * arg - The alloc & free memory fuctions used arg. * expandsize - The expend mempry for all pools in multiples pool. * dict_expendsize - The expend size for multiple dictnoary. - * calibrate - Whether to calibrate when counting memory usage. * Returned Value: * Return an initialized multiple pool pointer on success, * otherwise NULL is returned. @@ -270,7 +269,7 @@ mempool_multiple_init(FAR const char *name, mempool_multiple_alloc_t alloc, mempool_multiple_free_t free, FAR void *arg, size_t expandsize, - size_t dict_expendsize, bool calibrate) + size_t dict_expendsize) { FAR struct mempool_multiple_s *mpool; FAR struct mempool_s *pools; @@ -329,7 +328,6 @@ mempool_multiple_init(FAR const char *name, pools[i].priv = mpool; pools[i].alloc = mempool_multiple_alloc_callback; pools[i].free = mempool_multiple_free_callback; - pools[i].calibrate = calibrate; #if CONFIG_MM_BACKTRACE >= 0 pools[i].blockalign = mpool->minpoolsize; #endif diff --git a/mm/mm_heap/mm_initialize.c b/mm/mm_heap/mm_initialize.c index f9ee40c156..2bf2f267a8 100644 --- a/mm/mm_heap/mm_initialize.c +++ b/mm/mm_heap/mm_initialize.c @@ -41,6 +41,40 @@ # define MEMPOOL_NPOOLS (CONFIG_MM_HEAP_MEMPOOL_THRESHOLD / MM_MIN_CHUNK) #endif +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +#if CONFIG_MM_HEAP_MEMPOOL_THRESHOLD != 0 && CONFIG_MM_BACKTRACE >= 0 + +/**************************************************************************** + * Name: mempool_memalign + * + * Description: + * This function call mm_memalign and set mm_backtrace pid to free pid + * avoid repeated calculation. + ****************************************************************************/ + +static FAR void *mempool_memalign(FAR void *arg, size_t alignment, + size_t size) +{ + FAR struct mm_allocnode_s *node; + FAR void *ret; + + ret = mm_memalign(arg, alignment, size); + if (ret) + { + node = (FAR struct mm_allocnode_s *) + ((FAR char *)ret - SIZEOF_MM_ALLOCNODE); + node->pid = MM_BACKTRACE_MEMPOOL_PID; + } + + return ret; +} +#else +# define mempool_memalign mm_memalign +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -253,11 +287,10 @@ FAR struct mm_heap_s *mm_initialize(FAR const char *name, } heap->mm_mpool = mempool_multiple_init(name, poolsize, MEMPOOL_NPOOLS, - (mempool_multiple_alloc_t)mm_memalign, + (mempool_multiple_alloc_t)mempool_memalign, (mempool_multiple_free_t)mm_free, heap, CONFIG_MM_HEAP_MEMPOOL_EXPAND, - CONFIG_MM_HEAP_MEMPOOL_DICTIONARY_EXPAND, - true); + CONFIG_MM_HEAP_MEMPOOL_DICTIONARY_EXPAND); #endif return heap; diff --git a/mm/tlsf/mm_tlsf.c b/mm/tlsf/mm_tlsf.c index 25b111a163..5c924be716 100644 --- a/mm/tlsf/mm_tlsf.c +++ b/mm/tlsf/mm_tlsf.c @@ -220,6 +220,35 @@ static void free_delaylist(FAR struct mm_heap_s *heap) #endif } +#if CONFIG_MM_HEAP_MEMPOOL_THRESHOLD != 0 && CONFIG_MM_BACKTRACE >= 0 + +/**************************************************************************** + * Name: mempool_memalign + * + * Description: + * This function call mm_memalign and set mm_backtrace pid to free pid + * avoid repeated calculation. + ****************************************************************************/ + +static FAR void *mempool_memalign(FAR void *arg, size_t alignment, + size_t size) +{ + FAR struct memdump_backtrace_s *dump; + FAR void *ret; + + ret = mm_memalign(arg, alignment, size); + if (ret) + { + dump = ret + mm_malloc_size(arg, ret); + dump->pid = MM_BACKTRACE_MEMPOOL_PID; + } + + return ret; +} +#else +# define mempool_memalign mm_memalign +#endif + /**************************************************************************** * Name: mallinfo_handler ****************************************************************************/ @@ -800,11 +829,10 @@ FAR struct mm_heap_s *mm_initialize(FAR const char *name, } heap->mm_mpool = mempool_multiple_init(name, poolsize, MEMPOOL_NPOOLS, - (mempool_multiple_alloc_t)mm_memalign, + (mempool_multiple_alloc_t)mempool_algin, (mempool_multiple_free_t)mm_free, heap, CONFIG_MM_HEAP_MEMPOOL_EXPAND, - CONFIG_MM_HEAP_MEMPOOL_DICTIONARY_EXPAND, - true); + CONFIG_MM_HEAP_MEMPOOL_DICTIONARY_EXPAND); #endif return heap;