Skip to content

perf(malloc): reduce mmap faults for large hash tables - #26143

Merged
XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
XuPeng-SH:perf/tpch-q18-mmap
Jul 24, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
XuPeng-SH:perf/tpch-q18-mmap

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

What type of PR is this?

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

Which issue(s) this PR fixes:

Fixes #26132

What this PR does / why we need it:

Corrected root cause

The original issue attributed Q18 to MARK join falling back to LoopJoin. Controlled plans and adjacent-commit A/B refute that attribution: canonical Q18 remains a SEMI hash join, and #25822 is neutral/slightly faster than its direct parent.

Further bisection identifies 7ffd26c7e1 from #25820 as the first bad commit. Besides its pipeline lifecycle changes, that commit moved all off-heap allocations at or above 128 KiB from libc to immediate mmap/munmap. Q18 builds a roughly 1 GiB, 15-million-row hash aggregate; repeated growth faults transient tables, and immediate unmap makes the final working set fault again on the next execution. Disabling only that mmap path restores the old timing, while the physical plan and scan cardinalities remain unchanged.

Changes

  1. Segment large Int64/String hash tables at 4 MiB instead of 256 MiB. Growth appends blocks and preserves existing mappings rather than allocating and faulting another full contiguous table. Load-factor decisions still use the total table size, preserving the original 1/2, 2/3, 3/4, and 4/5 thresholds.
  2. Add bounded exact-size reuse for Linux mmap allocations used by zeroing Allocate/ReallocZero:
    • freed pages are marked MADV_FREE, so the kernel can reclaim them under pressure;
    • retained virtual memory is bounded by min(global memory limit / 4, 1 GiB);
    • all cached mappings are actively munmaped after one second of inactivity;
    • Malloc does not reuse LazyFree pages because its no-clear contract cannot safely reactivate every page;
    • non-Linux platforms keep the existing immediate-unmap behavior;
    • cached bytes are exposed as mo_mem_offheap_inuse_bytes{type="mpool-cache"}.

Performance

Single-node launch, TPCH 10G Q18, same data and machine:

Version Wall time
current main before this change 0.67-0.70 s, median 0.68 s
segmented hash table only 0.55-0.58 s, median 0.57 s
final branch, after allocator cache idle 0.517 s
final branch, burst steady state 0.302-0.323 s, median 0.317 s
pre-regression 0d8111ae 0.47-0.50 s

A 10-query process-counter sample reduced minor faults from 5,826,419 to 1,361,708 and system CPU ticks from 6,484 to 997. The cache sample contained about 1.045 GiB of LazyFree pages; after two idle seconds LazyFree returned to zero and RSS fell from 2.65 GiB to 1.61 GiB.

Spot checks of Q1, Q6, Q9, Q13, Q17, and Q21 against the main baseline found no regression; all were neutral or faster.

Ownership / unhappy-path review

  • Mapping ownership has one linear path: mmap caller -> cache -> zeroing caller, or cache -> idle timer -> munmap.
  • Capacity rejection and failed madvise retain caller ownership and fall back to immediate munmap.
  • The cache mutex removes mappings before unmapping, so take/expiry cannot double-release.
  • Cache growth has both a hard byte bound and an idle recycle point.
  • Old timer callbacks check the current idle generation before releasing mappings.

Validation

.agents/skills/mo-dev/scripts/mo-cgo-test -race \
  -run TestSimpleCAllocatorMmapCache -count=20 -timeout=240s \
  ./pkg/common/malloc

.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=180s \
  ./pkg/common/malloc ./pkg/common/mpool ./pkg/container/hashtable \
  ./pkg/common/hashmap ./pkg/sql/colexec/group

.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=240s \
  ./pkg/common/malloc ./pkg/common/mpool ./pkg/container/hashtable \
  ./pkg/common/hashmap ./pkg/sql/colexec/group

make build
go vet ./pkg/common/malloc ./pkg/common/mpool ./pkg/container/hashtable \
  ./pkg/common/hashmap ./pkg/sql/colexec/group

All commands passed after rebasing onto current main.

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

@aptend aptend 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 the mmap-cache ownership/lifecycle paths and segmented hash-table growth. Relevant package tests, race checks, vet, formatting, and additional multi-block growth stress coverage passed. The current Ubuntu failure is the unrelated JSON-overlaps allocation-count flake also seen on PR #26147.

@XuPeng-SH
XuPeng-SH force-pushed the perf/tpch-q18-mmap branch from c16e72c to 6e812f4 Compare July 24, 2026 14:23
@matrix-meow matrix-meow added size/XL Denotes a PR that changes [1000, 1999] lines and removed size/L Denotes a PR that changes [500,999] lines labels Jul 24, 2026
@LeftHandCold
LeftHandCold self-requested a review July 24, 2026 14:57

@LeftHandCold LeftHandCold left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Deep-reviewed the complete diff at 6e812f4, including mmap/MADV_FREE ownership, timer generations, capacity and expiry bounds, allocation-failure atomicity, segmented Int64/String hash-table addressing and in-place rehash, serialization compatibility, and the upper hashmap/group call paths. I found no remaining actionable correctness, lifecycle, or normal-business regression issue.

Fresh local evidence: build and vet passed for all affected/dependent packages; full UT and full -race passed for malloc, mpool, hashtable, hashmap, and colexec/group; focused segmented-growth/failure-atomicity tests passed for 10 repetitions. The current Ubuntu job failure is logservicedriver.TestReplay1 rejecting LogShardID=0, outside the changed code paths.

@XuPeng-SH
XuPeng-SH merged commit 2c29244 into matrixorigin:main Jul 24, 2026
0 of 3 checks passed
@XuPeng-SH
XuPeng-SH deleted the perf/tpch-q18-mmap branch July 24, 2026 17:44
XuPeng-SH added a commit that referenced this pull request Jul 25, 2026
## What type of PR is this?

- [x] Improvement

## What this PR does / why we need it

Reduce contention in the shared shuffle pool without changing shuffle
backpressure or buffering limits:

- account only batches changed by each union instead of rescanning the
whole bucket
- shard batch memory tracking to remove the global accounting mutex
- shard recycled batches by the local holder bound, with two padded
embedded slots per shard
- keep recycle lookup O(1) independently of the global shuffle bucket
count
- let a cold holder shard warm once without allowing a previously hot
bucket to monopolize the cache

The recycle capacity remains exactly `2 * maxHolders`. Sharding follows
the local concurrency bound rather than `bucketNum`, which can grow as
stage nodes times DOP in multi-CN plans.

This is complementary to the allocator/mmap work in #26143 and is kept
separate so both changes can be reviewed, measured, and reverted
independently.

Related to #26132.
Follow-up to #26143.

## Which issue(s) this PR fixes

None. #26143 already owns the closing reference for #26132.

## Testing

- focused recycle/accounting/error-path stress under `-race -count=50`
- `go test -race ./pkg/sql/colexec/shuffle`
- `go test ./pkg/sql/colexec/shuffle ./pkg/sql/compile ./pkg/vm/pipeline
./pkg/vm`
- `go test -race ./pkg/vm/pipeline`
- `go build ./pkg/sql/colexec/shuffle`
- `go vet ./pkg/sql/colexec/shuffle`
- benchmark matrix covering 16/128/1024 buckets, fixed-worker
concurrency, single-CN, multi-CN, drain-all, round-robin, and phased
skew
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…26143)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes matrixorigin#26132

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

### Corrected root cause

The original issue attributed Q18 to MARK join falling back to LoopJoin.
Controlled plans and adjacent-commit A/B refute that attribution:
canonical Q18 remains a SEMI hash join, and matrixorigin#25822 is neutral/slightly
faster than its direct parent.

Further bisection identifies `7ffd26c7e1` from matrixorigin#25820 as the first bad
commit. Besides its pipeline lifecycle changes, that commit moved all
off-heap allocations at or above 128 KiB from libc to immediate
`mmap`/`munmap`. Q18 builds a roughly 1 GiB, 15-million-row hash
aggregate; repeated growth faults transient tables, and immediate unmap
makes the final working set fault again on the next execution. Disabling
only that mmap path restores the old timing, while the physical plan and
scan cardinalities remain unchanged.

### Changes

1. Segment large Int64/String hash tables at 4 MiB instead of 256 MiB.
Growth appends blocks and preserves existing mappings rather than
allocating and faulting another full contiguous table. Load-factor
decisions still use the total table size, preserving the original 1/2,
2/3, 3/4, and 4/5 thresholds.
2. Add bounded exact-size reuse for Linux mmap allocations used by
zeroing `Allocate`/`ReallocZero`:
- freed pages are marked `MADV_FREE`, so the kernel can reclaim them
under pressure;
- retained virtual memory is bounded by `min(global memory limit / 4, 1
GiB)`;
- all cached mappings are actively `munmap`ed after one second of
inactivity;
- `Malloc` does not reuse LazyFree pages because its no-clear contract
cannot safely reactivate every page;
   - non-Linux platforms keep the existing immediate-unmap behavior;
- cached bytes are exposed as
`mo_mem_offheap_inuse_bytes{type="mpool-cache"}`.

### Performance

Single-node launch, TPCH 10G Q18, same data and machine:

| Version | Wall time |
|---|---:|
| current main before this change | 0.67-0.70 s, median 0.68 s |
| segmented hash table only | 0.55-0.58 s, median 0.57 s |
| final branch, after allocator cache idle | 0.517 s |
| final branch, burst steady state | 0.302-0.323 s, median 0.317 s |
| pre-regression `0d8111ae` | 0.47-0.50 s |

A 10-query process-counter sample reduced minor faults from 5,826,419 to
1,361,708 and system CPU ticks from 6,484 to 997. The cache sample
contained about 1.045 GiB of `LazyFree` pages; after two idle seconds
`LazyFree` returned to zero and RSS fell from 2.65 GiB to 1.61 GiB.

Spot checks of Q1, Q6, Q9, Q13, Q17, and Q21 against the main baseline
found no regression; all were neutral or faster.

### Ownership / unhappy-path review

- Mapping ownership has one linear path: mmap caller -> cache -> zeroing
caller, or cache -> idle timer -> munmap.
- Capacity rejection and failed `madvise` retain caller ownership and
fall back to immediate munmap.
- The cache mutex removes mappings before unmapping, so take/expiry
cannot double-release.
- Cache growth has both a hard byte bound and an idle recycle point.
- Old timer callbacks check the current idle generation before releasing
mappings.

### Validation

```text
.agents/skills/mo-dev/scripts/mo-cgo-test -race \
  -run TestSimpleCAllocatorMmapCache -count=20 -timeout=240s \
  ./pkg/common/malloc

.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=180s \
  ./pkg/common/malloc ./pkg/common/mpool ./pkg/container/hashtable \
  ./pkg/common/hashmap ./pkg/sql/colexec/group

.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=240s \
  ./pkg/common/malloc ./pkg/common/mpool ./pkg/container/hashtable \
  ./pkg/common/hashmap ./pkg/sql/colexec/group

make build
go vet ./pkg/common/malloc ./pkg/common/mpool ./pkg/container/hashtable \
  ./pkg/common/hashmap ./pkg/sql/colexec/group
```

All commands passed after rebasing onto current main.
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

## What this PR does / why we need it

Reduce contention in the shared shuffle pool without changing shuffle
backpressure or buffering limits:

- account only batches changed by each union instead of rescanning the
whole bucket
- shard batch memory tracking to remove the global accounting mutex
- shard recycled batches by the local holder bound, with two padded
embedded slots per shard
- keep recycle lookup O(1) independently of the global shuffle bucket
count
- let a cold holder shard warm once without allowing a previously hot
bucket to monopolize the cache

The recycle capacity remains exactly `2 * maxHolders`. Sharding follows
the local concurrency bound rather than `bucketNum`, which can grow as
stage nodes times DOP in multi-CN plans.

This is complementary to the allocator/mmap work in matrixorigin#26143 and is kept
separate so both changes can be reviewed, measured, and reverted
independently.

Related to matrixorigin#26132.
Follow-up to matrixorigin#26143.

## Which issue(s) this PR fixes

None. matrixorigin#26143 already owns the closing reference for matrixorigin#26132.

## Testing

- focused recycle/accounting/error-path stress under `-race -count=50`
- `go test -race ./pkg/sql/colexec/shuffle`
- `go test ./pkg/sql/colexec/shuffle ./pkg/sql/compile ./pkg/vm/pipeline
./pkg/vm`
- `go test -race ./pkg/vm/pipeline`
- `go build ./pkg/sql/colexec/shuffle`
- `go vet ./pkg/sql/colexec/shuffle`
- benchmark matrix covering 16/128/1024 buckets, fixed-worker
concurrency, single-CN, multi-CN, drain-all, round-robin, and phased
skew
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…26143)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes matrixorigin#26132

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

### Corrected root cause

The original issue attributed Q18 to MARK join falling back to LoopJoin.
Controlled plans and adjacent-commit A/B refute that attribution:
canonical Q18 remains a SEMI hash join, and matrixorigin#25822 is neutral/slightly
faster than its direct parent.

Further bisection identifies `7ffd26c7e1` from matrixorigin#25820 as the first bad
commit. Besides its pipeline lifecycle changes, that commit moved all
off-heap allocations at or above 128 KiB from libc to immediate
`mmap`/`munmap`. Q18 builds a roughly 1 GiB, 15-million-row hash
aggregate; repeated growth faults transient tables, and immediate unmap
makes the final working set fault again on the next execution. Disabling
only that mmap path restores the old timing, while the physical plan and
scan cardinalities remain unchanged.

### Changes

1. Segment large Int64/String hash tables at 4 MiB instead of 256 MiB.
Growth appends blocks and preserves existing mappings rather than
allocating and faulting another full contiguous table. Load-factor
decisions still use the total table size, preserving the original 1/2,
2/3, 3/4, and 4/5 thresholds.
2. Add bounded exact-size reuse for Linux mmap allocations used by
zeroing `Allocate`/`ReallocZero`:
- freed pages are marked `MADV_FREE`, so the kernel can reclaim them
under pressure;
- retained virtual memory is bounded by `min(global memory limit / 4, 1
GiB)`;
- all cached mappings are actively `munmap`ed after one second of
inactivity;
- `Malloc` does not reuse LazyFree pages because its no-clear contract
cannot safely reactivate every page;
   - non-Linux platforms keep the existing immediate-unmap behavior;
- cached bytes are exposed as
`mo_mem_offheap_inuse_bytes{type="mpool-cache"}`.

### Performance

Single-node launch, TPCH 10G Q18, same data and machine:

| Version | Wall time |
|---|---:|
| current main before this change | 0.67-0.70 s, median 0.68 s |
| segmented hash table only | 0.55-0.58 s, median 0.57 s |
| final branch, after allocator cache idle | 0.517 s |
| final branch, burst steady state | 0.302-0.323 s, median 0.317 s |
| pre-regression `0d8111ae` | 0.47-0.50 s |

A 10-query process-counter sample reduced minor faults from 5,826,419 to
1,361,708 and system CPU ticks from 6,484 to 997. The cache sample
contained about 1.045 GiB of `LazyFree` pages; after two idle seconds
`LazyFree` returned to zero and RSS fell from 2.65 GiB to 1.61 GiB.

Spot checks of Q1, Q6, Q9, Q13, Q17, and Q21 against the main baseline
found no regression; all were neutral or faster.

### Ownership / unhappy-path review

- Mapping ownership has one linear path: mmap caller -> cache -> zeroing
caller, or cache -> idle timer -> munmap.
- Capacity rejection and failed `madvise` retain caller ownership and
fall back to immediate munmap.
- The cache mutex removes mappings before unmapping, so take/expiry
cannot double-release.
- Cache growth has both a hard byte bound and an idle recycle point.
- Old timer callbacks check the current idle generation before releasing
mappings.

### Validation

```text
.agents/skills/mo-dev/scripts/mo-cgo-test -race \
  -run TestSimpleCAllocatorMmapCache -count=20 -timeout=240s \
  ./pkg/common/malloc

.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=180s \
  ./pkg/common/malloc ./pkg/common/mpool ./pkg/container/hashtable \
  ./pkg/common/hashmap ./pkg/sql/colexec/group

.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=240s \
  ./pkg/common/malloc ./pkg/common/mpool ./pkg/container/hashtable \
  ./pkg/common/hashmap ./pkg/sql/colexec/group

make build
go vet ./pkg/common/malloc ./pkg/common/mpool ./pkg/container/hashtable \
  ./pkg/common/hashmap ./pkg/sql/colexec/group
```

All commands passed after rebasing onto current main.
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

## What this PR does / why we need it

Reduce contention in the shared shuffle pool without changing shuffle
backpressure or buffering limits:

- account only batches changed by each union instead of rescanning the
whole bucket
- shard batch memory tracking to remove the global accounting mutex
- shard recycled batches by the local holder bound, with two padded
embedded slots per shard
- keep recycle lookup O(1) independently of the global shuffle bucket
count
- let a cold holder shard warm once without allowing a previously hot
bucket to monopolize the cache

The recycle capacity remains exactly `2 * maxHolders`. Sharding follows
the local concurrency bound rather than `bucketNum`, which can grow as
stage nodes times DOP in multi-CN plans.

This is complementary to the allocator/mmap work in matrixorigin#26143 and is kept
separate so both changes can be reviewed, measured, and reverted
independently.

Related to matrixorigin#26132.
Follow-up to matrixorigin#26143.

## Which issue(s) this PR fixes

None. matrixorigin#26143 already owns the closing reference for matrixorigin#26132.

## Testing

- focused recycle/accounting/error-path stress under `-race -count=50`
- `go test -race ./pkg/sql/colexec/shuffle`
- `go test ./pkg/sql/colexec/shuffle ./pkg/sql/compile ./pkg/vm/pipeline
./pkg/vm`
- `go test -race ./pkg/vm/pipeline`
- `go build ./pkg/sql/colexec/shuffle`
- `go vet ./pkg/sql/colexec/shuffle`
- benchmark matrix covering 16/128/1024 buckets, fixed-worker
concurrency, single-CN, multi-CN, drain-all, round-robin, and phased
skew
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…26143)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes matrixorigin#26132

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

### Corrected root cause

The original issue attributed Q18 to MARK join falling back to LoopJoin.
Controlled plans and adjacent-commit A/B refute that attribution:
canonical Q18 remains a SEMI hash join, and matrixorigin#25822 is neutral/slightly
faster than its direct parent.

Further bisection identifies `7ffd26c7e1` from matrixorigin#25820 as the first bad
commit. Besides its pipeline lifecycle changes, that commit moved all
off-heap allocations at or above 128 KiB from libc to immediate
`mmap`/`munmap`. Q18 builds a roughly 1 GiB, 15-million-row hash
aggregate; repeated growth faults transient tables, and immediate unmap
makes the final working set fault again on the next execution. Disabling
only that mmap path restores the old timing, while the physical plan and
scan cardinalities remain unchanged.

### Changes

1. Segment large Int64/String hash tables at 4 MiB instead of 256 MiB.
Growth appends blocks and preserves existing mappings rather than
allocating and faulting another full contiguous table. Load-factor
decisions still use the total table size, preserving the original 1/2,
2/3, 3/4, and 4/5 thresholds.
2. Add bounded exact-size reuse for Linux mmap allocations used by
zeroing `Allocate`/`ReallocZero`:
- freed pages are marked `MADV_FREE`, so the kernel can reclaim them
under pressure;
- retained virtual memory is bounded by `min(global memory limit / 4, 1
GiB)`;
- all cached mappings are actively `munmap`ed after one second of
inactivity;
- `Malloc` does not reuse LazyFree pages because its no-clear contract
cannot safely reactivate every page;
   - non-Linux platforms keep the existing immediate-unmap behavior;
- cached bytes are exposed as
`mo_mem_offheap_inuse_bytes{type="mpool-cache"}`.

### Performance

Single-node launch, TPCH 10G Q18, same data and machine:

| Version | Wall time |
|---|---:|
| current main before this change | 0.67-0.70 s, median 0.68 s |
| segmented hash table only | 0.55-0.58 s, median 0.57 s |
| final branch, after allocator cache idle | 0.517 s |
| final branch, burst steady state | 0.302-0.323 s, median 0.317 s |
| pre-regression `0d8111ae` | 0.47-0.50 s |

A 10-query process-counter sample reduced minor faults from 5,826,419 to
1,361,708 and system CPU ticks from 6,484 to 997. The cache sample
contained about 1.045 GiB of `LazyFree` pages; after two idle seconds
`LazyFree` returned to zero and RSS fell from 2.65 GiB to 1.61 GiB.

Spot checks of Q1, Q6, Q9, Q13, Q17, and Q21 against the main baseline
found no regression; all were neutral or faster.

### Ownership / unhappy-path review

- Mapping ownership has one linear path: mmap caller -> cache -> zeroing
caller, or cache -> idle timer -> munmap.
- Capacity rejection and failed `madvise` retain caller ownership and
fall back to immediate munmap.
- The cache mutex removes mappings before unmapping, so take/expiry
cannot double-release.
- Cache growth has both a hard byte bound and an idle recycle point.
- Old timer callbacks check the current idle generation before releasing
mappings.

### Validation

```text
.agents/skills/mo-dev/scripts/mo-cgo-test -race \
  -run TestSimpleCAllocatorMmapCache -count=20 -timeout=240s \
  ./pkg/common/malloc

.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=180s \
  ./pkg/common/malloc ./pkg/common/mpool ./pkg/container/hashtable \
  ./pkg/common/hashmap ./pkg/sql/colexec/group

.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=240s \
  ./pkg/common/malloc ./pkg/common/mpool ./pkg/container/hashtable \
  ./pkg/common/hashmap ./pkg/sql/colexec/group

make build
go vet ./pkg/common/malloc ./pkg/common/mpool ./pkg/container/hashtable \
  ./pkg/common/hashmap ./pkg/sql/colexec/group
```

All commands passed after rebasing onto current main.
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

## What this PR does / why we need it

Reduce contention in the shared shuffle pool without changing shuffle
backpressure or buffering limits:

- account only batches changed by each union instead of rescanning the
whole bucket
- shard batch memory tracking to remove the global accounting mutex
- shard recycled batches by the local holder bound, with two padded
embedded slots per shard
- keep recycle lookup O(1) independently of the global shuffle bucket
count
- let a cold holder shard warm once without allowing a previously hot
bucket to monopolize the cache

The recycle capacity remains exactly `2 * maxHolders`. Sharding follows
the local concurrency bound rather than `bucketNum`, which can grow as
stage nodes times DOP in multi-CN plans.

This is complementary to the allocator/mmap work in matrixorigin#26143 and is kept
separate so both changes can be reviewed, measured, and reverted
independently.

Related to matrixorigin#26132.
Follow-up to matrixorigin#26143.

## Which issue(s) this PR fixes

None. matrixorigin#26143 already owns the closing reference for matrixorigin#26132.

## Testing

- focused recycle/accounting/error-path stress under `-race -count=50`
- `go test -race ./pkg/sql/colexec/shuffle`
- `go test ./pkg/sql/colexec/shuffle ./pkg/sql/compile ./pkg/vm/pipeline
./pkg/vm`
- `go test -race ./pkg/vm/pipeline`
- `go build ./pkg/sql/colexec/shuffle`
- `go vet ./pkg/sql/colexec/shuffle`
- benchmark matrix covering 16/128/1024 buckets, fixed-worker
concurrency, single-CN, multi-CN, drain-all, round-robin, and phased
skew

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/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: TPC-H Q18 单机退化 14x — PR #25822 (hash MARK join) 编译路径使用 loop join 而非 hash join

4 participants