[Backport][main to 0.9] | feat(cache): make FileCachePool thread-safe for multi-vCPU access (#1555) - #1571
Merged
lihuiba merged 1 commit intoJul 27, 2026
Conversation
) * feat(cache): make FileCachePool thread-safe for multi-vCPU access Guard all FileCachePool metadata (fileIndex_, lru_, cold tiers, totalUsed_, tuning state) with a coarse photon::mutex (m_lock_) so one pool can be shared across multiple photon vCPUs (OS threads). Invariants: - m_lock_ is held only across in-memory ops; never across open()/do_open() or forceRecycle()/eviction(), keeping the lock order rw_lock -> m_lock_ one-way (avoids ABBA with ObjectCache's per-item mutex and non-reentrant self-deadlock). - eviction/evict snapshot a victim under m_lock_, release it, do the I/O (open()+WLOCK truncate), then re-lock to finalize. - the write path accounts size under the store rw_lock (updateSpace fstats under m_lock_) so it can't drift against eviction's WLOCK+truncate; forceRecycle() is deferred to do_pwritev2 after rw_lock is released. - running_/exit_/isFull_ and LruEntry::truncate_done become std::atomic. Add a multi-vCPU concurrency stress test (CachePool.concurrent_stress). QuotaFilePool is left unchanged and documented as not-yet-thread-safe (it is currently unwired: the factory always builds a plain FileCachePool). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * check total used in eviction loop --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
xiaoyang-hhh
force-pushed
the
backport-pr-eef65fb012f83dcc0fa4aa9ec3d8997131160aaf-0.9
branch
from
July 27, 2026 03:18
76efcad to
5797fa4
Compare
xiaoyang-hhh
marked this pull request as ready for review
July 27, 2026 03:23
lihuiba
approved these changes
Jul 27, 2026
photonlibos
deleted the
backport-pr-eef65fb012f83dcc0fa4aa9ec3d8997131160aaf-0.9
branch
July 27, 2026 08:21
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Guard all FileCachePool metadata (fileIndex_, lru_, cold tiers, totalUsed_,
tuning state) with a coarse photon::mutex (m_lock_) so one pool can be shared
across multiple photon vCPUs (OS threads).
Invariants:
forceRecycle()/eviction(), keeping the lock order rw_lock -> m_lock_ one-way
(avoids ABBA with ObjectCache's per-item mutex and non-reentrant self-deadlock).
(open()+WLOCK truncate), then re-lock to finalize.
m_lock_) so it can't drift against eviction's WLOCK+truncate; forceRecycle()
is deferred to do_pwritev2 after rw_lock is released.
Add a multi-vCPU concurrency stress test (CachePool.concurrent_stress).
QuotaFilePool is left unchanged and documented as not-yet-thread-safe (it is
currently unwired: the factory always builds a plain FileCachePool).
Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com
Co-authored-by: Claude Opus 4.8 noreply@anthropic.com
Generated by Backport Auto PR, by cherry-pick related commits.
Please review and decide whether to merge or close this backport PR.
Conflicts
Cherry-pick produced conflicts. Conflict markers are committed as-is; please resolve them manually before merging.