Conversation
ming1
commented
Oct 1, 2025
Contributor
- add get_batch() & put_batch()
- add test
- add --batch to benches/compare.rs
Add support for allocating and freeing consecutive bits atomically: - get_batch(nr_bits, hint): allocate nr_bits consecutive bits - put_batch(bitnr, nr_bits, hint): free nr_bits consecutive bits - Constraint: nr_bits must be <= bits_per_word() to ensure atomicity - Both operations are lock-free and thread-safe using atomic fetch_or/fetch_and Implementation includes helper methods for finding consecutive zero bits and comprehensive test coverage for edge cases, concurrency, fragmentation, and word boundary handling. Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Add --batch NR_BITS parameter to bench_compare binary to benchmark get_batch() and put_batch() APIs: - When --batch > 1, runs batch mode benchmarking only Sbitmap - When --batch = 1 (default), runs normal mode with both implementations - Validates batch_size <= bits_per_word() constraint - Refactor benchmark code to share common logic via benchmark_internal() This allows measuring performance of consecutive bit allocation/deallocation under high concurrency scenarios. Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Add init_hint() helper to eliminate code duplication between run_workload() and run_batch_workload(). Both functions now use the same hint initialization logic that combines stack address and system time for pseudo-random distribution. Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Update README.md to document the new batch allocation APIs: - Add "Batch Allocation" usage example showing how to allocate and free consecutive bits atomically - Document get_batch() and put_batch() methods in API section - Add batch operations to Memory Ordering guarantees - Update Performance Characteristics with batch complexity - Add batch resource allocation to Use Cases - Document --batch parameter in benchmarks section Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Split test_batch_word_boundary into two versions: - test_batch_word_boundary_64bit for 64-bit systems (shift=6, 64 bits/word) - test_batch_word_boundary_32bit for 32-bit systems (shift=5, 32 bits/word) This fixes the shift overflow error on i686 where usize is 32 bits and cannot support 64-bit words. Also fix clippy warning by using div_ceil() and inline format args. Signed-off-by: Ming Lei <tom.leiming@gmail.com>
When nr_bits equals BITS_PER_WORD (32 on i686), the expression (1usize << nr_bits) causes shift overflow. This helper checks for this special case and returns usize::MAX instead of shifting. Applied to three locations: - find_next_zero_batch() - get_batch_from_word() - put_batch() Fixes test_batch_concurrent failure on i686 architecture. Signed-off-by: Ming Lei <tom.leiming@gmail.com>
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.