summaryrefslogtreecommitdiff
path: root/src/defrag.c
diff options
context:
space:
mode:
authoryoav-steinberg <yoav@monfort.co.il>2021-08-05 08:25:58 +0300
committerGitHub <noreply@github.com>2021-08-05 08:25:58 +0300
commit5e908a290ccbe9c4a7bea9356faf3b837df62793 (patch)
treeee8c2008ef1c18653203245dd40d3befb2cd364f /src/defrag.c
parent1c59567a7fe207997eef6197eefa7d508d7fbf9f (diff)
downloadredis-5e908a290ccbe9c4a7bea9356faf3b837df62793.tar.gz
dict struct memory optimizations (#9228)
Reduce dict struct memory overhead on 64bit dict size goes down from jemalloc's 96 byte bin to its 56 byte bin. summary of changes: - Remove `privdata` from callbacks and dict creation. (this affects many files, see "Interface change" below). - Meld `dictht` struct into the `dict` struct to eliminate struct padding. (this affects just dict.c and defrag.c) - Eliminate the `sizemask` field, can be calculated from size when needed. - Convert the `size` field into `size_exp` (exponent), utilizes one byte instead of 8. Interface change: pass dict pointer to dict type call back functions. This is instead of passing the removed privdata field. In the future if we'd like to have private data in the callbacks we can extract it from the dict type. We can extend dictType to include a custom dict struct allocator and use it to allocate more data at the end of the dict struct. This data can then be used to store private data later acccessed by the callbacks.
Diffstat (limited to 'src/defrag.c')
-rw-r--r--src/defrag.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/defrag.c b/src/defrag.c
index 15230b5d2..5d18c9079 100644
--- a/src/defrag.c
+++ b/src/defrag.c
@@ -134,7 +134,6 @@ long dictIterDefragEntry(dictIterator *iter) {
* of the dict and it's iterator, but the benefit is that it is very easy
* to use, and require no other changes in the dict. */
long defragged = 0;
- dictht *ht;
/* Handle the next entry (if there is one), and update the pointer in the
* current entry. */
if (iter->nextEntry) {
@@ -146,12 +145,11 @@ long dictIterDefragEntry(dictIterator *iter) {
}
}
/* handle the case of the first entry in the hash bucket. */
- ht = &iter->d->ht[iter->table];
- if (ht->table[iter->index] == iter->entry) {
+ if (iter->d->ht_table[iter->table][iter->index] == iter->entry) {
dictEntry *newde = activeDefragAlloc(iter->entry);
if (newde) {
iter->entry = newde;
- ht->table[iter->index] = newde;
+ iter->d->ht_table[iter->table][iter->index] = newde;
defragged++;
}
}
@@ -165,14 +163,14 @@ long dictDefragTables(dict* d) {
dictEntry **newtable;
long defragged = 0;
/* handle the first hash table */
- newtable = activeDefragAlloc(d->ht[0].table);
+ newtable = activeDefragAlloc(d->ht_table[0]);
if (newtable)
- defragged++, d->ht[0].table = newtable;
+ defragged++, d->ht_table[0] = newtable;
/* handle the second hash table */
- if (d->ht[1].table) {
- newtable = activeDefragAlloc(d->ht[1].table);
+ if (d->ht_table[1]) {
+ newtable = activeDefragAlloc(d->ht_table[1]);
if (newtable)
- defragged++, d->ht[1].table = newtable;
+ defragged++, d->ht_table[1] = newtable;
}
return defragged;
}