Skip to content

fix(cn): react to cgroup memory pressure - #26471

Closed
gouhongshen wants to merge 1 commit into
matrixorigin:mainfrom
gouhongshen:codex/use-cgroup-memory-pressure
Closed

gouhongshen wants to merge 1 commit into
matrixorigin:mainfrom
gouhongshen:codex/use-cgroup-memory-pressure

Conversation

@gouhongshen

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG
  • Improvement

Which issue(s) this PR fixes:

Related to #26465

What this PR does / why we need it:

CN memory pressure handling currently samples process RSS only when the
resource throttler is used. This misses two parts of the actual OOM boundary:

  1. cgroup charges outside process RSS, including page cache and kernel slab;
  2. read-only workloads that do not acquire resources through the throttler and
    can therefore leave pressure state stale for tens of seconds.

The QA workload from #26465 exposed both gaps. A 36 GiB CN reached about
35.1 GiB cgroup working set while process RSS was still about 32.1 GiB. The
hard-pressure state was entered only seconds before the container was
OOM-killed. One affected CN currently has 4.4 GiB of cgroup slab alone, mainly
associated with 11,107,273 disk-cache files, which RSS cannot observe.

This PR:

  • reads the effective cgroup memory limit and usage as a matched pair from the
    tightest limiting cgroup ancestor (cgroup v1 and v2);
  • uses max(process RSS, cgroup usage) for cache pressure, available-memory
    calculation, and the CN S3 physical-memory backstop;
  • starts one stopper-managed, one-second CN pressure sampler so read-only
    workloads cannot leave the pressure state stale;
  • rate-limits routine refresh logs while retaining immediate pressure
    transition logs;
  • removes the now-unused automemlimit dependency.

Validation:

  • go test ./pkg/common/system ./pkg/common/rscthrottler ./pkg/cnservice -count=1
  • go test -race ./pkg/common/system ./pkg/common/rscthrottler ./pkg/cnservice -count=1
  • go vet ./pkg/common/system ./pkg/common/rscthrottler ./pkg/cnservice
  • cross-compiled pkg/common/system for Linux and ran it in an existing
    Alpine container with --memory 256m; the detector returned the exact
    268,435,456-byte limit and a non-zero usage below that limit.

The full MatrixOne container A/B is not included yet because the local builder
image cannot currently be fetched from Docker Hub (auth.docker.io TLS
failure). The component tests and real Linux cgroup test above pass; this PR is
kept as draft until full CI and workload validation complete.

@gouhongshen
gouhongshen force-pushed the codex/use-cgroup-memory-pressure branch from f3f9d17 to 007cf0b Compare July 31, 2026 02:38
XuPeng-SH pushed a commit that referenced this pull request Jul 31, 2026
## What type of PR is this?

- [x] Improvement

## Which issue(s) this PR fixes:

Related to #26465

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

After #26470 removed the per-object allocation, large table scans still
test
every visible tombstone object for every data block. The QA workload in
#26465
has system tables with roughly 700 visible tombstone objects and scans
roughly
132 data blocks per statement, resulting in about 92,000 object-level
Rowid
zone-map checks per scan.

This PR builds a per-data-source interval index from each tombstone
object's
Rowid zone-map block range:

- ranges are sorted by minimum block ID and carry a cumulative maximum;
- each data block queries only intervals that can contain its block ID;
- candidate objects are restored to the original visible-object order
before
the existing tombstone reader is called, preserving read and error
order;
- objects without an initialized Rowid zone map remain unconditional
  candidates because they cannot be safely excluded;
- scans below 32 blocks keep the existing allocation-free linear
iterator to
  avoid paying the index construction cost for small reads;
- the index and candidate scratch space are released when the data
source is
  closed.

The existing object/block zone-map checks remain in place. This changes
only
candidate selection, not tombstone visibility or deletion semantics.

Validation:

- `go test ./pkg/vm/engine/disttae -count=1`
- `go test -race ./pkg/vm/engine/disttae -run
'^TestTombstoneObjectIndex' -count=1`
- exhaustive equivalence test over 701 objects and 1,100 block IDs
- QA-shape benchmark (700 tombstone objects, 132 data blocks, 5
iterations):
  - linear scan: about 501 us/op
  - index build: about 72 us/op, 57,344 B/op, 1 alloc/op
  - indexed block queries: about 11.8 us/op, 0 B/op
  - build plus queries is about 6x faster than the linear scan

This is intentionally separate from the cgroup pressure handling in
#26471.
It reduces the work generated by the workload but does not claim to
solve all
sources of CN memory pressure by itself.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [x] Improvement

## Which issue(s) this PR fixes:

Related to matrixorigin#26465

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

After matrixorigin#26470 removed the per-object allocation, large table scans still
test
every visible tombstone object for every data block. The QA workload in
matrixorigin#26465
has system tables with roughly 700 visible tombstone objects and scans
roughly
132 data blocks per statement, resulting in about 92,000 object-level
Rowid
zone-map checks per scan.

This PR builds a per-data-source interval index from each tombstone
object's
Rowid zone-map block range:

- ranges are sorted by minimum block ID and carry a cumulative maximum;
- each data block queries only intervals that can contain its block ID;
- candidate objects are restored to the original visible-object order
before
the existing tombstone reader is called, preserving read and error
order;
- objects without an initialized Rowid zone map remain unconditional
  candidates because they cannot be safely excluded;
- scans below 32 blocks keep the existing allocation-free linear
iterator to
  avoid paying the index construction cost for small reads;
- the index and candidate scratch space are released when the data
source is
  closed.

The existing object/block zone-map checks remain in place. This changes
only
candidate selection, not tombstone visibility or deletion semantics.

Validation:

- `go test ./pkg/vm/engine/disttae -count=1`
- `go test -race ./pkg/vm/engine/disttae -run
'^TestTombstoneObjectIndex' -count=1`
- exhaustive equivalence test over 701 objects and 1,100 block IDs
- QA-shape benchmark (700 tombstone objects, 132 data blocks, 5
iterations):
  - linear scan: about 501 us/op
  - index build: about 72 us/op, 57,344 B/op, 1 alloc/op
  - indexed block queries: about 11.8 us/op, 0 B/op
  - build plus queries is about 6x faster than the linear scan

This is intentionally separate from the cgroup pressure handling in
matrixorigin#26471.
It reduces the work generated by the workload but does not claim to
solve all
sources of CN memory pressure by itself.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [x] Improvement

## Which issue(s) this PR fixes:

Related to matrixorigin#26465

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

After matrixorigin#26470 removed the per-object allocation, large table scans still
test
every visible tombstone object for every data block. The QA workload in
matrixorigin#26465
has system tables with roughly 700 visible tombstone objects and scans
roughly
132 data blocks per statement, resulting in about 92,000 object-level
Rowid
zone-map checks per scan.

This PR builds a per-data-source interval index from each tombstone
object's
Rowid zone-map block range:

- ranges are sorted by minimum block ID and carry a cumulative maximum;
- each data block queries only intervals that can contain its block ID;
- candidate objects are restored to the original visible-object order
before
the existing tombstone reader is called, preserving read and error
order;
- objects without an initialized Rowid zone map remain unconditional
  candidates because they cannot be safely excluded;
- scans below 32 blocks keep the existing allocation-free linear
iterator to
  avoid paying the index construction cost for small reads;
- the index and candidate scratch space are released when the data
source is
  closed.

The existing object/block zone-map checks remain in place. This changes
only
candidate selection, not tombstone visibility or deletion semantics.

Validation:

- `go test ./pkg/vm/engine/disttae -count=1`
- `go test -race ./pkg/vm/engine/disttae -run
'^TestTombstoneObjectIndex' -count=1`
- exhaustive equivalence test over 701 objects and 1,100 block IDs
- QA-shape benchmark (700 tombstone objects, 132 data blocks, 5
iterations):
  - linear scan: about 501 us/op
  - index build: about 72 us/op, 57,344 B/op, 1 alloc/op
  - indexed block queries: about 11.8 us/op, 0 B/op
  - build plus queries is about 6x faster than the linear scan

This is intentionally separate from the cgroup pressure handling in
matrixorigin#26471.
It reduces the work generated by the workload but does not claim to
solve all
sources of CN memory pressure by itself.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [x] Improvement

## Which issue(s) this PR fixes:

Related to matrixorigin#26465

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

After matrixorigin#26470 removed the per-object allocation, large table scans still
test
every visible tombstone object for every data block. The QA workload in
matrixorigin#26465
has system tables with roughly 700 visible tombstone objects and scans
roughly
132 data blocks per statement, resulting in about 92,000 object-level
Rowid
zone-map checks per scan.

This PR builds a per-data-source interval index from each tombstone
object's
Rowid zone-map block range:

- ranges are sorted by minimum block ID and carry a cumulative maximum;
- each data block queries only intervals that can contain its block ID;
- candidate objects are restored to the original visible-object order
before
the existing tombstone reader is called, preserving read and error
order;
- objects without an initialized Rowid zone map remain unconditional
  candidates because they cannot be safely excluded;
- scans below 32 blocks keep the existing allocation-free linear
iterator to
  avoid paying the index construction cost for small reads;
- the index and candidate scratch space are released when the data
source is
  closed.

The existing object/block zone-map checks remain in place. This changes
only
candidate selection, not tombstone visibility or deletion semantics.

Validation:

- `go test ./pkg/vm/engine/disttae -count=1`
- `go test -race ./pkg/vm/engine/disttae -run
'^TestTombstoneObjectIndex' -count=1`
- exhaustive equivalence test over 701 objects and 1,100 block IDs
- QA-shape benchmark (700 tombstone objects, 132 data blocks, 5
iterations):
  - linear scan: about 501 us/op
  - index build: about 72 us/op, 57,344 B/op, 1 alloc/op
  - indexed block queries: about 11.8 us/op, 0 B/op
  - build plus queries is about 6x faster than the linear scan

This is intentionally separate from the cgroup pressure handling in
matrixorigin#26471.
It reduces the work generated by the workload but does not claim to
solve all
sources of CN memory pressure by itself.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

This branch had an error being deployed

1 failed deployment
ci — 007cf0bf Deployed Jul 31, 2026 by gouhongshen via Matrixone Utils CI / Coverage #43701
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 size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants