[alloc+atomic] Make allocation and deallocation paths of slab allocators mutex free#18
Merged
Conversation
… no concurrent changes to free list
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the two slab allocators to remove allocator-level mutexes under the atomic feature by making free-list push/pop operations linearizable using BStack::cross_exchange and BStack::process_gen, aiming to make allocation/deallocation paths mutex-free while preserving (or improving) crash/thread-safety guarantees.
Changes:
- Replaced mutex-serialized free-list operations in
SlabBStackAllocatorwithprocess_gen(pop) andcross_exchange(push/splice) underatomic. - Updated
CheckedSlabBStackAllocatorfree-list operations similarly; retained a mutex only to makerecover()single-flight. - Reworked
CheckedSlabBStackAllocator::recover()inatomicbuilds into a singleprocess_genscan pass plus lock-free per-block reclaim.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/alloc/slab.rs | Removes allocator mutex under atomic and makes free-list push/pop mutex-free via cross_exchange/process_gen. |
| src/alloc/checked_slab.rs | Makes alloc/dealloc/realloc free-list paths mutex-free under atomic, retains mutex only for single-flight recovery, and rewrites recover() to use a locked process_gen scan. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Description: Under the flag
atomic, making the two slab allocators (SlabBStackAllocatorandCheckedSlabBStackAllocator) operations atomic and mutex free with new atomic operations on the free list. Also adds theDiscardoption to RustBStackGenOp, which is C's pop with null pointer input.Important Feature: No
Type: Allocator - Optimization; Allocator - Concurrent
Tests: Included
Feature Flags: alloc + set + atomic
Breaking change: No
New Types: None
Rust Only: No
Fuzz: Yes
Safety Review: Needed: Crash Safety, Invariants, Thread Safety