moonchen opened a new pull request, #13218:
URL: https://github.com/apache/trafficserver/pull/13218
## Problem
With `ENABLE_ALLOCATOR_METRICS=ON`, `proxy.process.allocator.inuse.hdrHeap`
and `proxy.process.allocator.inuse.hdrStrHeap` go deeply negative —
observed wrapping around as a huge `uint64` value (displayed ~ -5.8e10).
Every other allocator's `inuse` stays sane.
## Root cause
`hdrHeapAllocator` and `strHeapAllocator` are plain `Allocator` globals,
and their objects are allocated with **no constructor arguments**
(`THREAD_ALLOC(hdrHeapAllocator, this_ethread())`, then a manual
`init()`/placement-new). With no extra args, `THREAD_ALLOC` resolves to
the **non-templated** overload
`thread_alloc(Allocator &, ProxyAllocator &)` in `ProxyAllocator.cc`
rather than the templated `thread_alloc(CAlloc &, ProxyAllocator &, Args
&&...)`
in `ProxyAllocator.h`.
The two overloads diverged:
- The **templated** overload (used by every `ClassAllocator<>` allocator —
IO buffers, sessions, etc.) calls `a.increment_for_alloc()` when it
reuses an object from the per-thread freelist.
- The **non-templated** overload did **not**.
Meanwhile `THREAD_FREE` always decrements `inuse` (`UPDATE_FREE_METRICS`)
when an object is pushed onto the freelist. So for these two allocators,
every reuse-from-freelist decremented `inuse` with no matching increment,
and the counter marched negative until it wrapped. Only `hdrHeap` and
`hdrStrHeap` hit the non-templated overload, which is why only they
underflowed.
## Fix
Add the missing `increment_for_alloc()` to the freelist-reuse path of the
non-templated `thread_alloc`, mirroring the templated overload, so the two
paths stay symmetric. Guarded by `TS_USE_ALLOCATOR_METRICS`.
## Test
Added a regression test in `test_HdrHeap.cc` (guarded by
`TS_USE_ALLOCATOR_METRICS`) that enables the per-thread freelist and cycles
a single `hdrHeap`/`hdrStrHeap` block through free→reuse 1000 times,
asserting `inuse` returns to baseline+1 and never dips below the starting
value.
Before the fix the test fails as `inuse` reaches `-999`/`-1000`
(reproducing the underflow); after the fix it passes. The full
`test_proxy_hdrs` suite is green.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]