From 2eb0a4fd7ec05268675a1ef3bc824badfc6c92c1 Mon Sep 17 00:00:00 2001 From: chao an Date: Tue, 27 Oct 2026 17:45:20 +0800 Subject: [PATCH] mm/mempool: Reuse same-size blocks in realloc Return the original block when a multiple mempool realloc request still fits in the current pool block. This avoids unnecessary allocation, copy, and free work for same size class reallocations. Signed-off-by: chao an --- mm/mempool/mempool_multiple.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mm/mempool/mempool_multiple.c b/mm/mempool/mempool_multiple.c index a53faa06ecd19..75a0aa6a5873e 100644 --- a/mm/mempool/mempool_multiple.c +++ b/mm/mempool/mempool_multiple.c @@ -596,6 +596,11 @@ FAR void *mempool_multiple_realloc(FAR struct mempool_multiple_s *mpool, return NULL; } + if (size > 0 && mempool_multiple_find(mpool, size) == dict->pool) + { + return oldblk; + } + blk = mempool_multiple_alloc(mpool, size); if (blk != NULL && oldblk != NULL) {