Repository navigation
Attribute LZ4 codec context memory to client memory usage - #4702
sarthakaggarwal97 merged 5 commits into
Conversation
The LZ4 frame contexts allocate through the custom zmalloc-backed allocator, so their memory is inside used_memory but attributed to nothing and lands in the used_memory_dataset residual. The contexts allocate internal staging buffers lazily, so the held memory cannot be derived from the context pointer alone. Track the usable bytes each context holds via the allocator's opaque state, pointing at a ctx_memory counter on the owning stream struct. Account it in getClientMemoryUsage: the per-replica compressor joins the existing replicaCompressionState accounting, and the replica-side push reader (decoder context plus retained wire buffer) is attributed to the primary client, since it exists for exactly that link. Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com>
|
No actionable comments were generated in the recent review. π βΉοΈ Recent review infoβοΈ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: π Files selected for processing (4)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. π WalkthroughWalkthroughThe change tracks memory held by LZ4 codec contexts and adds it to client memory usage. Tests verify allocation growth, stream round trips, and complete release. ChangesCodec Context Memory Accounting
Priority: β¬οΈ Low Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: Merge Risk: βͺ Minimal Β· up to The memory-accounting change has no identified merge-blocking risk. π₯ Pre-merge checks | β 4 | β 1β Failed checks (1 warning)
β Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Correction to my inline review: please disregard that comment. Rechecking the |
Codecov Reportβ
All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## unstable #4702 +/- ##
============================================
- Coverage 80.63% 80.54% -0.10%
============================================
Files 192 192
Lines 100803 100849 +46
============================================
- Hits 81284 81226 -58
- Misses 19519 19623 +104
π New features to boost your workflow:
|
|
@zuiderkwast / @hpatro it's a small change, if you can help take a look! |
00a8a19
into
valkey-io:unstable
Follow-up to #3853, addresses #3853 (comment). The LZ4 contexts go through the custom zmalloc allocator, so their memory is inside `used_memory` but not attributed to anything and shows up under `used_memory_dataset`. There are two of them: the per-replica `LZ4F_cctx` on the primary, and the stream reader on the replica (`LZ4F_dctx` plus a retained input buffer), which lives on the server struct so per-client accounting never sees it. `zmalloc_size(ctx)` doesn't work here. The context struct is ~200 bytes and the staging buffers it allocates lazily are ~80 KiB. So the allocator callbacks now count the bytes into a `ctx_memory` field on the owning stream, via `LZ4F_CustomMem.opaqueState`. `getClientMemoryUsage()` picks up the compressor context in the existing replica block, and charges the replica-side reader to the primary client, so it shows up in `mem_clients_normal` like other client memory. Added a unit test that checks the counter grows when the streaming buffers are allocated and drops back to zero on free. Signed-off-by: Sarthak Aggarwal <sarthagg@amazon.com> Backport-Source-PR: 4702
Follow-up to #3853, addresses #3853 (comment).
The LZ4 contexts go through the custom zmalloc allocator, so their memory is inside
used_memorybut not attributed to anything and shows up underused_memory_dataset. There are two of them: the per-replicaLZ4F_cctxon the primary, and the stream reader on the replica (LZ4F_dctxplus a retained input buffer), which lives on the server struct so per-client accounting never sees it.zmalloc_size(ctx)doesn't work here. The context struct is ~200 bytes and the staging buffers it allocates lazily are ~80 KiB. So the allocator callbacks now count the bytes into actx_memoryfield on the owning stream, viaLZ4F_CustomMem.opaqueState.getClientMemoryUsage()picks up the compressor context in the existing replica block, and charges the replica-side reader to the primary client, so it shows up inmem_clients_normallike other client memory.Added a unit test that checks the counter grows when the streaming buffers are allocated and drops back to zero on free.