From 12055ed8c295a0ba5f809efaf28147e2851c75e2 Mon Sep 17 00:00:00 2001 From: Oran Agra Date: Thu, 1 Oct 2020 11:30:22 +0300 Subject: [PATCH] Include internal sds fragmentation in MEMORY reporting (#7864) The MEMORY command is used for debugging memory usage, so it should include internal fragmentation, same as used_memory (cherry picked from commit eb6241a3dd3ee27610922e6bccd44603a9b845e8) --- src/object.c | 12 ++++++------ src/server.c | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/object.c b/src/object.c index 6caa71bb9..92eebb556 100644 --- a/src/object.c +++ b/src/object.c @@ -786,7 +786,7 @@ size_t objectComputeSize(robj *o, size_t sample_size) { if(o->encoding == OBJ_ENCODING_INT) { asize = sizeof(*o); } else if(o->encoding == OBJ_ENCODING_RAW) { - asize = sdsAllocSize(o->ptr)+sizeof(*o); + asize = sdsZmallocSize(o->ptr)+sizeof(*o); } else if(o->encoding == OBJ_ENCODING_EMBSTR) { asize = sdslen(o->ptr)+2+sizeof(*o); } else { @@ -814,7 +814,7 @@ size_t objectComputeSize(robj *o, size_t sample_size) { asize = sizeof(*o)+sizeof(dict)+(sizeof(struct dictEntry*)*dictSlots(d)); while((de = dictNext(di)) != NULL && samples < sample_size) { ele = dictGetKey(de); - elesize += sizeof(struct dictEntry) + sdsAllocSize(ele); + elesize += sizeof(struct dictEntry) + sdsZmallocSize(ele); samples++; } dictReleaseIterator(di); @@ -836,7 +836,7 @@ size_t objectComputeSize(robj *o, size_t sample_size) { (sizeof(struct dictEntry*)*dictSlots(d))+ zmalloc_size(zsl->header); while(znode != NULL && samples < sample_size) { - elesize += sdsAllocSize(znode->ele); + elesize += sdsZmallocSize(znode->ele); elesize += sizeof(struct dictEntry) + zmalloc_size(znode); samples++; znode = znode->level[0].forward; @@ -855,7 +855,7 @@ size_t objectComputeSize(robj *o, size_t sample_size) { while((de = dictNext(di)) != NULL && samples < sample_size) { ele = dictGetKey(de); ele2 = dictGetVal(de); - elesize += sdsAllocSize(ele) + sdsAllocSize(ele2); + elesize += sdsZmallocSize(ele) + sdsZmallocSize(ele2); elesize += sizeof(struct dictEntry); samples++; } @@ -995,7 +995,7 @@ struct redisMemOverhead *getMemoryOverheadData(void) { mem = 0; if (server.aof_state != AOF_OFF) { - mem += sdsalloc(server.aof_buf); + mem += sdsZmallocSize(server.aof_buf); mem += aofRewriteBufferSize(); } mh->aof_buffer = mem; @@ -1311,7 +1311,7 @@ NULL return; } size_t usage = objectComputeSize(dictGetVal(de),samples); - usage += sdsAllocSize(dictGetKey(de)); + usage += sdsZmallocSize(dictGetKey(de)); usage += sizeof(dictEntry); addReplyLongLong(c,usage); } else if (!strcasecmp(c->argv[1]->ptr,"stats") && c->argc == 2) { diff --git a/src/server.c b/src/server.c index 1f20efe94..cc9fe7d2f 100644 --- a/src/server.c +++ b/src/server.c @@ -1608,7 +1608,7 @@ int clientsCronTrackClientsMemUsage(client *c) { size_t mem = 0; int type = getClientType(c); mem += getClientOutputBufferMemoryUsage(c); - mem += sdsAllocSize(c->querybuf); + mem += sdsZmallocSize(c->querybuf); mem += sizeof(client); /* Now that we have the memory used by the client, remove the old * value from the old category, and add it back. */