Fix MEMORY USAGE command#5
Fix MEMORY USAGE command#5tomerqodo wants to merge 2 commits intoaugment_full_base_fix_memory_usage_command_pr5from
Conversation
🤖 Augment PR SummarySummary: Fixes Changes:
Technical Notes: The estimator relies on allocator-reported allocation sizes and sampling to approximate nested container memory usage. 🤖 Was this summary useful? React with 👍 or 👎 |
| size_t elesize = 0, elecount = 0, samples = 0; | ||
|
|
||
| /* 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.
kvobjComputeSize uses malloc_usable_size(), which may not be available / may not match the allocator Redis is built with (e.g., jemalloc uses je_malloc_usable_size via zmalloc_*). This can break portability and/or make MEMORY USAGE inconsistent with zmalloc_size-based accounting used elsewhere.
🤖 Was this useful? React with 👍 or 👎
| 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.
In the quicklist branch, asize += (double)elesize/samples*ql->count appears to mix “per-node” averaging (/samples) with “total element count” scaling (*ql->count), which can massively mis-estimate list memory usage. It looks like this should be normalized consistently (e.g., per-element vs per-node) before scaling.
🤖 Was this useful? React with 👍 or 👎
| } else { | ||
| if (samples) lpsize /= samples; /* Compute the average. */ | ||
| asize += lpsize * (s->rax->numele-1); | ||
| asize += lpsize * s->rax->numele; |
There was a problem hiding this comment.
In the stream branch, asize += lpsize * s->rax->numele is followed by adding the actual size of the last listpack, which seems to double-count the last listpack (the old code used numele-1 before adding the last). This likely inflates MEMORY USAGE results for streams.
🤖 Was this useful? React with 👍 or 👎
Benchmark PR from agentic-review-benchmarks#5