Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we avoid to call try_advance in some senarios? [crossbeam-epoch] #1001

Open
Yriuns opened this issue Jul 6, 2023 · 2 comments
Open

Can we avoid to call try_advance in some senarios? [crossbeam-epoch] #1001

Yriuns opened this issue Jul 6, 2023 · 2 comments

Comments

@Yriuns
Copy link

Yriuns commented Jul 6, 2023

Recently I'm working on a epoch-based memory reclamation library and learned a lot of from crossbeam-epoch. Thank you for your great work.

But I noticed that we will call global().collect() every PINNINGS_BETWEEN_COLLECT 1st pins.
In the senario which defer_destroy happens rarely, there is nothing to collect in most time. But try_advance issues a SeqCst ordering and a traverse of all threads, which is heavy. I wonder if we can add something like:

if self.queue.empty() {
    return
}

at the beginning of collect(), to reduce the overhead?

pub(crate) fn collect(&self, guard: &Guard) {
let global_epoch = self.try_advance(guard);
let steps = if cfg!(crossbeam_sanitize) {
usize::max_value()
} else {
Self::COLLECT_STEPS
};
for _ in 0..steps {
match self.queue.try_pop_if(
|sealed_bag: &SealedBag| sealed_bag.is_expired(global_epoch),
guard,
) {
None => break,
Some(sealed_bag) => drop(sealed_bag),
}
}
}

@loyd
Copy link

loyd commented Mar 24, 2024

I observed the same situation for my case (99.99% reads), especially with many threads that's related to #852

Another approach is implemented in the scc crate, where scan is started ONLY (@wvwwvwwv, is it correct?) when:

  • the current thread has garbage
  • OR some other thread terminated with some garbage
  • OR user code in another thread explicitly called suspend().

@taiki-e, what do you think about it?

@wvwwvwwv
Copy link

@loyd yes, correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants