Skip to content

fix(mpool): make on-heap ownership observable - #27497

Merged
XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
aunjgr:fix/mpool-onheap-observability-27404
Aug 23, 2026
Merged

XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
aunjgr:fix/mpool-onheap-observability-27404

Conversation

@aunjgr

@aunjgr aunjgr commented Aug 23, 2026 •

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 #27404

What this PR does / why we need it:

Keep the strong pointer registry and make its explicit-Free ownership contract observable instead of relying on GC semantics that the registry intentionally prevents.

  • Account successful on-heap MPool allocations globally by live bytes, live objects, and high-water mark without changing off-heap admission or resource accounting.
  • Export live-byte and live-object Prometheus gauges, and include per-pool outstanding ownership plus optional allocation/free call sites in diagnostics.
  • Warn when a normal pool is deleted with outstanding on-heap ownership while preserving metadata for a valid late Free. Treat NoLock pool deletion as its terminal bulk-release boundary.
  • Document that every successful non-empty allocation must reach Free, except for NoLock allocations released by pool teardown.
  • Fix the test-only missing cleanup sites surfaced by the ownership audit.

The hot path keeps only bounded global atomic accounting. Per-pool diagnostics scan the authoritative sharded registry at report/delete boundaries, avoiding per-allocation labels or unbounded diagnostic state. The added benchmark shows no allocation-count regression (one allocation per on-heap Alloc/Free cycle); exact-main comparisons showed roughly 7% median overhead for normal-pool 64 B and 1 KiB cycles, with noisier NoLock/large-object results.

Validation:

  • full pkg/common/mpool, pkg/util/metric/v2, pkg/util/metric/mometric, and pkg/frontend tests
  • focused lifecycle, failed-allocation, cross-pool, double-free, and concurrent on/off-heap tests
  • race stress (100 repetitions) for lifecycle/teardown/concurrent accounting and metric refresh
  • full race tests for pkg/common/mpool and pkg/util/metric/mometric
  • build and vet for affected packages
  • high-risk ownership audit across vector, batch, reuse, publication, and frontend; no remaining outstanding-on-heap warnings

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

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

Deep-reviewed exact head 476a5f5f766c78f54f115254747887431e3c7580. The normal-pool, NoLock teardown, late/cross-pool Free, global ownership counters, per-pool diagnostics, and metric publication paths close consistently. Local race/lifecycle stress and the focused frontend cleanup tests passed; I found no blocking correctness or lifecycle issue.

@XuPeng-SH
XuPeng-SH merged commit 8b5b16c into matrixorigin:main Aug 23, 2026
15 of 18 checks passed
@mergify mergify Bot removed the dequeued label Aug 23, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes matrixorigin#27404

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

Keep the strong pointer registry and make its explicit-Free ownership
contract observable instead of relying on GC semantics that the registry
intentionally prevents.

- Account successful on-heap MPool allocations globally by live bytes,
live objects, and high-water mark without changing off-heap admission or
resource accounting.
- Export live-byte and live-object Prometheus gauges, and include
per-pool outstanding ownership plus optional allocation/free call sites
in diagnostics.
- Warn when a normal pool is deleted with outstanding on-heap ownership
while preserving metadata for a valid late Free. Treat NoLock pool
deletion as its terminal bulk-release boundary.
- Document that every successful non-empty allocation must reach Free,
except for NoLock allocations released by pool teardown.
- Fix the test-only missing cleanup sites surfaced by the ownership
audit.

The hot path keeps only bounded global atomic accounting. Per-pool
diagnostics scan the authoritative sharded registry at report/delete
boundaries, avoiding per-allocation labels or unbounded diagnostic
state. The added benchmark shows no allocation-count regression (one
allocation per on-heap Alloc/Free cycle); exact-main comparisons showed
roughly 7% median overhead for normal-pool 64 B and 1 KiB cycles, with
noisier NoLock/large-object results.

Validation:

- full pkg/common/mpool, pkg/util/metric/v2, pkg/util/metric/mometric,
and pkg/frontend tests
- focused lifecycle, failed-allocation, cross-pool, double-free, and
concurrent on/off-heap tests
- race stress (100 repetitions) for lifecycle/teardown/concurrent
accounting and metric refresh
- full race tests for pkg/common/mpool and pkg/util/metric/mometric
- build and vet for affected packages
- high-risk ownership audit across vector, batch, reuse, publication,
and frontend; no remaining outstanding-on-heap warnings

---------

Co-authored-by: XuPeng-SH <[email protected]>
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?

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

## Which issue(s) this PR fixes:

Fixes matrixorigin#27404

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

Keep the strong pointer registry and make its explicit-Free ownership
contract observable instead of relying on GC semantics that the registry
intentionally prevents.

- Account successful on-heap MPool allocations globally by live bytes,
live objects, and high-water mark without changing off-heap admission or
resource accounting.
- Export live-byte and live-object Prometheus gauges, and include
per-pool outstanding ownership plus optional allocation/free call sites
in diagnostics.
- Warn when a normal pool is deleted with outstanding on-heap ownership
while preserving metadata for a valid late Free. Treat NoLock pool
deletion as its terminal bulk-release boundary.
- Document that every successful non-empty allocation must reach Free,
except for NoLock allocations released by pool teardown.
- Fix the test-only missing cleanup sites surfaced by the ownership
audit.

The hot path keeps only bounded global atomic accounting. Per-pool
diagnostics scan the authoritative sharded registry at report/delete
boundaries, avoiding per-allocation labels or unbounded diagnostic
state. The added benchmark shows no allocation-count regression (one
allocation per on-heap Alloc/Free cycle); exact-main comparisons showed
roughly 7% median overhead for normal-pool 64 B and 1 KiB cycles, with
noisier NoLock/large-object results.

Validation:

- full pkg/common/mpool, pkg/util/metric/v2, pkg/util/metric/mometric,
and pkg/frontend tests
- focused lifecycle, failed-allocation, cross-pool, double-free, and
concurrent on/off-heap tests
- race stress (100 repetitions) for lifecycle/teardown/concurrent
accounting and metric refresh
- full race tests for pkg/common/mpool and pkg/util/metric/mometric
- build and vet for affected packages
- high-risk ownership audit across vector, batch, reuse, publication,
and frontend; no remaining outstanding-on-heap warnings

---------

Co-authored-by: XuPeng-SH <[email protected]>
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?

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

## Which issue(s) this PR fixes:

Fixes matrixorigin#27404

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

Keep the strong pointer registry and make its explicit-Free ownership
contract observable instead of relying on GC semantics that the registry
intentionally prevents.

- Account successful on-heap MPool allocations globally by live bytes,
live objects, and high-water mark without changing off-heap admission or
resource accounting.
- Export live-byte and live-object Prometheus gauges, and include
per-pool outstanding ownership plus optional allocation/free call sites
in diagnostics.
- Warn when a normal pool is deleted with outstanding on-heap ownership
while preserving metadata for a valid late Free. Treat NoLock pool
deletion as its terminal bulk-release boundary.
- Document that every successful non-empty allocation must reach Free,
except for NoLock allocations released by pool teardown.
- Fix the test-only missing cleanup sites surfaced by the ownership
audit.

The hot path keeps only bounded global atomic accounting. Per-pool
diagnostics scan the authoritative sharded registry at report/delete
boundaries, avoiding per-allocation labels or unbounded diagnostic
state. The added benchmark shows no allocation-count regression (one
allocation per on-heap Alloc/Free cycle); exact-main comparisons showed
roughly 7% median overhead for normal-pool 64 B and 1 KiB cycles, with
noisier NoLock/large-object results.

Validation:

- full pkg/common/mpool, pkg/util/metric/v2, pkg/util/metric/mometric,
and pkg/frontend tests
- focused lifecycle, failed-allocation, cross-pool, double-free, and
concurrent on/off-heap tests
- race stress (100 repetitions) for lifecycle/teardown/concurrent
accounting and metric refresh
- full race tests for pkg/common/mpool and pkg/util/metric/mometric
- build and vet for affected packages
- high-risk ownership audit across vector, batch, reuse, publication,
and frontend; no remaining outstanding-on-heap warnings

---------

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

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/test-ci size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: mpool records on-heap allocations in globalPtrShards, making every missed Free() permanently unreclaimable (behaviour change since #23293)

3 participants