You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Replace atomic_shared_ptr<EventTracker> with unique_ptr in Cache and raw ptr in NVM
Summary:
Every cache operation (find, allocate, insert, remove, eviction) call recordEvent(), which calls getEventTracker(). Previously, getEventTracker() called folly::atomic_shared_ptr<EventTracker>::load(), which returns a shared_ptr — incurring an atomic refcount increment on load and an atomic decrement on destruction. On x86, each of these is a lock xadd instruction that forces cache-line synchronization across cores. This overhead occurs on every cache operation, even when the event is not sampled.
Since setEventTracker() is called once during initialization (before workers start) and never again, atomic shared pointer semantics are unnecessary. This diff replaces the atomic_shared_ptr with a "cached raw pointer" pattern:
- Ownership: std::unique_ptr<EventTracker> in CacheBase holds the sole owning reference, set once during init.
- Navy layer: Engine, EnginePair, Driver, and AbstractCache now take and store non-owning EventTracker* pointers, since lifetime is managed by CacheBase. These are set during NVM cache initialization and invalidated by
~CacheAllocator() which destroys NVM cache before ~CacheBase() destroys the EventTracker.
Reviewed By: rlyerly
Differential Revision: D95646744
fbshipit-source-id: 39d2d352e3bf72bc669c9cdf5dfd3fd165178625
0 commit comments