Skip to content

Commit

Permalink
epoch: Fix false sharing in Local struct (crossbeam-rs#1026)
Browse files Browse the repository at this point in the history
The perf c2c data shows lots of cacheline contention were caused by
false sharing between epoch and other field in "Local" struct. So
use CachePadded class to align it to another cacheline to resolve
this issue.
  • Loading branch information
linericyang authored and powergee committed Oct 18, 2023
1 parent 655c8cc commit 2da1595
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions crossbeam-epoch/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,6 @@ pub(crate) struct Local {
/// A node in the intrusive linked list of `Local`s.
entry: Entry,

/// The local epoch.
epoch: AtomicEpoch,

/// A reference to the global data.
///
/// When all guards and handles get dropped, this reference is destroyed.
Expand All @@ -315,6 +312,9 @@ pub(crate) struct Local {
prev_epoch: Cell<Epoch>,

collecting: Cell<bool>,

/// The local epoch.
epoch: CachePadded<AtomicEpoch>,
}

// Make sure `Local` is less than or equal to 2048 bytes.
Expand Down Expand Up @@ -343,7 +343,6 @@ impl Local {

let local = Owned::new(Local {
entry: Entry::default(),
epoch: AtomicEpoch::new(Epoch::starting()),
collector: UnsafeCell::new(ManuallyDrop::new(collector.clone())),
bag: UnsafeCell::new(Bag::new()),
guard_count: Cell::new(0),
Expand All @@ -352,6 +351,7 @@ impl Local {
advance_count: Cell::new(0),
prev_epoch: Cell::new(Epoch::starting()),
collecting: Cell::new(false),
epoch: CachePadded::new(AtomicEpoch::new(Epoch::starting())),
})
.into_shared(unprotected());
collector.global.locals.insert(local, unprotected());
Expand Down

0 comments on commit 2da1595

Please sign in to comment.