Skip to content

fix: reduce CN RSS pressure under TPCC - #24535

Merged
mergify[bot] merged 8 commits into
matrixorigin:4.0-devfrom
LeftHandCold:fix/tpcc-cn-rss-oom
May 23, 2026
Merged

mergify[bot] merged 8 commits into
matrixorigin:4.0-devfrom
LeftHandCold:fix/tpcc-cn-rss-oom

Conversation

@LeftHandCold

@LeftHandCold LeftHandCold commented May 22, 2026 •

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #24534

What this PR does / why we need it:

This PR reduces CN RSS pressure under high-concurrency TPCC / sysbench workloads.

  1. Adds real target-based pressure eviction APIs for FileService memory cache and objectio metadata cache. Existing EvictMemoryCaches / EvictCache only evict to current capacity and do not release RSS when caches are already under cap.
  2. Hooks CN RSS scavenging to evict caches by RSS watermark: >=85% actual memory lowers cache targets to 80% capacity, and >=92% lowers them to 50% capacity. A debug.FreeOSMemory() pass is also run after cache pressure eviction.
  3. Adds begin/end logs for memory-cache and metadata-cache pressure eviction, including used-before, used-after, capacity, target, target-percent, duration, and context error, so we can tell whether eviction actually started and completed before an OOM.
  4. Disables full-file preload only on the PK conflict / tombstone PK check paths. Normal scan workloads keep their default full-file preload behavior.
  5. Moves PKPersistedBetween throttling earlier so the semaphore covers real metadata/BF/block/tombstone reads.
  6. Adds tests for target-based cache eviction, RSS cache-eviction triggering/escalation, and policy propagation for PK/tombstone reads.

Validation:

go test ./pkg/common/rscthrottler ./pkg/fileservice ./pkg/objectio -run 'TestMemThrottlerRSSCacheEvictionByRSSRate|TestMemThrottlerRSSCacheEvictionConcurrentEscalation|TestMemoryCacheEvictToCapacityPercent|TestNonExistent' -count=1
go test ./pkg/cnservice -run TestNonExistent -count=0
go test ./pkg/objectio/ioutil ./pkg/vm/engine/disttae ./pkg/common/rscthrottler -run 'TestLoadColumnsDataPropagatesPolicy|TestTombstonePKExistsInRangeSkipsFullFilePreloads|TestTombstonePKExistsInRange|TestMemThrottlerRSSCacheEvictionConcurrentEscalation|TestNonExistent' -count=1

Add RSS-triggered cache pressure eviction for CN memory and object metadata caches, and expand PK conflict check throttling to metadata, bloom filter, block, and tombstone reads.

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings May 22, 2026 06:20
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces CN resident set size (RSS) pressure under high-concurrency TPCC by enabling “evict-to-target” behavior for key memory caches, wiring cache eviction into RSS scavenging at high watermarks, and expanding the PK conflict-check semaphore scope to cover more of the I/O-heavy path.

Changes:

  • Add target-based eviction APIs for FileService memory caches and objectio metadata cache (evict down to a capacity percentage, even when already under cap).
  • Trigger cache eviction (soft/hard targets) from rscthrottler RSS scavenging and follow with freeOSMemory() to encourage RSS return.
  • Acquire the PK conflict I/O semaphore earlier in PKPersistedBetween to bound concurrent metadata/BF/block/tombstone reads; add unit tests for new behaviors.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/vm/engine/disttae/txn_table.go Move PK conflict I/O semaphore acquisition earlier to cover more of the PK check I/O path.
pkg/objectio/cache.go Add metadata cache eviction to a capacity-percentage target.
pkg/fileservice/mem_cache.go Add MemCache helpers to evict to a target and to a capacity-percentage target.
pkg/fileservice/mem_cache_test.go Add test coverage for capacity-percentage eviction across global memory caches.
pkg/fileservice/fscache/data_cache.go Extend DataCache interface with target-based eviction methods.
pkg/fileservice/fifocache/fifo.go Implement EvictToTargetWithWait/ForceEvictWithWait and expose Used/Capacity on FIFO cache.
pkg/fileservice/fifocache/data_cache.go Plumb new eviction APIs through the FIFO DataCache wrapper.
pkg/fileservice/disk_cache_test.go Update test stub to satisfy the extended DataCache interface.
pkg/fileservice/cache.go Add global EvictMemoryCachesToCapacityPercent for pressure-driven eviction.
pkg/common/rscthrottler/resource_throttler.go Add RSS watermark-driven cache eviction hook and option (WithRSSCacheEvictor).
pkg/common/rscthrottler/resource_throttler_test.go Add tests validating RSS-rate-based cache eviction triggering.
pkg/cnservice/server.go Wire CN mem throttler RSS cache-eviction hook to FileService + objectio caches.

Comment thread pkg/fileservice/fifocache/fifo.go Resolved
Keep cache pressure eviction throttling separate from OS scavenging so a soft cache target does not block later hard eviction under rising RSS.

Co-authored-by: Copilot <[email protected]>

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The RSS-triggered cache eviction, FIFO pressure-eviction path, and earlier PK conflict throttling all look sound. I did not find a blocking correctness or concurrency issue in the changed paths.

@fengttt fengttt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know this PR actually helps? Any measurement?

I am really happy that queueLock.Unlock is finally sane (a simple defer without making postEvict dangling out of lock). I am really disapointed we still need this queueLock at all -- why a cache replacement need a queue, or queueLock, is beyond me ...

@LeftHandCold

Copy link
Copy Markdown
Collaborator Author

Do we know this PR actually helps? Any measurement?

I am really happy that queueLock.Unlock is finally sane (a simple defer without making postEvict dangling out of lock). I am really disapointed we still need this queueLock at all -- why a cache replacement need a queue, or queueLock, is beyond me ...

What we do have is the failure evidence and targeted verification for the mechanisms this PR changes:

In the original TPCC OOM window, small PK-conflict reads could trigger full-file preload and turn ~40-50KiB entries into ~80-95MiB full-object reads. This PR disables full-file preload only for PK conflict / tombstone PK check reads; normal scan workloads keep the default policy.
In the later sysbench duplicate-insert OOM, RSS reached ~54.38GiB / 55GiB and RSSScavenge calculated cache-target-percent=50, but logs did not prove whether memory/meta cache eviction actually started or completed. This update now logs pressure-evict begin/end with used-before, used-after, capacity, target, target-percent, duration, and context error.
The RSS cache eviction thresholds were moved earlier: soft at 85% RSS to an 80% cache target, hard at 92% RSS to a 50% target. This should create headroom before the process is already at ~54GiB.
Unit tests cover soft/hard escalation, actual-used return from pressure eviction, and policy propagation for the scoped no-full-preload reads.
Expected perf impact is intentionally scoped: below 85% RSS there is no new cache eviction behavior; full-file preload remains enabled for normal scans / TPCH / SSB-style workloads. Under high RSS, we may sacrifice some cache hit rate to avoid OOM, which is the intended tradeoff.

I agree the cache queue/queueLock design is worth revisiting separately, but I would keep that out of this PR to avoid turning this OOM fix into a larger cache replacement refactor.

@mergify

mergify Bot commented May 23, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-05-23 13:52 UTC · Rule: release-4.0
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-05-23 13:53 UTC · at a081210d1e3a50bc36ec8ed1e5285024be8953cd · squash

This pull request spent 26 seconds in the queue, including 3 seconds running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working kind/enhancement kind/test-ci size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants