mempool:Calibration total memory statistics

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
This commit is contained in:
anjiahao 2023-01-10 18:10:28 +08:00 committed by Alin Jerpelea
parent d846004533
commit b362f18d6a
5 changed files with 35 additions and 11 deletions

View File

@ -75,6 +75,9 @@ 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 */
@ -85,12 +88,14 @@ struct mempool_s
sq_queue_t iqueue; /* The free block queue in interrupt mempool */
sq_queue_t equeue; /* The expand block queue for normal mempool */
#if CONFIG_MM_BACKTRACE >= 0
struct list_node alist; /* The used block list in mempool */
struct list_node alist; /* The used block list in mempool */
#else
size_t nalloc; /* The number of used block in mempool */
size_t nalloc; /* The number of used block in mempool */
#endif
spinlock_t lock; /* The protect lock to mempool */
sem_t waitsem; /* The semaphore of waiter get free block */
spinlock_t lock; /* The protect lock to mempool */
sem_t waitsem; /* The semaphore of waiter get free block */
size_t nexpend; /* The number of expend memory for mempool */
size_t totalsize; /* Total size of the expend for mempoll */
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMPOOL)
struct mempool_procfs_entry_s procfs; /* The entry of procfs */
#endif
@ -288,8 +293,8 @@ void mempool_procfs_unregister(FAR struct mempool_procfs_entry_s *entry);
* free - The free memory function for multiples pool.
* arg - The alloc & free memory fuctions used arg.
* expandsize - The expend mempry for all pools in multiples pool.
* dict_expendsize - The expend number for multiple dictnoary
*
* 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.
@ -304,7 +309,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);
size_t dict_expendsize, bool calibrate);
/****************************************************************************
* Name: mempool_multiple_alloc

View File

@ -154,6 +154,8 @@ int mempool_init(FAR struct mempool_s *pool, FAR const char *name)
sq_init(&pool->queue);
sq_init(&pool->iqueue);
sq_init(&pool->equeue);
pool->nexpend = 0;
pool->totalsize = 0;
#if CONFIG_MM_BACKTRACE >= 0
list_initialize(&pool->alist);
@ -173,6 +175,8 @@ int mempool_init(FAR struct mempool_s *pool, FAR const char *name)
return -ENOMEM;
}
pool->nexpend++;
pool->totalsize += size;
mempool_add_queue(&pool->iqueue, pool->ibase, ninterrupt, blocksize);
kasan_poison(pool->ibase, size);
}
@ -194,6 +198,8 @@ int mempool_init(FAR struct mempool_s *pool, FAR const char *name)
return -ENOMEM;
}
pool->nexpend++;
pool->totalsize += size;
mempool_add_queue(&pool->queue, base, ninitial, blocksize);
sq_addlast((FAR sq_entry_t *)(base + ninitial * blocksize),
&pool->equeue);
@ -273,6 +279,8 @@ retry:
return NULL;
}
pool->nexpend++;
pool->totalsize += size;
kasan_poison(base, size);
flags = spin_lock_irqsave(&pool->lock);
mempool_add_queue(&pool->queue, base, nexpand, blocksize);
@ -425,6 +433,11 @@ 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 == -1)
{
@ -436,6 +449,8 @@ int mempool_info_task(FAR struct mempool_s *pool,
info->aordblks += count;
info->uordblks += count * pool->blocksize;
info->aordblks -= pool->nexpend;
info->uordblks -= pool->totalsize;
}
#if CONFIG_MM_BACKTRACE >= 0
else

View File

@ -253,7 +253,8 @@ mempool_multiple_get_dict(FAR struct mempool_multiple_s *mpool,
* free - The free memory function for multiples pool.
* 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
* 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.
@ -266,7 +267,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)
size_t dict_expendsize, bool calibrate)
{
FAR struct mempool_multiple_s *mpool;
FAR struct mempool_s *pools;
@ -325,6 +326,7 @@ 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;
ret = mempool_init(pools + i, name);
if (ret < 0)

View File

@ -259,7 +259,8 @@ FAR struct mm_heap_s *mm_initialize(FAR const char *name,
(mempool_multiple_alloc_t)mm_memalign,
(mempool_multiple_free_t)mm_free, heap,
CONFIG_MM_HEAP_MEMPOOL_EXPAND,
CONFIG_MM_HEAP_MEMPOOL_DICTIONARY_EXPAND);
CONFIG_MM_HEAP_MEMPOOL_DICTIONARY_EXPAND,
true);
#endif
return heap;

View File

@ -804,7 +804,8 @@ FAR struct mm_heap_s *mm_initialize(FAR const char *name,
(mempool_multiple_alloc_t)mm_memalign,
(mempool_multiple_free_t)mm_free, heap,
CONFIG_MM_HEAP_MEMPOOL_EXPAND,
CONFIG_MM_HEAP_MEMPOOL_DICTIONARY_EXPAND);
CONFIG_MM_HEAP_MEMPOOL_DICTIONARY_EXPAND,
true);
#endif
return heap;