-
Notifications
You must be signed in to change notification settings - Fork 349
Add a simple batch allocator #10456
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
base: main
Are you sure you want to change the base?
Add a simple batch allocator #10456
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces a simple batch allocator for managing equal-size memory pools where allocated elements are returned to a free pool rather than being deallocated. The allocator dynamically grows the pool using power-of-2 sized batches (starting with 2 elements, up to a maximum of 32 per batch) and uses bitmasks to track allocation state.
Key Changes
- New batch allocator API with
batch_alloc()andbatch_free()functions - Dynamic pool growth strategy using power-of-2 batch sizes
- Comprehensive unit test suite for the batch allocator
Reviewed changes
Copilot reviewed 7 out of 11 changed files in this pull request and generated 15 comments.
Show a summary per file
| File | Description |
|---|---|
| src/include/sof/batch.h | New public API header declaring batch allocator functions |
| src/lib/batch.c | Implementation of batch allocator with dynamic growth and bitmask-based tracking |
| src/lib/CMakeLists.txt | Added batch.c to the common source files list |
| test/ztest/unit/batch/testcase.yaml | Test configuration for batch allocator unit tests |
| test/ztest/unit/batch/test_batch_ztest.c | Unit tests validating allocation/deallocation across multiple batch sizes |
| test/ztest/unit/batch/prj.conf | Ztest project configuration for batch tests |
| test/ztest/unit/batch/CMakeLists.txt | CMake build configuration for batch unit tests |
| test/ztest/unit/math/basic/trigonometry/prj.conf | No functional change (formatting only) |
| test/ztest/unit/math/basic/arithmetic/prj.conf | No functional change (formatting only) |
| test/ztest/unit/list/prj.conf | No functional change (formatting only) |
| test/ztest/unit/fast-get/prj.conf | No functional change (formatting only) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
46b8123 to
33f9c9e
Compare
lgirdwood
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whats the use case here ?
@lgirdwood memory domains |
|
The PTL Jenkins failure https://sof-ci.01.org/sofpr/PR10456/build18317/devicetest/index.html?model=PTLP_RVP_SDW&testcase=check-runtime-pm-status is strange. I cannot find earlier occurrences and it couldn't be caused by this PR, because it isn't changing runtime by itself. The test has been run on top of 70828dd - before #10386 was merged |
Add missing "new line" symbols in multiple prj.conf files. Signed-off-by: Guennadi Liakhovetski <[email protected]>
Add a simple "batch allocator." It allocates memory for equally sized objects, that never has to be freed, but can be reused instead. The first call to this allocator allocates two instances of the object, the next one allocates 4, then 8, 16, and after that every new allocation request adds 32 instances. When those objects are freed, they are only marked as free and kept for reuse. Also add a unit test for it. Signed-off-by: Guennadi Liakhovetski <[email protected]>
kv2019i
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice to have the testsuite included.
ok, memory domain kobjects ? Why does this need to be special for memory domain ? Can you give some more context around usage. If its for general purpose use within certain domain, then this is what vregion is for. |
@lgirdwood don't think vregions are related. This is to adapt to the fact, that memory domains cannot be freed, and therefore should be reused. So this allocator just grows the pool of objects as needed. If no free object is available, a new batch is allocated, when objects are released, they're returned to the pool, but never freed back to the heap. Memory domains should be the first user of this allocator, but it's generic. It is somewhat similar to module resource containers, so we can move those to this allocator too if desired. |
Ok, so is this for memory domain context data or general module data ? |
add an allocator for equal size pool management where allocated elements are never freed but only added to a free pool