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
This commit is contained in:
Oran Agra 2020-10-01 11:30:22 +03:00 committed by GitHub
parent dc803d25a6
commit eb6241a3dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View File

@ -787,7 +787,7 @@ size_t objectComputeSize(robj *o, size_t sample_size) {
if(o->encoding == OBJ_ENCODING_INT) { if(o->encoding == OBJ_ENCODING_INT) {
asize = sizeof(*o); asize = sizeof(*o);
} else if(o->encoding == OBJ_ENCODING_RAW) { } 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) { } else if(o->encoding == OBJ_ENCODING_EMBSTR) {
asize = sdslen(o->ptr)+2+sizeof(*o); asize = sdslen(o->ptr)+2+sizeof(*o);
} else { } else {
@ -815,7 +815,7 @@ size_t objectComputeSize(robj *o, size_t sample_size) {
asize = sizeof(*o)+sizeof(dict)+(sizeof(struct dictEntry*)*dictSlots(d)); asize = sizeof(*o)+sizeof(dict)+(sizeof(struct dictEntry*)*dictSlots(d));
while((de = dictNext(di)) != NULL && samples < sample_size) { while((de = dictNext(di)) != NULL && samples < sample_size) {
ele = dictGetKey(de); ele = dictGetKey(de);
elesize += sizeof(struct dictEntry) + sdsAllocSize(ele); elesize += sizeof(struct dictEntry) + sdsZmallocSize(ele);
samples++; samples++;
} }
dictReleaseIterator(di); dictReleaseIterator(di);
@ -837,7 +837,7 @@ size_t objectComputeSize(robj *o, size_t sample_size) {
(sizeof(struct dictEntry*)*dictSlots(d))+ (sizeof(struct dictEntry*)*dictSlots(d))+
zmalloc_size(zsl->header); zmalloc_size(zsl->header);
while(znode != NULL && samples < sample_size) { while(znode != NULL && samples < sample_size) {
elesize += sdsAllocSize(znode->ele); elesize += sdsZmallocSize(znode->ele);
elesize += sizeof(struct dictEntry) + zmalloc_size(znode); elesize += sizeof(struct dictEntry) + zmalloc_size(znode);
samples++; samples++;
znode = znode->level[0].forward; znode = znode->level[0].forward;
@ -856,7 +856,7 @@ size_t objectComputeSize(robj *o, size_t sample_size) {
while((de = dictNext(di)) != NULL && samples < sample_size) { while((de = dictNext(di)) != NULL && samples < sample_size) {
ele = dictGetKey(de); ele = dictGetKey(de);
ele2 = dictGetVal(de); ele2 = dictGetVal(de);
elesize += sdsAllocSize(ele) + sdsAllocSize(ele2); elesize += sdsZmallocSize(ele) + sdsZmallocSize(ele2);
elesize += sizeof(struct dictEntry); elesize += sizeof(struct dictEntry);
samples++; samples++;
} }
@ -996,7 +996,7 @@ struct redisMemOverhead *getMemoryOverheadData(void) {
mem = 0; mem = 0;
if (server.aof_state != AOF_OFF) { if (server.aof_state != AOF_OFF) {
mem += sdsalloc(server.aof_buf); mem += sdsZmallocSize(server.aof_buf);
mem += aofRewriteBufferSize(); mem += aofRewriteBufferSize();
} }
mh->aof_buffer = mem; mh->aof_buffer = mem;
@ -1312,7 +1312,7 @@ NULL
return; return;
} }
size_t usage = objectComputeSize(dictGetVal(de),samples); size_t usage = objectComputeSize(dictGetVal(de),samples);
usage += sdsAllocSize(dictGetKey(de)); usage += sdsZmallocSize(dictGetKey(de));
usage += sizeof(dictEntry); usage += sizeof(dictEntry);
addReplyLongLong(c,usage); addReplyLongLong(c,usage);
} else if (!strcasecmp(c->argv[1]->ptr,"stats") && c->argc == 2) { } else if (!strcasecmp(c->argv[1]->ptr,"stats") && c->argc == 2) {

View File

@ -1626,7 +1626,7 @@ int clientsCronTrackClientsMemUsage(client *c) {
size_t mem = 0; size_t mem = 0;
int type = getClientType(c); int type = getClientType(c);
mem += getClientOutputBufferMemoryUsage(c); mem += getClientOutputBufferMemoryUsage(c);
mem += sdsAllocSize(c->querybuf); mem += sdsZmallocSize(c->querybuf);
mem += sizeof(client); mem += sizeof(client);
/* Now that we have the memory used by the client, remove the old /* Now that we have the memory used by the client, remove the old
* value from the old category, and add it back. */ * value from the old category, and add it back. */