Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@ming1
Copy link
Contributor

@ming1 ming1 commented Oct 1, 2025

  • add get_batch() & put_batch()
  • add test
  • add --batch to benches/compare.rs

ming1 added 7 commits October 1, 2025 15:20
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
Signed-off-by: Ming Lei <[email protected]>
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 <[email protected]>
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 <[email protected]>
@ming1 ming1 merged commit fd44eec into main Oct 1, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant