Skip to content

[alloc+atomic] Make allocation and deallocation paths of slab allocators mutex free#18

Merged
williamwutq merged 14 commits into
masterfrom
allocators
Jun 11, 2026
Merged

[alloc+atomic] Make allocation and deallocation paths of slab allocators mutex free#18
williamwutq merged 14 commits into
masterfrom
allocators

Conversation

@williamwutq

@williamwutq williamwutq commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Description: Under the flag atomic, making the two slab allocators (SlabBStackAllocator and CheckedSlabBStackAllocator) operations atomic and mutex free with new atomic operations on the free list. Also adds the Discard option to Rust BStackGenOp, 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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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 SlabBStackAllocator with process_gen (pop) and cross_exchange (push/splice) under atomic.
  • Updated CheckedSlabBStackAllocator free-list operations similarly; retained a mutex only to make recover() single-flight.
  • Reworked CheckedSlabBStackAllocator::recover() in atomic builds into a single process_gen scan 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.

Comment thread src/alloc/checked_slab.rs Outdated
@williamwutq williamwutq requested a review from Copilot June 10, 2026 23:27
@williamwutq williamwutq marked this pull request as ready for review June 10, 2026 23:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Comment thread src/alloc/checked_slab.rs

@williamwutq williamwutq left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@williamwutq williamwutq merged commit e7226d6 into master Jun 11, 2026
17 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.

2 participants