Open tatsuya6502 opened 9 months ago
Unlike crossbeam-epoch
, seize
provides the followings:
batch_size
: Collector::batch_size
Collector::epoch_frequency
seize
collector.I am doing some experiments in a separate repository.
Memo:
Ideally, I want a concurrent memory reclamation library to provide the followings:
Hi! I happened to come across this issue and can share some details about seize.
One of the biggest benefits of seize over crossbeam-epoch is predictable latency. Epoch based reclamation has the issue that you have to check whether it is safe to free objects every once in a while when pinning/unpinning a threads, and this check is very expensive as you have to access shared memory from other threads. This means you run into a fundamental tradeoff between latency and memory efficiency. Seize on the other hand only performs this check once when retiring a batch (by pushing the objects to other threads), and uses reference counting to free memory.
This is an important consideration for a cache as you want an optimal balance between performance and memory usage.
Give us a control whether this differed destruction request should be buffered in a thread local storage or not.
This is something I've been thinking about. The problem is that seize requires at least as many objects as the number of active threads to be able to retire a batch, as each object acts as a node in a local thread linked list. Skipping the thread-local buffer would require allocating a large chunk of memory to perform the retirement process, which may be confusing.
What you can do is try to reclaim by calling Guard::flush
after large objects are retired.
I also recently released papaya, a hash table built on seize. I'd be interested in porting moka to use papaya and see the results, I'd expect significant performance improvements compared to the internal cht, especially for readers. Is that something you'd be open to?
@ibraheemdev
Is that something you'd be open to?
Thanks. Yes, I am open to it. I was not aware of papaya, but at first glance, it sounds like a good idea to use it in moka!
Try
seize
crate as a replacement ofcrossbeam-epoch
crate.moka
cache usescrossbeam-epoch
in its lock-free concurrent hash table calledcht
.crossbeam-epoch
is an epoch-based garbage collector and helps to implement high-performance concurrent data structures likecht
. However, we have been struggling for years with the spec ofcrossbeam-epoch
, which does not guarantee to run the destructor of the pointed objects.https://docs.rs/crossbeam-epoch/0.9.18/crossbeam_epoch/struct.Guard.html#method.defer_destroy
Many of
moka
cache users expect the cached entries to be dropped as soon as they are evicted from the cache, of course. However, thiscrossbeam-epoch
spec causes these evicted entries to be dropped with some delays or never dropped.We have added mitigations for it (notes) and they mostly work except performance degradation. However, there are still some corner cases which seems difficult to solve/mitigate. It might be the time to try alternatives like
seize
.seize
is based on Hyaline reclamation scheme and used in a concurrent hash table calledflurry
.