Skip to content

fix: keep cache pressure target under high RSS - #24543

Merged
2 commits merged into
matrixorigin:4.0-devfrom
LeftHandCold:fix/rss-cache-pressure-closed-loop
May 25, 2026
Merged

2 commits merged into
matrixorigin:4.0-devfrom
LeftHandCold:fix/rss-cache-pressure-closed-loop

Conversation

@LeftHandCold

Copy link
Copy Markdown
Collaborator

Summary

Fixes #24534.

This follows the post-#24542 OOM evidence from the 4.0-dev nightly run:

  • nightly-regression-dis-tp-cn-6t6mx was OOMKilled during sysbench update-index 1000.
  • The image already included fix: cap fileservice event logger during cache eviction #24542, and Pyroscope no longer showed fileservice.eventLogger.emit as the dominant heap owner.
  • RSS reached hard pressure while Workspace observed the pressure, but only the CNFlushS3 throttler had RSS cache eviction configured.
  • SHARED memory cache was evicted once, then refilled back near its cap before the next RSS sample.

Changes

  • Enable RSS scavenging/cache eviction on the default Workspace throttler, so hard RSS observed by workspace allocation paths can evict memory/meta caches to the hard target.
  • Add sticky pressure admission targets for fileservice memory cache and objectio metadata cache.
  • Keep stricter active targets from being loosened by later softer targets.
  • Skip memory/meta cache writes while a pressure target is active and the write would refill cache above that target.

Tests

  • GOCACHE=/private/tmp/matrixone-rss-cache-gocache go test ./pkg/fileservice -run 'TestMemoryCachePressureAdmission|TestMemoryCacheEvictToCapacityPercent'

Local broader package tests are blocked by existing environment dependencies:

  • go test ./pkg/objectio ... and go test ./pkg/cnservice ... fail during build because this machine is missing usearch.h and xxhash.h.
  • Full pkg/fileservice tests also hit sandbox networking restrictions in httptest listener setup.

Copilot AI review requested due to automatic review settings May 24, 2026 16:08
@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 addresses CN OOM risk under high RSS pressure by making cache eviction/admission enforcement more effective during RSS scavenging, so memory/meta caches don’t quickly refill back to near-cap after an eviction.

Changes:

  • Enable RSS scavenging + cache-family eviction for the default Workspace mem throttler (disttae engine).
  • Introduce “sticky” pressure admission targets (with TTL) for FileService memory cache and objectio meta cache, and skip cache writes that would exceed the active pressure target.
  • Add unit tests covering pressure-admission behavior and expiry for both caches.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pkg/vm/engine/disttae/engine.go Adds RSS cache-eviction hook to Workspace throttler and applies sticky cache pressure targets.
pkg/cnservice/server.go Extends RSS cache evictor to also set sticky cache pressure admission targets.
pkg/fileservice/mem_cache.go Adds memory-cache pressure target state and skips cache admission above active target.
pkg/fileservice/mem_cache_test.go Adds tests for memory-cache pressure admission skip + expiry.
pkg/objectio/cache.go Adds meta-cache pressure target state and skips meta cache admission above active target.
pkg/objectio/meta_test.go Adds tests for meta-cache pressure admission skip + expiry.

Comment thread pkg/cnservice/server.go Resolved
Comment thread pkg/vm/engine/disttae/engine.go Resolved
Comment thread pkg/fileservice/mem_cache.go Resolved
Comment thread pkg/cnservice/server.go Resolved

@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.

Reviewed from correctness, concurrency, cancellation, and regression angles.

The RSS pressure handling now closes the loop end-to-end: eviction and sticky admission targets are wired consistently for both CNFlushS3 and Workspace, the FIFO admission path accounts atomically under queueLock, and the added tests cover the key pressure-admission and timeout behaviors.

LGTM.

@ghost
ghost merged commit 58c90b8 into matrixorigin:4.0-dev May 25, 2026
23 of 24 checks passed
@LeftHandCold
LeftHandCold deleted the fix/rss-cache-pressure-closed-loop branch May 25, 2026 06:13
XuPeng-SH pushed a commit that referenced this pull request May 26, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue #24592

## What this PR does / why we need it:

This PR reverts the risky semantic changes from the previous
RSS-pressure fixes, then restores only the minimal cache-pressure
protection needed for high RSS:

1. Revert the prior cache/PK-path changes from #24535, #24542, and
#24543 as a clean baseline.
2. Keep the low-risk fileservice event logger cap and strip request
event logging from cache-capacity eviction before cache-data allocation.
3. Under RSS pressure, asynchronously evict fileservice memory cache and
objectio metadata cache to a bounded target.
4. Run CN memory-cache and metadata-cache pressure eviction concurrently
so one slow cache family cannot consume the shared pressure timeout and
skip the other.
5. Keep a short pressure admission target so memory/meta cache writes do
not immediately refill the just-evicted caches.
6. Do not change PK check concurrency behavior beyond reverting the
risky metadata/BF/tombstone scope expansion.
7. Do not change tombstone, metadata, or bloom-filter read policy.
8. Keep foreground cache allocation from consuming global async eviction
debt.
9. Add pressure logs and metrics for RSS trigger, cache eviction
duration, and admission skips.

The intended behavior is:

- Normal RSS: no cache throttling or PK-path behavior change.
- High RSS: background cache/meta eviction plus temporary
cache-admission suppression.
- Foreground reads/writes: no global PK semaphore expansion, no
tombstone policy change, no metadata/BF policy change.

## Test

```text
git diff --check
git diff --check base/4.0-dev...HEAD
GOCACHE=/private/tmp/mo-gocache go test ./pkg/fileservice/fifocache -run 'TestEvict|TestPostEvict|TestMemoryCache|TestCachePressure|TestEvictToTarget' -count=1
GOCACHE=/private/tmp/mo-gocache go test ./pkg/fileservice -run 'TestEventLogger|TestWithoutEventLogger|TestMemoryCache|TestDiskCacheReadEnsuresMemoryCacheCapacity' -count=1
GOCACHE=/private/tmp/mo-gocache go test ./pkg/objectio -run 'TestMetaCachePressure' -count=1
GOCACHE=/private/tmp/mo-gocache go test ./pkg/common/rscthrottler -run 'TestMemThrottlerRSS|TestAcquirePolicyForCNFlushS3|TestAcquirePolicyForDataBranch' -count=1
GOCACHE=/private/tmp/mo-gocache go test ./pkg/cnservice -run 'TestMakeRSSCacheEvictor|Test_InitServer|Test_tenant' -count=1
GOCACHE=/private/tmp/mo-gocache go test ./pkg/vm/engine/disttae -run 'TestTombstonePKExistsInRange|TestLinearSearchOffsetByValFactory' -count=1
GOCACHE=/private/tmp/mo-gocache go test ./pkg/vm/engine/disttae -run 'TestPKCheckSemaphore|TestTombstonePKExistsInRange' -count=1
```
mergify Bot pushed a commit that referenced this pull request May 27, 2026
This PR ports the final minimal RSS cache pressure protection from #24612 to `main`.

Background:

- #24535 tried to reduce CN RSS pressure under TPCC/sysbench, but it mixed cache pressure handling with broader PK, tombstone, metadata, and BF read-path behavior changes.
- #24542 added fileservice event logger capacity protection.
- #24543 kept cache pressure admission targets active under high RSS.
- #24612 reverted the risky mixed behavior on `4.0-dev` and restored only the smaller validated RSS cache pressure protection.

`main` does not contain the risky #24535/#24542/#24543 commits, so this PR does not cherry-pick those revert commits. It ports the final net behavior directly:

- cap fileservice event logger events;
- avoid carrying request event logs into cache capacity eviction;
- asynchronously trigger memory cache and metadata cache eviction under RSS pressure;
- keep a short pressure admission TTL to prevent immediate cache refill;
- keep foreground `EvictWithWait` from absorbing async eviction debt;
- add cache pressure trigger / eviction / admission-skip / eviction-duration metrics;
- run CN memory/meta cache family eviction concurrently with independent timeouts;
- add focused coverage for cache admission, target eviction, event logger caps, RSS soft/hard target escalation, and CN concurrent eviction.

One `main` port adjustment:

- `tryScavengeRSS` captures the evictor and `freeOSMemory` hook before launching the async goroutine, preserving behavior while avoiding a race-detector issue in tests that replace the package-level hook.

Validation:

```text
GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/fileservice/fifocache -run 'TestEvict|TestPostEvict|TestMemoryCache|TestCachePressure|TestEvictToTarget' -count=1
GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/fileservice -run 'TestEventLogger|TestWithoutEventLogger|TestMemoryCache|TestDiskCacheReadEnsuresMemoryCacheCapacity' -count=1
GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/objectio -run 'TestMetaCachePressure' -count=1
GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/common/rscthrottler -run 'TestMemThrottlerRSS|TestAcquirePolicyForCNFlushS3|TestAcquirePolicyForDataBranch' -count=1
GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/cnservice -run 'TestMakeRSSCacheEvictor|Test_InitServer|Test_tenant' -count=1
GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/util/metric/v2 -run TestNonExistent -count=0
GOCACHE=/private/tmp/mo-gocache-main go test -race ./pkg/common/rscthrottler -run 'TestMemThrottlerRSSCacheEviction' -count=10
GOCACHE=/private/tmp/mo-gocache-main go test -race ./pkg/cnservice -run 'TestMakeRSSCacheEvictor' -count=10
git diff --check base/main...HEAD
```

Approved by: @gouhongshen, @XuPeng-SH, @aptend
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#24615)

This PR ports the final minimal RSS cache pressure protection from matrixorigin#24612 to `main`.

Background:

- matrixorigin#24535 tried to reduce CN RSS pressure under TPCC/sysbench, but it mixed cache pressure handling with broader PK, tombstone, metadata, and BF read-path behavior changes.
- matrixorigin#24542 added fileservice event logger capacity protection.
- matrixorigin#24543 kept cache pressure admission targets active under high RSS.
- matrixorigin#24612 reverted the risky mixed behavior on `4.0-dev` and restored only the smaller validated RSS cache pressure protection.

`main` does not contain the risky matrixorigin#24535/matrixorigin#24542/matrixorigin#24543 commits, so this PR does not cherry-pick those revert commits. It ports the final net behavior directly:

- cap fileservice event logger events;
- avoid carrying request event logs into cache capacity eviction;
- asynchronously trigger memory cache and metadata cache eviction under RSS pressure;
- keep a short pressure admission TTL to prevent immediate cache refill;
- keep foreground `EvictWithWait` from absorbing async eviction debt;
- add cache pressure trigger / eviction / admission-skip / eviction-duration metrics;
- run CN memory/meta cache family eviction concurrently with independent timeouts;
- add focused coverage for cache admission, target eviction, event logger caps, RSS soft/hard target escalation, and CN concurrent eviction.

One `main` port adjustment:

- `tryScavengeRSS` captures the evictor and `freeOSMemory` hook before launching the async goroutine, preserving behavior while avoiding a race-detector issue in tests that replace the package-level hook.

Validation:

```text
GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/fileservice/fifocache -run 'TestEvict|TestPostEvict|TestMemoryCache|TestCachePressure|TestEvictToTarget' -count=1
GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/fileservice -run 'TestEventLogger|TestWithoutEventLogger|TestMemoryCache|TestDiskCacheReadEnsuresMemoryCacheCapacity' -count=1
GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/objectio -run 'TestMetaCachePressure' -count=1
GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/common/rscthrottler -run 'TestMemThrottlerRSS|TestAcquirePolicyForCNFlushS3|TestAcquirePolicyForDataBranch' -count=1
GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/cnservice -run 'TestMakeRSSCacheEvictor|Test_InitServer|Test_tenant' -count=1
GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/util/metric/v2 -run TestNonExistent -count=0
GOCACHE=/private/tmp/mo-gocache-main go test -race ./pkg/common/rscthrottler -run 'TestMemThrottlerRSSCacheEviction' -count=10
GOCACHE=/private/tmp/mo-gocache-main go test -race ./pkg/cnservice -run 'TestMakeRSSCacheEvictor' -count=10
git diff --check base/main...HEAD
```

Approved by: @gouhongshen, @XuPeng-SH, @aptend
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#24615)

This PR ports the final minimal RSS cache pressure protection from matrixorigin#24612 to `main`.

Background:

- matrixorigin#24535 tried to reduce CN RSS pressure under TPCC/sysbench, but it mixed cache pressure handling with broader PK, tombstone, metadata, and BF read-path behavior changes.
- matrixorigin#24542 added fileservice event logger capacity protection.
- matrixorigin#24543 kept cache pressure admission targets active under high RSS.
- matrixorigin#24612 reverted the risky mixed behavior on `4.0-dev` and restored only the smaller validated RSS cache pressure protection.

`main` does not contain the risky matrixorigin#24535/matrixorigin#24542/matrixorigin#24543 commits, so this PR does not cherry-pick those revert commits. It ports the final net behavior directly:

- cap fileservice event logger events;
- avoid carrying request event logs into cache capacity eviction;
- asynchronously trigger memory cache and metadata cache eviction under RSS pressure;
- keep a short pressure admission TTL to prevent immediate cache refill;
- keep foreground `EvictWithWait` from absorbing async eviction debt;
- add cache pressure trigger / eviction / admission-skip / eviction-duration metrics;
- run CN memory/meta cache family eviction concurrently with independent timeouts;
- add focused coverage for cache admission, target eviction, event logger caps, RSS soft/hard target escalation, and CN concurrent eviction.

One `main` port adjustment:

- `tryScavengeRSS` captures the evictor and `freeOSMemory` hook before launching the async goroutine, preserving behavior while avoiding a race-detector issue in tests that replace the package-level hook.

Validation:

```text
GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/fileservice/fifocache -run 'TestEvict|TestPostEvict|TestMemoryCache|TestCachePressure|TestEvictToTarget' -count=1
GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/fileservice -run 'TestEventLogger|TestWithoutEventLogger|TestMemoryCache|TestDiskCacheReadEnsuresMemoryCacheCapacity' -count=1
GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/objectio -run 'TestMetaCachePressure' -count=1
GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/common/rscthrottler -run 'TestMemThrottlerRSS|TestAcquirePolicyForCNFlushS3|TestAcquirePolicyForDataBranch' -count=1
GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/cnservice -run 'TestMakeRSSCacheEvictor|Test_InitServer|Test_tenant' -count=1
GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/util/metric/v2 -run TestNonExistent -count=0
GOCACHE=/private/tmp/mo-gocache-main go test -race ./pkg/common/rscthrottler -run 'TestMemThrottlerRSSCacheEviction' -count=10
GOCACHE=/private/tmp/mo-gocache-main go test -race ./pkg/cnservice -run 'TestMakeRSSCacheEvictor' -count=10
git diff --check base/main...HEAD
```

Approved by: @gouhongshen, @XuPeng-SH, @aptend
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#24615)

This PR ports the final minimal RSS cache pressure protection from matrixorigin#24612 to `main`.

Background:

- matrixorigin#24535 tried to reduce CN RSS pressure under TPCC/sysbench, but it mixed cache pressure handling with broader PK, tombstone, metadata, and BF read-path behavior changes.
- matrixorigin#24542 added fileservice event logger capacity protection.
- matrixorigin#24543 kept cache pressure admission targets active under high RSS.
- matrixorigin#24612 reverted the risky mixed behavior on `4.0-dev` and restored only the smaller validated RSS cache pressure protection.

`main` does not contain the risky matrixorigin#24535/matrixorigin#24542/matrixorigin#24543 commits, so this PR does not cherry-pick those revert commits. It ports the final net behavior directly:

- cap fileservice event logger events;
- avoid carrying request event logs into cache capacity eviction;
- asynchronously trigger memory cache and metadata cache eviction under RSS pressure;
- keep a short pressure admission TTL to prevent immediate cache refill;
- keep foreground `EvictWithWait` from absorbing async eviction debt;
- add cache pressure trigger / eviction / admission-skip / eviction-duration metrics;
- run CN memory/meta cache family eviction concurrently with independent timeouts;
- add focused coverage for cache admission, target eviction, event logger caps, RSS soft/hard target escalation, and CN concurrent eviction.

One `main` port adjustment:

- `tryScavengeRSS` captures the evictor and `freeOSMemory` hook before launching the async goroutine, preserving behavior while avoiding a race-detector issue in tests that replace the package-level hook.

Validation:

```text
GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/fileservice/fifocache -run 'TestEvict|TestPostEvict|TestMemoryCache|TestCachePressure|TestEvictToTarget' -count=1
GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/fileservice -run 'TestEventLogger|TestWithoutEventLogger|TestMemoryCache|TestDiskCacheReadEnsuresMemoryCacheCapacity' -count=1
GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/objectio -run 'TestMetaCachePressure' -count=1
GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/common/rscthrottler -run 'TestMemThrottlerRSS|TestAcquirePolicyForCNFlushS3|TestAcquirePolicyForDataBranch' -count=1
GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/cnservice -run 'TestMakeRSSCacheEvictor|Test_InitServer|Test_tenant' -count=1
GOCACHE=/private/tmp/mo-gocache-main go test ./pkg/util/metric/v2 -run TestNonExistent -count=0
GOCACHE=/private/tmp/mo-gocache-main go test -race ./pkg/common/rscthrottler -run 'TestMemThrottlerRSSCacheEviction' -count=10
GOCACHE=/private/tmp/mo-gocache-main go test -race ./pkg/cnservice -run 'TestMakeRSSCacheEvictor' -count=10
git diff --check base/main...HEAD
```

Approved by: @gouhongshen, @XuPeng-SH, @aptend
This pull request was closed.

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

size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants