Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mempool:Allocate a chunk for multiple mempool avoid memory fragmentation #9488

Merged
merged 2 commits into from Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions arch/sim/src/sim/sim_heap.c
Expand Up @@ -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));
host_mallinfo(&info->aordblks, &info->uordblks);
return 0;
struct mallinfo info;

memset(&info, 0, sizeof(struct mallinfo));
host_mallinfo(&info.aordblks, &info.uordblks);
return info;
}

/****************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion arch/xtensa/include/arch.h
Expand Up @@ -163,7 +163,7 @@ bool xtensa_imm_heapmember(void *mem);
*
****************************************************************************/

int xtensa_imm_mallinfo(struct mallinfo *info);
struct mallinfo xtensa_imm_mallinfo(void);
#endif

#undef EXTERN
Expand Down
4 changes: 2 additions & 2 deletions arch/xtensa/src/esp32/esp32_imm.c
Expand Up @@ -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 */
4 changes: 2 additions & 2 deletions arch/xtensa/src/esp32/esp32_iramheap.c
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion arch/xtensa/src/esp32/esp32_iramheap.h
Expand Up @@ -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
#ifdef __cplusplus
Expand Down
4 changes: 2 additions & 2 deletions arch/xtensa/src/esp32/esp32_rtcheap.c
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion arch/xtensa/src/esp32/esp32_rtcheap.h
Expand Up @@ -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
#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion fs/procfs/fs_procfsmeminfo.c
Expand Up @@ -313,7 +313,7 @@ static ssize_t meminfo_read(FAR struct file *filep, FAR char *buffer,

/* Show heap information */

mm_mallinfo(entry->heap, &minfo);
minfo = mm_mallinfo(entry->heap);
linesize = procfs_snprintf(procfile->line, MEMINFO_LINELEN,
"%12s:%11lu%11lu%11lu%11lu%7lu%7lu\n",
entry->name,
Expand Down
18 changes: 16 additions & 2 deletions include/nuttx/mm/mempool.h
Expand Up @@ -60,6 +60,8 @@ typedef CODE FAR void *(*mempool_multiple_alloc_t)(FAR void *arg,
size_t alignment,
size_t size);
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,
FAR void *arg);
Expand Down Expand Up @@ -320,8 +322,10 @@ void mempool_procfs_unregister(FAR struct mempool_procfs_entry_s *entry);
* poolsize - The block size array for pools in multiples pool.
* npools - How many pools in 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.
* arg - The alloc & free memory fuctions used arg.
* chunksize - The multiples pool chunk size.
* expandsize - The expend mempry for all pools in multiples pool.
* dict_expendsize - The expend size for multiple dictnoary.
* Returned Value:
Expand All @@ -336,8 +340,9 @@ FAR struct mempool_multiple_s *
mempool_multiple_init(FAR const char *name,
FAR size_t *poolsize, size_t npools,
mempool_multiple_alloc_t alloc,
mempool_multiple_free_t free,
FAR void *arg, size_t expandsize,
mempool_multiple_alloc_size_t alloc_size,
mempool_multiple_free_t free, FAR void *arg,
size_t chunksize, size_t expandsize,
size_t dict_expendsize);

/****************************************************************************
Expand Down Expand Up @@ -491,6 +496,15 @@ void mempool_multiple_foreach(FAR struct mempool_multiple_s *mpool,
mempool_multiple_foreach_t handle,
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
* Description:
Expand Down
2 changes: 1 addition & 1 deletion include/nuttx/mm/mm.h
Expand Up @@ -315,7 +315,7 @@ void kmm_extend(FAR void *mem, size_t size, int region);
/* Functions contained in mm_mallinfo.c *************************************/

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 mm_mallinfo_task(FAR struct mm_heap_s *heap,
FAR const struct mm_memdump_s *dump);
Expand Down
13 changes: 10 additions & 3 deletions mm/Kconfig
Expand Up @@ -207,21 +207,28 @@ config MM_HEAP_MEMPOOL_THRESHOLD
than the threshold, the memory will be requested from the
multiple mempool by default.

config MM_HEAP_MEMPOOL_EXPAND
config MM_HEAP_MEMPOOL_EXPAND_SIZE
int "The expand size for each mempool in multiple mempool"
default 4096
depends on MM_HEAP_MEMPOOL_THRESHOLD != 0
---help---
This size describes the size of each expansion of each memory
pool with insufficient memory in the multi-level memory pool.

config MM_HEAP_MEMPOOL_DICTIONARY_EXPAND
config MM_HEAP_MEMPOOL_DICTIONARY_EXPAND_SIZE
int "The expand size for multiple mempool's dictonary"
default MM_HEAP_MEMPOOL_EXPAND
default MM_HEAP_MEMPOOL_EXPAND_SIZE
depends on MM_HEAP_MEMPOOL_THRESHOLD != 0
---help---
This size describes the multiple mempool dictonary expend.

config MM_HEAP_MEMPOOL_CHUNK_SIZE
int "The multiples pool chunk size"
default 0
depends on MM_HEAP_MEMPOOL_THRESHOLD != 0
---help---
This size describes the multiple mempool chunk size.

config FS_PROCFS_EXCLUDE_MEMPOOL
bool "Exclude mempool"
default DEFAULT_SMALL
Expand Down
4 changes: 1 addition & 3 deletions mm/kmm_heap/kmm_mallinfo.c
Expand Up @@ -45,9 +45,7 @@

struct mallinfo kmm_mallinfo(void)
{
struct mallinfo info;
mm_mallinfo(g_kmmheap, &info);
return info;
return mm_mallinfo(g_kmmheap);
}

/****************************************************************************
Expand Down