Improve objectComputeSize() with allocator fragmentaiton.
This commit improve MEMORY USAGE command to include internal fragmentation overheads of:
1. EMBSTR encoded strings
2. ziplist encoded zsets and hashes
3. List type nodes
@@ -803,7 +803,7 @@ size_t objectComputeSize(robj *key, robj *o, size_t sample_size, int dbid) {
} else if(o->encoding == OBJ_ENCODING_RAW) {
asize = sdsZmallocSize(o->ptr)+sizeof(*o);
} else if(o->encoding == OBJ_ENCODING_EMBSTR) {
- asize = sdslen(o->ptr)+2+sizeof(*o);
+ asize = zmalloc_size((void *)o);
} else {
serverPanic("Unknown string encoding");
}
@@ -813,12 +813,12 @@ size_t objectComputeSize(robj *key, robj *o, size_t sample_size, int dbid) {
quicklistNode *node = ql->head;
asize = sizeof(*o)+sizeof(quicklist);
do {
- elesize += sizeof(quicklistNode)+ziplistBlobLen(node->zl);
+ elesize += sizeof(quicklistNode)+zmalloc_size(node->zl);
samples++;
} while ((node = node->next) && samples < sample_size);
asize += (double)elesize/samples*ql->len;
} else if (o->encoding == OBJ_ENCODING_ZIPLIST) {
- asize = sizeof(*o)+ziplistBlobLen(o->ptr);
+ asize = sizeof(*o)+zmalloc_size(o->ptr);
} else {
serverPanic("Unknown list encoding");
}
@@ -835,14 +835,13 @@ size_t objectComputeSize(robj *key, robj *o, size_t sample_size, int dbid) {
dictReleaseIterator(di);
if (samples) asize += (double)elesize/samples*dictSize(d);
} else if (o->encoding == OBJ_ENCODING_INTSET) {
- intset *is = o->ptr;
- asize = sizeof(*o)+sizeof(*is)+(size_t)is->encoding*is->length;
+ asize = sizeof(*o)+zmalloc_size(o->ptr);
} else {
serverPanic("Unknown set encoding");
}
} else if (o->type == OBJ_ZSET) {
if (o->encoding == OBJ_ENCODING_ZIPLIST) {
- asize = sizeof(*o)+(ziplistBlobLen(o->ptr));
+ asize = sizeof(*o)+zmalloc_size(o->ptr);
} else if (o->encoding == OBJ_ENCODING_SKIPLIST) {
d = ((zset*)o->ptr)->dict;
zskiplist *zsl = ((zset*)o->ptr)->zsl;
@@ -862,7 +861,7 @@ size_t objectComputeSize(robj *key, robj *o, size_t sample_size, int dbid) {
}
} else if (o->type == OBJ_HASH) {
if (o->encoding == OBJ_ENCODING_ZIPLIST) {
- asize = sizeof(*o)+(ziplistBlobLen(o->ptr));
+ asize = sizeof(*o)+zmalloc_size(o->ptr);
} else if (o->encoding == OBJ_ENCODING_HT) {
d = o->ptr;
di = dictGetIterator(d);
