Add SegRwLock : a segment RwLock Type#424
Conversation
Signed-off-by: Ping Zhao <ping.zhao@intel.com> Signed-off-by: Lin Yang <lin.a.yang@intel.com>
Signed-off-by: Ping Zhao <ping.zhao@intel.com> Signed-off-by: Lin Yang <lin.a.yang@intel.com>
318440b to
9a047fb
Compare
|
It's not clear to me what use case this is trying to solve. The most common use case for RwLock is to have many readers but few writers. Your implementation does not help with this case since all the readers are still thrashing Have you considered a different implementation using a sharded RwLock? The basic idea is to have an array of |
|
Original RwLock memory layout likes this:
One matter need to care is that |
Add a new RwLock type as SegRwLock which separate the cache line for Read state and Write state in RwLock to solve the cache-line false sharing problem in RwLock in multi threads scenarios.
Since the 'Data' protected by RwLock shares the same cache-line with lock state. When lock state changes the whole cache-line need update which is not necessary for 'Data' in Read lock, and cause unnecessary cache-line update. SegRwLock put Read state in one cache-line and Write state and 'Data' in the other cache-line, to avoid the false sharing between Read state and 'Data'.