memepool:fix memory consumption double counting issue
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
This commit is contained in:
parent
49cd7a795a
commit
781a34da94
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue