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)
This commit is contained in:
parent
c80f6219d5
commit
12055ed8c2
12
src/object.c
12
src/object.c
@ -786,7 +786,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 {
|
||||||
@ -814,7 +814,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);
|
||||||
@ -836,7 +836,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;
|
||||||
@ -855,7 +855,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++;
|
||||||
}
|
}
|
||||||
@ -995,7 +995,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;
|
||||||
@ -1311,7 +1311,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) {
|
||||||
|
@ -1608,7 +1608,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. */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user