Isolate I/O thread written client fields on a dedicated cache line#4176
Isolate I/O thread written client fields on a dedicated cache line#4176abokhalill wants to merge 3 commits into
Conversation
The reply append path explicitly supports appending while an I/O thread streams the same client (io_write_state guards in _addReplyProtoToList), so during every in-flight write job the main thread updates net_output_bytes_curr_cmd while the owning I/O thread updates io_tracked_reply_len, nwritten and io_write_state a few bytes away on the same cache lines. Group every I/O-thread-written field on one _Alignas(CACHE_LINE_SIZE) line of its own, in the same spirit as valkey-io#1179 did for used_memory_thread, and allocate clients cache line aligned so the alignment holds. Costs 64 bytes per client (576 -> 640). Signed-off-by: Yousef Ahmed <yosefkhalil610@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe ChangesClient cache alignment
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/server.h`:
- Around line 1379-1395: Update the client allocations in the networking unit
tests at the referenced construction sites to use
zmalloc_cache_aligned(sizeof(client)) instead of zmalloc/zcalloc. Ensure every
allocation of client objects is cache-line aligned to satisfy the
_Alignas(CACHE_LINE_SIZE) fields in the client definition, while preserving
existing initialization behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 298c617d-649d-4c4a-ac15-36bc3bb5407a
📒 Files selected for processing (2)
src/networking.csrc/server.h
client now carries _Alignas(CACHE_LINE_SIZE) fields, so the plain zmalloc/zcalloc in the networking unit tests under-align it. Route all test client allocations through one aligned, zeroing helper. Signed-off-by: Yousef Ahmed <yosefkhalil610@gmail.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/unit/test_networking.cpp`:
- Around line 140-146: Separate allocation from initialization in
src/unit/test_networking.cpp: rename the cache-aligned helper at lines 140-146
to a distinct allocator symbol, then update the initializing createTestClient()
at lines 536-537 to call that allocator instead of recursively calling itself;
preserve the existing client initialization behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 426fa410-93f0-4eb2-9d46-7384e995a6a3
📒 Files selected for processing (1)
src/unit/test_networking.cpp
The aligned allocation helper collided with the existing initializing createTestClient() and rewrote its allocation into a self-call. Name the raw allocator allocTestClient() and have createTestClient() and the previously raw allocation sites use it. Signed-off-by: Yousef Ahmed <yosefkhalil610@gmail.com>
|
hey @madolson, would appreciate you taking a look at this once you have a cycle |
The reply append path explicitly supports appending while an I/O thread streams the same client, so during every in flight write job, the main thread updates
net_output_bytes_curr_cmdwhile the owning I/O thread updatesio_tracked_reply_len,nwrittenandio_write_statea few bytes away on the same cache lines. Group every I/O thread written field on one_Alignas(CACHE_LINE_SIZE) line of its own, in the same spirit as #1179 did forused_memory_thread.Signed off by: Yousef Ahmed yosefkhalil610@gmail.com