mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 14:27:37 +08:00
mempool:Add mail_info support for multiple pools
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
This commit is contained in:
@@ -381,11 +381,13 @@ void mm_extend(struct mm_heap_s *heap, void *mem, size_t size,
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int mm_mallinfo(struct mm_heap_s *heap, struct mallinfo *info)
|
struct mallinfo mm_mallinfo(struct mm_heap_s *heap)
|
||||||
{
|
{
|
||||||
memset(info, 0, sizeof(struct mallinfo));
|
struct mallinfo info;
|
||||||
host_mallinfo(&info->aordblks, &info->uordblks);
|
|
||||||
return 0;
|
memset(&info, 0, sizeof(struct mallinfo));
|
||||||
|
host_mallinfo(&info.aordblks, &info.uordblks);
|
||||||
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ bool xtensa_imm_heapmember(void *mem);
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int xtensa_imm_mallinfo(struct mallinfo *info);
|
struct mallinfo xtensa_imm_mallinfo(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#undef EXTERN
|
#undef EXTERN
|
||||||
|
|||||||
@@ -177,9 +177,9 @@ bool xtensa_imm_heapmember(void *mem)
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int xtensa_imm_mallinfo(struct mallinfo *info)
|
struct mallinfo xtensa_imm_mallinfo()
|
||||||
{
|
{
|
||||||
return mm_mallinfo(g_iheap, info);
|
return mm_mallinfo(g_iheap);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_XTENSA_IMEM_USE_SEPARATE_HEAP */
|
#endif /* CONFIG_XTENSA_IMEM_USE_SEPARATE_HEAP */
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ bool esp32_iramheap_heapmember(void *mem)
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int esp32_iramheap_mallinfo(struct mallinfo *info)
|
struct mallinfo esp32_iramheap_mallinfo(void)
|
||||||
{
|
{
|
||||||
return mm_mallinfo(g_iramheap, info);
|
return mm_mallinfo(g_iramheap);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ bool esp32_iramheap_heapmember(void *mem);
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int esp32_iramheap_mallinfo(struct mallinfo *info);
|
struct mallinfo esp32_iramheap_mallinfo(void);
|
||||||
|
|
||||||
#undef EXTERN
|
#undef EXTERN
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ bool esp32_rtcheap_heapmember(void *mem)
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int esp32_rtcheap_mallinfo(struct mallinfo *info)
|
struct mallinfo esp32_rtcheap_mallinfo(void)
|
||||||
{
|
{
|
||||||
return mm_mallinfo(g_rtcheap, info);
|
return mm_mallinfo(g_rtcheap);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ bool esp32_rtcheap_heapmember(void *mem);
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int esp32_rtcheap_mallinfo(struct mallinfo *info);
|
struct mallinfo esp32_rtcheap_mallinfo(void);
|
||||||
|
|
||||||
#undef EXTERN
|
#undef EXTERN
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@@ -313,7 +313,7 @@ static ssize_t meminfo_read(FAR struct file *filep, FAR char *buffer,
|
|||||||
|
|
||||||
/* Show heap information */
|
/* Show heap information */
|
||||||
|
|
||||||
mm_mallinfo(entry->heap, &minfo);
|
minfo = mm_mallinfo(entry->heap);
|
||||||
linesize = procfs_snprintf(procfile->line, MEMINFO_LINELEN,
|
linesize = procfs_snprintf(procfile->line, MEMINFO_LINELEN,
|
||||||
"%12s:%11lu%11lu%11lu%11lu%7lu%7lu\n",
|
"%12s:%11lu%11lu%11lu%11lu%7lu%7lu\n",
|
||||||
entry->name,
|
entry->name,
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ typedef CODE FAR void *(*mempool_multiple_alloc_t)(FAR void *arg,
|
|||||||
size_t alignment,
|
size_t alignment,
|
||||||
size_t size);
|
size_t size);
|
||||||
typedef CODE void (*mempool_multiple_free_t)(FAR void *arg, FAR void *addr);
|
typedef CODE void (*mempool_multiple_free_t)(FAR void *arg, FAR void *addr);
|
||||||
|
typedef CODE size_t (*mempool_multiple_alloc_size_t)(FAR void *arg,
|
||||||
|
FAR void *addr);
|
||||||
|
|
||||||
typedef CODE void (mempool_multiple_foreach_t)(FAR struct mempool_s *pool,
|
typedef CODE void (mempool_multiple_foreach_t)(FAR struct mempool_s *pool,
|
||||||
FAR void *arg);
|
FAR void *arg);
|
||||||
@@ -320,6 +322,7 @@ void mempool_procfs_unregister(FAR struct mempool_procfs_entry_s *entry);
|
|||||||
* poolsize - The block size array for pools in multiples pool.
|
* poolsize - The block size array for pools in multiples pool.
|
||||||
* npools - How many pools in multiples pool.
|
* npools - How many pools in multiples pool.
|
||||||
* alloc - The alloc memory function for multiples pool.
|
* alloc - The alloc memory function for multiples pool.
|
||||||
|
* alloc_size - Get the address size of the alloc function.
|
||||||
* free - The free memory function for multiples pool.
|
* free - The free memory function for multiples pool.
|
||||||
* arg - The alloc & free memory fuctions used arg.
|
* arg - The alloc & free memory fuctions used arg.
|
||||||
* chunksize - The multiples pool chunk size.
|
* chunksize - The multiples pool chunk size.
|
||||||
@@ -337,6 +340,7 @@ FAR struct mempool_multiple_s *
|
|||||||
mempool_multiple_init(FAR const char *name,
|
mempool_multiple_init(FAR const char *name,
|
||||||
FAR size_t *poolsize, size_t npools,
|
FAR size_t *poolsize, size_t npools,
|
||||||
mempool_multiple_alloc_t alloc,
|
mempool_multiple_alloc_t alloc,
|
||||||
|
mempool_multiple_alloc_size_t alloc_size,
|
||||||
mempool_multiple_free_t free, FAR void *arg,
|
mempool_multiple_free_t free, FAR void *arg,
|
||||||
size_t chunksize, size_t expandsize,
|
size_t chunksize, size_t expandsize,
|
||||||
size_t dict_expendsize);
|
size_t dict_expendsize);
|
||||||
@@ -492,6 +496,15 @@ void mempool_multiple_foreach(FAR struct mempool_multiple_s *mpool,
|
|||||||
mempool_multiple_foreach_t handle,
|
mempool_multiple_foreach_t handle,
|
||||||
FAR void *arg);
|
FAR void *arg);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: mempool_multiple_mallinfo
|
||||||
|
* Description:
|
||||||
|
* mallinfo returns a copy of updated current multiples pool information.
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
struct mallinfo
|
||||||
|
mempool_multiple_mallinfo(FAR struct mempool_multiple_s *mpool);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: mempool_multiple_info_task
|
* Name: mempool_multiple_info_task
|
||||||
* Description:
|
* Description:
|
||||||
|
|||||||
@@ -315,7 +315,7 @@ void kmm_extend(FAR void *mem, size_t size, int region);
|
|||||||
/* Functions contained in mm_mallinfo.c *************************************/
|
/* Functions contained in mm_mallinfo.c *************************************/
|
||||||
|
|
||||||
struct mallinfo; /* Forward reference */
|
struct mallinfo; /* Forward reference */
|
||||||
int mm_mallinfo(FAR struct mm_heap_s *heap, FAR struct mallinfo *info);
|
struct mallinfo mm_mallinfo(FAR struct mm_heap_s *heap);
|
||||||
struct mallinfo_task; /* Forward reference */
|
struct mallinfo_task; /* Forward reference */
|
||||||
struct mallinfo_task mm_mallinfo_task(FAR struct mm_heap_s *heap,
|
struct mallinfo_task mm_mallinfo_task(FAR struct mm_heap_s *heap,
|
||||||
FAR const struct mm_memdump_s *dump);
|
FAR const struct mm_memdump_s *dump);
|
||||||
|
|||||||
@@ -45,9 +45,7 @@
|
|||||||
|
|
||||||
struct mallinfo kmm_mallinfo(void)
|
struct mallinfo kmm_mallinfo(void)
|
||||||
{
|
{
|
||||||
struct mallinfo info;
|
return mm_mallinfo(g_kmmheap);
|
||||||
mm_mallinfo(g_kmmheap, &info);
|
|
||||||
return info;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
@@ -63,17 +63,21 @@ struct mpool_chunk_s
|
|||||||
|
|
||||||
struct mempool_multiple_s
|
struct mempool_multiple_s
|
||||||
{
|
{
|
||||||
FAR struct mempool_s *pools; /* The memory pool array */
|
FAR struct mempool_s *pools; /* The memory pool array */
|
||||||
size_t npools; /* The number of memory pool array elements */
|
size_t npools; /* The number of memory pool array elements */
|
||||||
size_t expandsize; /* The number not will use it to init erery
|
size_t expandsize; /* The number not will use it to init erery
|
||||||
* pool expandsize
|
* pool expandsize
|
||||||
*/
|
*/
|
||||||
size_t minpoolsize; /* The number is align for each memory pool */
|
size_t minpoolsize; /* The number is align for each memory pool */
|
||||||
FAR void *arg; /* This pointer is used to store the user's
|
FAR void *arg; /* This pointer is used to store the user's
|
||||||
* private data
|
* private data
|
||||||
*/
|
*/
|
||||||
mempool_multiple_alloc_t alloc; /* The alloc function for mempool */
|
mempool_multiple_alloc_t alloc; /* The alloc function for mempool */
|
||||||
mempool_multiple_free_t free; /* The free function for mempool */
|
mempool_multiple_alloc_size_t alloc_size; /* Get the address size of the
|
||||||
|
* alloc function
|
||||||
|
*/
|
||||||
|
mempool_multiple_free_t free; /* The free function for mempool */
|
||||||
|
size_t alloced; /* Total size of alloc */
|
||||||
|
|
||||||
/* This delta describes the relationship between the block size of each
|
/* This delta describes the relationship between the block size of each
|
||||||
* mempool in multiple mempool by user initialized. It is automatically
|
* mempool in multiple mempool by user initialized. It is automatically
|
||||||
@@ -82,19 +86,19 @@ struct mempool_multiple_s
|
|||||||
* arithmetic progressions, otherwise it is an increasing progressions.
|
* arithmetic progressions, otherwise it is an increasing progressions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
size_t delta;
|
size_t delta;
|
||||||
|
|
||||||
/* It is used to record the information recorded by the mempool during
|
/* It is used to record the information recorded by the mempool during
|
||||||
* expansion, and find the mempool by adding an index
|
* expansion, and find the mempool by adding an index
|
||||||
*/
|
*/
|
||||||
|
|
||||||
mutex_t lock;
|
mutex_t lock;
|
||||||
sq_queue_t chunk_queue;
|
sq_queue_t chunk_queue;
|
||||||
size_t chunk_size;
|
size_t chunk_size;
|
||||||
size_t dict_used;
|
size_t dict_used;
|
||||||
size_t dict_col_num_log2;
|
size_t dict_col_num_log2;
|
||||||
size_t dict_row_num;
|
size_t dict_row_num;
|
||||||
FAR struct mpool_dict_s **dict;
|
FAR struct mpool_dict_s **dict;
|
||||||
};
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -157,7 +161,13 @@ mempool_multiple_alloc_chunk(FAR struct mempool_multiple_s *mpool,
|
|||||||
|
|
||||||
if (mpool->chunk_size < mpool->expandsize)
|
if (mpool->chunk_size < mpool->expandsize)
|
||||||
{
|
{
|
||||||
return mpool->alloc(mpool->arg, align, size);
|
ret = mpool->alloc(mpool->arg, align, size);
|
||||||
|
if (ret)
|
||||||
|
{
|
||||||
|
mpool->alloced += mpool->alloc_size(mpool->arg, ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
chunk = (FAR struct mpool_chunk_s *)sq_peek(&mpool->chunk_queue);
|
chunk = (FAR struct mpool_chunk_s *)sq_peek(&mpool->chunk_queue);
|
||||||
@@ -173,6 +183,7 @@ retry:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mpool->alloced += mpool->alloc_size(mpool->arg, tmp);
|
||||||
chunk = (FAR struct mpool_chunk_s *)(tmp + mpool->chunk_size);
|
chunk = (FAR struct mpool_chunk_s *)(tmp + mpool->chunk_size);
|
||||||
chunk->end = tmp + mpool->chunk_size;
|
chunk->end = tmp + mpool->chunk_size;
|
||||||
chunk->start = tmp;
|
chunk->start = tmp;
|
||||||
@@ -345,6 +356,7 @@ mempool_multiple_get_dict(FAR struct mempool_multiple_s *mpool,
|
|||||||
* poolsize - The block size array for pools in multiples pool.
|
* poolsize - The block size array for pools in multiples pool.
|
||||||
* npools - How many pools in multiples pool.
|
* npools - How many pools in multiples pool.
|
||||||
* alloc - The alloc memory function for multiples pool.
|
* alloc - The alloc memory function for multiples pool.
|
||||||
|
* alloc_size - Get the address size of the alloc function.
|
||||||
* free - The free memory function for multiples pool.
|
* free - The free memory function for multiples pool.
|
||||||
* arg - The alloc & free memory fuctions used arg.
|
* arg - The alloc & free memory fuctions used arg.
|
||||||
* chunksize - The multiples pool chunk size.
|
* chunksize - The multiples pool chunk size.
|
||||||
@@ -360,6 +372,7 @@ FAR struct mempool_multiple_s *
|
|||||||
mempool_multiple_init(FAR const char *name,
|
mempool_multiple_init(FAR const char *name,
|
||||||
FAR size_t *poolsize, size_t npools,
|
FAR size_t *poolsize, size_t npools,
|
||||||
mempool_multiple_alloc_t alloc,
|
mempool_multiple_alloc_t alloc,
|
||||||
|
mempool_multiple_alloc_size_t alloc_size,
|
||||||
mempool_multiple_free_t free, FAR void *arg,
|
mempool_multiple_free_t free, FAR void *arg,
|
||||||
size_t chunksize, size_t expandsize,
|
size_t chunksize, size_t expandsize,
|
||||||
size_t dict_expendsize)
|
size_t dict_expendsize)
|
||||||
@@ -397,11 +410,13 @@ mempool_multiple_init(FAR const char *name,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mpool->alloc_size = alloc_size;
|
||||||
mpool->expandsize = expandsize;
|
mpool->expandsize = expandsize;
|
||||||
mpool->chunk_size = chunksize;
|
mpool->chunk_size = chunksize;
|
||||||
mpool->alloc = alloc;
|
mpool->alloc = alloc;
|
||||||
mpool->free = free;
|
mpool->free = free;
|
||||||
mpool->arg = arg;
|
mpool->arg = arg;
|
||||||
|
mpool->alloced = alloc_size(arg, mpool);
|
||||||
sq_init(&mpool->chunk_queue);
|
sq_init(&mpool->chunk_queue);
|
||||||
pools = mempool_multiple_alloc_chunk(mpool, sizeof(uintptr_t),
|
pools = mempool_multiple_alloc_chunk(mpool, sizeof(uintptr_t),
|
||||||
npools * sizeof(struct mempool_s));
|
npools * sizeof(struct mempool_s));
|
||||||
@@ -703,6 +718,50 @@ void mempool_multiple_foreach(FAR struct mempool_multiple_s *mpool,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: mempool_multiple_mallinfo
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
struct mallinfo
|
||||||
|
mempool_multiple_mallinfo(FAR struct mempool_multiple_s *mpool)
|
||||||
|
{
|
||||||
|
struct mallinfo info;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
memset(&info, 0, sizeof(struct mallinfo));
|
||||||
|
|
||||||
|
nxmutex_lock(&mpool->lock);
|
||||||
|
info.arena = mpool->alloced;
|
||||||
|
|
||||||
|
if (mpool->chunk_size >= mpool->expandsize)
|
||||||
|
{
|
||||||
|
FAR struct mpool_chunk_s *chunk;
|
||||||
|
|
||||||
|
chunk = (FAR struct mpool_chunk_s *)sq_peek(&mpool->chunk_queue);
|
||||||
|
info.fordblks += chunk->end - chunk->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
nxmutex_unlock(&mpool->lock);
|
||||||
|
|
||||||
|
for (i = 0; i < mpool->npools; i++)
|
||||||
|
{
|
||||||
|
struct mempoolinfo_s poolinfo;
|
||||||
|
|
||||||
|
mempool_info(mpool->pools + i, &poolinfo);
|
||||||
|
info.fordblks += (poolinfo.ordblks + poolinfo.iordblks)
|
||||||
|
* poolinfo.sizeblks;
|
||||||
|
info.ordblks += poolinfo.ordblks + poolinfo.iordblks;
|
||||||
|
info.aordblks += poolinfo.aordblks;
|
||||||
|
if (info.mxordblk < poolinfo.sizeblks)
|
||||||
|
{
|
||||||
|
info.mxordblk = poolinfo.sizeblks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
info.uordblks += mpool->alloced - info.fordblks;
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: mempool_multiple_info_task
|
* Name: mempool_multiple_info_task
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|||||||
@@ -288,6 +288,7 @@ FAR struct mm_heap_s *mm_initialize(FAR const char *name,
|
|||||||
|
|
||||||
heap->mm_mpool = mempool_multiple_init(name, poolsize, MEMPOOL_NPOOLS,
|
heap->mm_mpool = mempool_multiple_init(name, poolsize, MEMPOOL_NPOOLS,
|
||||||
(mempool_multiple_alloc_t)mempool_memalign,
|
(mempool_multiple_alloc_t)mempool_memalign,
|
||||||
|
(mempool_multiple_alloc_size_t)mm_malloc_size,
|
||||||
(mempool_multiple_free_t)mm_free, heap,
|
(mempool_multiple_free_t)mm_free, heap,
|
||||||
CONFIG_MM_HEAP_MEMPOOL_CHUNK_SIZE,
|
CONFIG_MM_HEAP_MEMPOOL_CHUNK_SIZE,
|
||||||
CONFIG_MM_HEAP_MEMPOOL_EXPAND_SIZE,
|
CONFIG_MM_HEAP_MEMPOOL_EXPAND_SIZE,
|
||||||
|
|||||||
@@ -136,20 +136,28 @@ static void mallinfo_task_handler(FAR struct mm_allocnode_s *node,
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int mm_mallinfo(FAR struct mm_heap_s *heap, FAR struct mallinfo *info)
|
struct mallinfo mm_mallinfo(FAR struct mm_heap_s *heap)
|
||||||
{
|
{
|
||||||
|
struct mallinfo info;
|
||||||
|
#if CONFIG_MM_HEAP_MEMPOOL_THRESHOLD != 0
|
||||||
|
struct mallinfo poolinfo;
|
||||||
|
#endif
|
||||||
#if CONFIG_MM_REGIONS > 1
|
#if CONFIG_MM_REGIONS > 1
|
||||||
int region = heap->mm_nregions;
|
int region = heap->mm_nregions;
|
||||||
#else
|
#else
|
||||||
# define region 1
|
# define region 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DEBUGASSERT(info);
|
memset(&info, 0, sizeof(info));
|
||||||
|
mm_foreach(heap, mallinfo_handler, &info);
|
||||||
|
info.arena = heap->mm_heapsize;
|
||||||
|
|
||||||
memset(info, 0, sizeof(*info));
|
#if CONFIG_MM_HEAP_MEMPOOL_THRESHOLD != 0
|
||||||
mm_foreach(heap, mallinfo_handler, info);
|
poolinfo = mempool_multiple_mallinfo(heap->mm_mpool);
|
||||||
|
|
||||||
info->arena = heap->mm_heapsize;
|
info.uordblks -= poolinfo.fordblks;
|
||||||
|
info.fordblks += poolinfo.fordblks;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Account for the heap->mm_heapend[region] node overhead and the
|
/* Account for the heap->mm_heapend[region] node overhead and the
|
||||||
* heap->mm_heapstart[region]->preceding:
|
* heap->mm_heapstart[region]->preceding:
|
||||||
@@ -158,11 +166,11 @@ int mm_mallinfo(FAR struct mm_heap_s *heap, FAR struct mallinfo *info)
|
|||||||
* and SIZEOF_MM_ALLOCNODE = OVERHEAD_MM_ALLOCNODE + sizeof(mmsize_t).
|
* and SIZEOF_MM_ALLOCNODE = OVERHEAD_MM_ALLOCNODE + sizeof(mmsize_t).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
info->uordblks += region * SIZEOF_MM_ALLOCNODE;
|
info.uordblks += region * SIZEOF_MM_ALLOCNODE;
|
||||||
|
|
||||||
DEBUGASSERT((size_t)info->uordblks + info->fordblks == heap->mm_heapsize);
|
DEBUGASSERT((size_t)info.uordblks + info.fordblks == heap->mm_heapsize);
|
||||||
|
|
||||||
return OK;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
@@ -282,7 +282,7 @@ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size)
|
|||||||
|
|
||||||
mwarn("WARNING: Allocation failed, size %zu\n", alignsize);
|
mwarn("WARNING: Allocation failed, size %zu\n", alignsize);
|
||||||
#ifdef CONFIG_MM_DUMP_ON_FAILURE
|
#ifdef CONFIG_MM_DUMP_ON_FAILURE
|
||||||
mm_mallinfo(heap, &minfo);
|
minfo = mm_mallinfo(heap);
|
||||||
mwarn("Total:%d, used:%d, free:%d, largest:%d, nused:%d, nfree:%d\n",
|
mwarn("Total:%d, used:%d, free:%d, largest:%d, nused:%d, nfree:%d\n",
|
||||||
minfo.arena, minfo.uordblks, minfo.fordblks,
|
minfo.arena, minfo.uordblks, minfo.fordblks,
|
||||||
minfo.mxordblk, minfo.aordblks, minfo.ordblks);
|
minfo.mxordblk, minfo.aordblks, minfo.ordblks);
|
||||||
|
|||||||
+18
-8
@@ -845,6 +845,7 @@ FAR struct mm_heap_s *mm_initialize(FAR const char *name,
|
|||||||
|
|
||||||
heap->mm_mpool = mempool_multiple_init(name, poolsize, MEMPOOL_NPOOLS,
|
heap->mm_mpool = mempool_multiple_init(name, poolsize, MEMPOOL_NPOOLS,
|
||||||
(mempool_multiple_alloc_t)mempool_memalign,
|
(mempool_multiple_alloc_t)mempool_memalign,
|
||||||
|
(mempool_multiple_alloc_size_t)mm_malloc_size,
|
||||||
(mempool_multiple_free_t)mm_free, heap,
|
(mempool_multiple_free_t)mm_free, heap,
|
||||||
CONFIG_MM_HEAP_MEMPOOL_CHUNK_SIZE,
|
CONFIG_MM_HEAP_MEMPOOL_CHUNK_SIZE,
|
||||||
CONFIG_MM_HEAP_MEMPOOL_EXPAND_SIZE,
|
CONFIG_MM_HEAP_MEMPOOL_EXPAND_SIZE,
|
||||||
@@ -862,17 +863,19 @@ FAR struct mm_heap_s *mm_initialize(FAR const char *name,
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int mm_mallinfo(FAR struct mm_heap_s *heap, FAR struct mallinfo *info)
|
struct mallinfo mm_mallinfo(FAR struct mm_heap_s *heap)
|
||||||
{
|
{
|
||||||
|
struct mallinfo info;
|
||||||
|
#if CONFIG_MM_HEAP_MEMPOOL_THRESHOLD != 0
|
||||||
|
struct mallinfo poolinfo;
|
||||||
|
#endif
|
||||||
#if CONFIG_MM_REGIONS > 1
|
#if CONFIG_MM_REGIONS > 1
|
||||||
int region;
|
int region;
|
||||||
#else
|
#else
|
||||||
# define region 0
|
# define region 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DEBUGASSERT(info);
|
memset(&info, 0, sizeof(struct mallinfo));
|
||||||
|
|
||||||
memset(info, 0, sizeof(struct mallinfo));
|
|
||||||
|
|
||||||
/* Visit each region */
|
/* Visit each region */
|
||||||
|
|
||||||
@@ -884,15 +887,22 @@ int mm_mallinfo(FAR struct mm_heap_s *heap, FAR struct mallinfo *info)
|
|||||||
|
|
||||||
DEBUGVERIFY(mm_lock(heap));
|
DEBUGVERIFY(mm_lock(heap));
|
||||||
tlsf_walk_pool(heap->mm_heapstart[region],
|
tlsf_walk_pool(heap->mm_heapstart[region],
|
||||||
mallinfo_handler, info);
|
mallinfo_handler, &info);
|
||||||
mm_unlock(heap);
|
mm_unlock(heap);
|
||||||
}
|
}
|
||||||
#undef region
|
#undef region
|
||||||
|
|
||||||
info->arena = heap->mm_heapsize;
|
info.arena = heap->mm_heapsize;
|
||||||
info->uordblks = info->arena - info->fordblks;
|
info.uordblks = info.arena - info.fordblks;
|
||||||
|
|
||||||
return OK;
|
#if CONFIG_MM_HEAP_MEMPOOL_THRESHOLD != 0
|
||||||
|
poolinfo = mempool_multiple_mallinfo(heap->mm_mpool);
|
||||||
|
|
||||||
|
info.uordblks -= poolinfo.fordblks;
|
||||||
|
info.fordblks += poolinfo.fordblks;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct mallinfo_task mm_mallinfo_task(FAR struct mm_heap_s *heap,
|
struct mallinfo_task mm_mallinfo_task(FAR struct mm_heap_s *heap,
|
||||||
|
|||||||
@@ -45,9 +45,7 @@
|
|||||||
|
|
||||||
struct mallinfo mallinfo(void)
|
struct mallinfo mallinfo(void)
|
||||||
{
|
{
|
||||||
struct mallinfo info;
|
return mm_mallinfo(USR_HEAP);
|
||||||
mm_mallinfo(USR_HEAP, &info);
|
|
||||||
return info;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
Reference in New Issue
Block a user