Fix MEMORY USAGE command#27
Fix MEMORY USAGE command#27tomerqodo wants to merge 2 commits intocoderabbit_full_base_fix_memory_usage_command_pr5from
Conversation
WalkthroughThe changes rename and refactor a memory-size calculation function from Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/object.c (1)
1318-1336: Stream listpack estimate appears to double‑count the last node.
The comment says “average for first N‑1, then add last,” but Line 1331 multiplies bynumeleand then adds the last node again. Consider matching the comment to avoid systematic overcounting.🔧 Proposed fix
- asize += lpsize * s->rax->numele; + asize += lpsize * (s->rax->numele - 1);
🤖 Fix all issues with AI agents
In `@src/object.c`:
- Around line 1216-1218: Replace the non-portable call to malloc_usable_size
with the Redis allocator wrapper: change the line computing asize (size_t asize
= malloc_usable_size((void *)o);) to use zmalloc_usable_size((void *)o) (or the
appropriate zmalloc wrapper provided by your build) so the code uses Redis's
allocator API; update any includes if needed to ensure zmalloc_usable_size is
declared.
- Around line 1231-1239: The code computes average per-node size
(elesize/samples) but multiplies by ql->count (total elements) which
overestimates size; change the multiplier to ql->len (number of quicklist nodes)
and guard against division by zero. Locate the block using quicklist *ql,
quicklistNode *node, variables elesize/samples and replace asize +=
(double)elesize/samples*ql->count with asize += (samples>0)?
(double)elesize/samples*ql->len : 0 (or equivalent) so the scaling uses node
count (ql->len) and avoids divide-by-zero.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/object.ctests/unit/type/hash.tcltests/unit/type/list.tcltests/unit/type/string.tcl
🧰 Additional context used
🧬 Code graph analysis (1)
src/object.c (4)
src/networking.c (1)
sdsZmallocSize(43-46)src/zmalloc.c (1)
zmalloc_size(443-447)src/dict.c (1)
dictInitIterator(1129-1137)src/module.c (1)
moduleGetMemUsage(12160-12173)
🪛 GitHub Actions: External Server Tests
src/object.c
[error] 1217-1217: Implicit declaration of function 'malloc_usable_size'; did you mean 'zmalloc_usable_size'? [-Werror=implicit-function-declaration]
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: test-sanitizer-address
- GitHub Check: Analyze (cpp)
- GitHub Check: code-coverage
- GitHub Check: build-centos-jemalloc
- GitHub Check: test-sanitizer-address
- GitHub Check: code-coverage
🔇 Additional comments (4)
tests/unit/type/hash.tcl (1)
46-47: Coverage label update is clear.
No concerns.tests/unit/type/list.tcl (1)
2244-2245: LGTM – coverage probe is reasonable.tests/unit/type/string.tcl (1)
687-712: Nice coverage expansion for MEMORY USAGE.src/object.c (1)
1787-1788: LGTM – MEMORY USAGE now routes throughkvobjComputeSize.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
| /* All kv-objects has at least kvobj header and embedded key */ | ||
| size_t asize = malloc_usable_size((void *)o); | ||
|
|
There was a problem hiding this comment.
Build break: replace malloc_usable_size with Redis allocator wrapper.
Line 1217 fails the build (implicit declaration of function 'malloc_usable_size'). Use the zmalloc wrapper to keep portability.
🔧 Proposed fix
- size_t asize = malloc_usable_size((void *)o);
+ size_t asize = zmalloc_size((void *)o);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| /* All kv-objects has at least kvobj header and embedded key */ | |
| size_t asize = malloc_usable_size((void *)o); | |
| /* All kv-objects has at least kvobj header and embedded key */ | |
| size_t asize = zmalloc_size((void *)o); | |
🧰 Tools
🪛 GitHub Actions: External Server Tests
[error] 1217-1217: Implicit declaration of function 'malloc_usable_size'; did you mean 'zmalloc_usable_size'? [-Werror=implicit-function-declaration]
🤖 Prompt for AI Agents
In `@src/object.c` around lines 1216 - 1218, Replace the non-portable call to
malloc_usable_size with the Redis allocator wrapper: change the line computing
asize (size_t asize = malloc_usable_size((void *)o);) to use
zmalloc_usable_size((void *)o) (or the appropriate zmalloc wrapper provided by
your build) so the code uses Redis's allocator API; update any includes if
needed to ensure zmalloc_usable_size is declared.
| quicklist *ql = o->ptr; | ||
| quicklistNode *node = ql->head; | ||
| asize = sizeof(*o)+sizeof(quicklist); | ||
| asize += sizeof(quicklist); | ||
| do { | ||
| elesize += sizeof(quicklistNode)+zmalloc_size(node->entry); | ||
| elecount += node->count; | ||
| samples++; | ||
| } while ((node = node->next) && samples < sample_size); | ||
| asize += (double)elesize/elecount*ql->count; | ||
| asize += (double)elesize/samples*ql->count; |
There was a problem hiding this comment.
Quicklist size scaling should use node count, not element count.
Line 1239 samples per-node size but multiplies by ql->count (elements), which inflates MEMORY USAGE for long nodes. Use ql->len.
🔧 Proposed fix
- asize += (double)elesize/samples*ql->count;
+ asize += (double)elesize/samples*ql->len;🤖 Prompt for AI Agents
In `@src/object.c` around lines 1231 - 1239, The code computes average per-node
size (elesize/samples) but multiplies by ql->count (total elements) which
overestimates size; change the multiplier to ql->len (number of quicklist nodes)
and guard against division by zero. Locate the block using quicklist *ql,
quicklistNode *node, variables elesize/samples and replace asize +=
(double)elesize/samples*ql->count with asize += (samples>0)?
(double)elesize/samples*ql->len : 0 (or equivalent) so the scaling uses node
count (ql->len) and avoids divide-by-zero.
Benchmark PR from agentic-review-benchmarks#5
Summary by CodeRabbit
Tests
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.