Repository navigation
Conversation
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 <anchao.archer@bytedance.com>
|
| (((FAR char *)kasan_clear_tag(oldblk) - | ||
| ((FAR char *)kasan_clear_tag(dict->addr) + | ||
| mpool->minpoolsize)) % MEMPOOL_REALBLOCKSIZE(dict->pool)); | ||
| if (size > 0 && size <= dict->pool->blocksize && blkbase == oldblk) |
Contributor
There was a problem hiding this comment.
why need check blkbase == oldblk
casaroli
requested changes
Oct 27, 2026
| (((FAR char *)kasan_clear_tag(oldblk) - | ||
| ((FAR char *)kasan_clear_tag(dict->addr) + | ||
| mpool->minpoolsize)) % MEMPOOL_REALBLOCKSIZE(dict->pool)); | ||
| if (size > 0 && size <= dict->pool->blocksize && blkbase == oldblk) |
Contributor
There was a problem hiding this comment.
This also keeps the block when the size shrinks to a smaller pool: realloc(p, 16) on a 512-byte block now keeps the 512-byte block, where before the data moved to the 16-byte pool.
Fix: reuse the block only when mempool_multiple_find(mpool, size) == dict->pool.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Optimize
mempool_multiple_realloc()by returning the original block whenthe requested size still fits in the current multiple mempool block.
The previous implementation always allocated a new block, copied data, and
freed the old block even when the new size stayed within the same pool size
class. This change adds an in-place fast path for normal mempool blocks.
Details
The fast path is used only when:
The base-address check keeps existing behavior for interior pointers such as
mempool_multiple_memalign()results, where the available tail space may besmaller than the full pool block.
Benefits
Testing
sim/nsh