Skip to content

Commit

Permalink
epoch: Fix false sharing in Local struct (#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 Sep 12, 2023
1 parent 9384f1e commit 4bb27db
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 @@ -273,9 +273,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 @@ -294,6 +291,9 @@ pub(crate) struct Local {
///
/// This is just an auxiliary counter that sometimes kicks off collection.
pin_count: Cell<Wrapping<usize>>,

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

// Make sure `Local` is less than or equal to 2048 bytes.
Expand All @@ -320,12 +320,12 @@ 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),
handle_count: Cell::new(1),
pin_count: Cell::new(Wrapping(0)),
epoch: CachePadded::new(AtomicEpoch::new(Epoch::starting())),
})
.into_shared(unprotected());
collector.global.locals.insert(local, unprotected());
Expand Down

0 comments on commit 4bb27db

Please sign in to comment.