masaori335 commented on code in PR #12601:
URL: https://github.com/apache/trafficserver/pull/12601#discussion_r2453592996


##########
CACHE_RWLOCK_ANALYSIS.md:
##########
@@ -0,0 +1,183 @@
+# Cache Reader/Writer Lock Optimization Analysis
+
+## Current Problem: Exclusive Locks for Read Operations
+
+### Current Implementation
+The cache currently uses **exclusive try locks** (`CACHE_TRY_LOCK`) for all 
operations:
+- Cache lookups (read-only)
+- Directory probes (read-only)
+- Cache writes (modifying)
+- Directory inserts/removes (modifying)
+
+**Result**: Even read-only operations acquire exclusive locks, preventing 
concurrent reads.
+
+## Why Reader/Writer Locks Would Help
+
+### Available Infrastructure
+Apache Traffic Server already has **two** reader/writer lock implementations:
+
+1. **`ts::shared_mutex`** (`include/tsutil/TsSharedMutex.h`)
+   - Wrapper around `pthread_rwlock_t`
+   - Provides writer-starvation prevention
+   - Standard interface: `lock()`, `lock_shared()`, `try_lock()`, 
`try_lock_shared()`
+
+2. **`ts::bravo::shared_mutex`** (`include/tsutil/Bravo.h`)
+   - High-performance BRAVO algorithm implementation
+   - Optimized fast-path for readers (lock-free in common case)
+   - Prevents writer starvation with adaptive policy
+   - More complex but potentially much faster
+
+### Cache Operation Breakdown
+
+#### Read-Only Operations (can use shared locks):
+```
+Cache.cc:345          - stripe->directory.probe()    [cache lookup]

Review Comment:
   I tried this approach before and faced a problem. If I understand correctly, 
Directory::probe needs the write lock when it found invalid Dir and call 
dir_delete_entry. This is why I'm waiting RCU/Hazard Pointer.
   
   
https://github.com/apache/trafficserver/blob/0411aa7bdb7139b61bc4671232edcabdb097b941/src/iocore/cache/CacheDir.cc#L522-L527



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to