summaryrefslogtreecommitdiff
path: root/src/zmalloc.c
diff options
context:
space:
mode:
authorOran Agra <oran@redislabs.com>2018-02-21 20:18:34 +0200
committerOran Agra <oran@redislabs.com>2018-07-16 16:43:42 +0300
commitbf680b6f8cdaee2c5588c5c8932a7f3b7fa70b15 (patch)
treebc0c6ef60ab8748cf1585406c4d27fb4e3083187 /src/zmalloc.c
parentab33bcd34640306cdf70fd4fda0af41d93c687bf (diff)
downloadredis-bf680b6f8cdaee2c5588c5c8932a7f3b7fa70b15.tar.gz
slave buffers were wasteful and incorrectly counted causing eviction
A) slave buffers didn't count internal fragmentation and sds unused space, this caused them to induce eviction although we didn't mean for it. B) slave buffers were consuming about twice the memory of what they actually needed. - this was mainly due to sdsMakeRoomFor growing to twice as much as needed each time but networking.c not storing more than 16k (partially fixed recently in 237a38737). - besides it wasn't able to store half of the new string into one buffer and the other half into the next (so the above mentioned fix helped mainly for small items). - lastly, the sds buffers had up to 30% internal fragmentation that was wasted, consumed but not used. C) inefficient performance due to starting from a small string and reallocing many times. what i changed: - creating dedicated buffers for reply list, counting their size with zmalloc_size - when creating a new reply node from, preallocate it to at least 16k. - when appending a new reply to the buffer, first fill all the unused space of the previous node before starting a new one. other changes: - expose mem_not_counted_for_evict info field for the benefit of the test suite - add a test to make sure slave buffers are counted correctly and that they don't cause eviction
Diffstat (limited to 'src/zmalloc.c')
-rw-r--r--src/zmalloc.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/zmalloc.c b/src/zmalloc.c
index 4956f905f..0d9917510 100644
--- a/src/zmalloc.c
+++ b/src/zmalloc.c
@@ -182,6 +182,9 @@ size_t zmalloc_size(void *ptr) {
if (size&(sizeof(long)-1)) size += sizeof(long)-(size&(sizeof(long)-1));
return size+PREFIX_SIZE;
}
+size_t zmalloc_usable(void *ptr) {
+ return zmalloc_usable(ptr)-PREFIX_SIZE;
+}
#endif
void zfree(void *ptr) {