experimental: Ring buffer reuse for leaked 160-byte objects#1
experimental: Ring buffer reuse for leaked 160-byte objects#1
Conversation
The pool-based approach on master cannot reclaim leaked objects because free() is never called (confirmed: free=0 in all tests). This branch uses a ring buffer instead: - After threshold (10GB), new malloc(160) calls recycle the oldest allocation in the ring - Most recent 1M allocations (~160MB) are preserved - Older allocations are overwritten and returned to new callers ⚠ EXPERIMENTAL — needs long-running session validation. Risk: if caller reads recycled memory, data corruption possible. Heap dump shows objects are 85% zeros and likely write-once, but this is unverified under sustained load. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
dalsoop
left a comment
There was a problem hiding this comment.
The main correctness risk I see is the interaction between the new ring and free().
In this branch, ring slots are never cleared or updated when a pointer is later freed by the caller. So if even a small fraction of these 160-byte allocations are eventually freed in real workloads, the ring can keep a stale pointer and later hand that freed allocation back out from malloc(160).
That means the safety argument here is stronger than just “maybe the caller still reads old allocations”. There is also a more direct possibility of reissuing memory that has already been returned to the allocator.
If you want to keep this approach experimental, I would at least make the ring aware of frees for tracked pointers before trusting long-running sessions. Otherwise the branch is assuming both:
- leaked objects are never read again
- and they are never freed later either
The first assumption is already risky; the second one is not enforced by the code.
|
리뷰 포인트 1개는 치명적이라 바로 남깁니다. 이 branch는 PR 설명에도 |
|
20일 묵은 experimental PR. long-running session test 미수행 + 위험 (data corruption 가능). 필요 시 재오픈. |
Summary
Replace the pool-based approach with a ring buffer that forcibly recycles old allocations.
Why
The current master branch pools freed 160-byte blocks for reuse. But testing confirmed
free()is never called for the leaked objects (free=0in all tests). This means the pool stays empty and memory keeps growing — Tier 1 is effectively a no-op for this leak.What this does
After threshold (10GB / ~60M allocations):
malloc(160)calls recycle the oldest allocation from a ring bufferRisk
If the caller still holds a reference to a recycled allocation and reads it, data corruption is possible.
Evidence that this is safe (but unproven):
What's needed to merge
reusecounter increases and no crashes/corruption occurHow to test
🤖 Generated with Claude Code