Repository navigation
fix(fileservice): reduce memory pressure from concurrent cache allocations - #24352
Merged
mergify[bot] merged 6 commits intoMay 13, 2026
Merged
Conversation
…tions (matrixorigin#24348) Fix two issues causing unbounded memory growth under high-concurrency DiskCache read paths (e.g., 1000 TPCC FOR UPDATE terminals): 1. EnsureNBytes could silently skip eviction under contention because it used TryLock-based Evict. When the cache is at capacity and a new allocation is requested, use blocking EvictWithWait to guarantee space is freed before the allocation proceeds. 2. ReadFromOSFile held both the compressed IO buffer (i.Data) and the decompressed CachedData simultaneously until IOVector.Release(). Since ReadFromOSFile is only called from DiskCache.Read (which sets fromCache=diskCache, causing diskCache.Update to skip), the IO buffer can be released immediately after setCachedData succeeds, reducing peak memory by ~30-50% per concurrent read. Co-Authored-By: Claude Opus 4.6 <[email protected]>
ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one. |
Co-Authored-By: Claude Opus 4.6 <[email protected]>
fengttt
approved these changes
May 12, 2026
Contributor
Merge Queue Status
This pull request spent 29 minutes 29 seconds in the queue, with no time running CI. Waiting for
All conditions
ReasonThe merge conditions cannot be satisfied due to failing checks HintYou may have to fix your CI before adding the pull request to the queue again. |
Contributor
Merge Queue Status
This pull request spent 58 minutes 17 seconds in the queue, including 57 minutes 59 seconds running CI. Required conditions to merge
|
This branch was previously deployed
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.
What type of PR is this?
Which issue(s) does this PR fix or relate to?
Fixes #24348
What this PR does / why we need it:
Two issues causing unbounded memory growth under high-concurrency DiskCache read paths (1000 TPCC FOR UPDATE terminals simultaneously hitting
AllocateCacheDataWithHint):EnsureNBytessilently skips eviction under contention: The FIFO cache'sEvictusesTryLock— when 1000 goroutines concurrently callEnsureNBytes, only one actually evicts while the rest skip and proceed to allocate, causing the memory cache to overshoot its configured capacity by up toN × blockSize. Fix: when the cache is already at/over capacity, use blockingEvictWithWaitto guarantee space is freed before returning.IO buffer and CachedData held simultaneously:
ReadFromOSFileheld both the compressed IO buffer (i.Data, allocated viaioAllocator) and the decompressedCachedData(allocated viamemoryCacheAllocator) untilIOVector.Release(). Since this function is only called fromDiskCache.Read(which setsfromCache = diskCache, causingdiskCache.Updateto skip the entry), the IO buffer can be released immediately aftersetCachedDatasucceeds. This reduces peak per-entry memory by ~30-50%.Root Cause Analysis
The OOM path:
LockOp.callNonBlocking→TableScan→DiskCache.Read→setCachedData→constructorFactory→AllocateCacheDataWithHint→MetricsAllocator.AllocateUnder 1000 concurrent FOR UPDATE transactions:
EnsureNByteswas ineffective under contention (TryLock skip)Test plan
pkg/fileservice/...tests passpkg/fileservice/fifocache/...tests passTestLockOpHoldingCacheDataOOMreproduces the concurrency model (run withMO_TEST_OOM_REPRO=1)🤖 Generated with Claude Code