summaryrefslogtreecommitdiff
path: root/src/redis-cli.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/redis-cli.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/redis-cli.c')
-rw-r--r--src/redis-cli.c35
1 files changed, 17 insertions, 18 deletions
diff --git a/src/redis-cli.c b/src/redis-cli.c
index fbd392d4b..8a06f22f0 100644
--- a/src/redis-cli.c
+++ b/src/redis-cli.c
@@ -168,10 +168,10 @@ int spectrum_palette_size;
/* Dict Helpers */
static uint64_t dictSdsHash(const void *key);
-static int dictSdsKeyCompare(void *privdata, const void *key1,
+static int dictSdsKeyCompare(dict *d, const void *key1,
const void *key2);
-static void dictSdsDestructor(void *privdata, void *val);
-static void dictListDestructor(void *privdata, void *val);
+static void dictSdsDestructor(dict *d, void *val);
+static void dictListDestructor(dict *d, void *val);
/* Cluster Manager Command Info */
typedef struct clusterManagerCommand {
@@ -454,11 +454,10 @@ static uint64_t dictSdsHash(const void *key) {
return dictGenHashFunction((unsigned char*)key, sdslen((char*)key));
}
-static int dictSdsKeyCompare(void *privdata, const void *key1,
- const void *key2)
+static int dictSdsKeyCompare(dict *d, const void *key1, const void *key2)
{
int l1,l2;
- DICT_NOTUSED(privdata);
+ UNUSED(d);
l1 = sdslen((sds)key1);
l2 = sdslen((sds)key2);
@@ -466,15 +465,15 @@ static int dictSdsKeyCompare(void *privdata, const void *key1,
return memcmp(key1, key2, l1) == 0;
}
-static void dictSdsDestructor(void *privdata, void *val)
+static void dictSdsDestructor(dict *d, void *val)
{
- DICT_NOTUSED(privdata);
+ UNUSED(d);
sdsfree(val);
}
-void dictListDestructor(void *privdata, void *val)
+void dictListDestructor(dict *d, void *val)
{
- DICT_NOTUSED(privdata);
+ UNUSED(d);
listRelease((list*)val);
}
@@ -3012,7 +3011,7 @@ static int clusterManagerGetAntiAffinityScore(clusterManagerNodeArray *ipnodes,
* replication of each other) */
for (i = 0; i < ip_count; i++) {
clusterManagerNodeArray *node_array = &(ipnodes[i]);
- dict *related = dictCreate(&clusterManagerDictType, NULL);
+ dict *related = dictCreate(&clusterManagerDictType);
char *ip = NULL;
for (j = 0; j < node_array->len; j++) {
clusterManagerNode *node = node_array->nodes[j];
@@ -4519,7 +4518,7 @@ cleanup:
* node addresses that cannot reach the unreachable node. */
static dict *clusterManagerGetLinkStatus(void) {
if (cluster_manager.nodes == NULL) return NULL;
- dict *status = dictCreate(&clusterManagerLinkDictType, NULL);
+ dict *status = dictCreate(&clusterManagerLinkDictType);
listIter li;
listNode *ln;
listRewind(cluster_manager.nodes, &li);
@@ -5282,7 +5281,7 @@ static int clusterManagerCheckCluster(int quiet) {
clusterManagerNode *n = ln->value;
if (n->migrating != NULL) {
if (open_slots == NULL)
- open_slots = dictCreate(&clusterManagerDictType, NULL);
+ open_slots = dictCreate(&clusterManagerDictType);
sds errstr = sdsempty();
errstr = sdscatprintf(errstr,
"[WARNING] Node %s:%d has slots in "
@@ -5300,7 +5299,7 @@ static int clusterManagerCheckCluster(int quiet) {
}
if (n->importing != NULL) {
if (open_slots == NULL)
- open_slots = dictCreate(&clusterManagerDictType, NULL);
+ open_slots = dictCreate(&clusterManagerDictType);
sds errstr = sdsempty();
errstr = sdscatprintf(errstr,
"[WARNING] Node %s:%d has slots in "
@@ -5361,7 +5360,7 @@ static int clusterManagerCheckCluster(int quiet) {
dictType dtype = clusterManagerDictType;
dtype.keyDestructor = dictSdsDestructor;
dtype.valDestructor = dictListDestructor;
- clusterManagerUncoveredSlots = dictCreate(&dtype, NULL);
+ clusterManagerUncoveredSlots = dictCreate(&dtype);
int fixed = clusterManagerFixSlotsCoverage(slots);
if (fixed > 0) result = 1;
}
@@ -7528,9 +7527,9 @@ static typeinfo* typeinfo_add(dict *types, char* name, typeinfo* type_template)
return info;
}
-void type_free(void* priv_data, void* val) {
+void type_free(dict *d, void* val) {
typeinfo *info = val;
- UNUSED(priv_data);
+ UNUSED(d);
if (info->biggest_key)
sdsfree(info->biggest_key);
sdsfree(info->name);
@@ -7656,7 +7655,7 @@ static void findBigKeys(int memkeys, unsigned memkeys_samples) {
typeinfo **types = NULL;
double pct;
- dict *types_dict = dictCreate(&typeinfoDictType, NULL);
+ dict *types_dict = dictCreate(&typeinfoDictType);
typeinfo_add(types_dict, "string", &type_string);
typeinfo_add(types_dict, "list", &type_list);
typeinfo_add(types_dict, "set", &type_set);