Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shrink dict when deleting dictEntry #12850

Merged
merged 14 commits into from
Jan 15, 2024
Merged
10 changes: 6 additions & 4 deletions src/dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
* between the number of elements and the buckets > dict_force_resize_ratio. */
static dictResizeEnable dict_can_resize = DICT_RESIZE_ENABLE;
static unsigned int dict_force_resize_ratio = 5;
static unsigned int dict_force_shrink_ratio = 10;
static unsigned int dict_force_shrink_ratio = 2;
oranagra marked this conversation as resolved.
Show resolved Hide resolved

/* -------------------------- types ----------------------------------------- */
struct dictEntry {
Expand Down Expand Up @@ -1432,9 +1432,11 @@ static int _dictShrinkIfNeeded(dict *d) {
/* Incremental rehashing already in progress. Return. */
if (dictIsRehashing(d)) return DICT_OK;

if (dict_can_resize == DICT_RESIZE_ENABLE &&
DICTHT_SIZE(d->ht_size_exp[0]) > DICT_HT_INITIAL_SIZE &&
(d->ht_used[0] * 100 / DICTHT_SIZE(d->ht_size_exp[0]) < dict_force_shrink_ratio))
if (DICTHT_SIZE(d->ht_size_exp[0]) > DICT_HT_INITIAL_SIZE &&
oranagra marked this conversation as resolved.
Show resolved Hide resolved
((dict_can_resize == DICT_RESIZE_ENABLE &&
oranagra marked this conversation as resolved.
Show resolved Hide resolved
d->ht_used[0] * 100 / DICTHT_SIZE(d->ht_size_exp[0]) < HASHTABLE_MIN_FILL) ||
(dict_can_resize != DICT_RESIZE_FORBID &&
d->ht_used[0] * 100 / DICTHT_SIZE(d->ht_size_exp[0]) < dict_force_shrink_ratio)))
{
if (!dictTypeExpandAllowed(d))
oranagra marked this conversation as resolved.
Show resolved Hide resolved
return DICT_OK;
Expand Down
3 changes: 3 additions & 0 deletions src/dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
#define DICT_OK 0
#define DICT_ERR 1

/* Hash table parameters */
#define HASHTABLE_MIN_FILL 10 /* Minimal hash table fill 10% */

typedef struct dictEntry dictEntry; /* opaque */
typedef struct dict dict;

Expand Down
1 change: 0 additions & 1 deletion src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ struct hdr_histogram;
extern int configOOMScoreAdjValuesDefaults[CONFIG_OOM_COUNT];

/* Hash table parameters */
#define HASHTABLE_MIN_FILL 10 /* Minimal hash table fill 10% */
#define HASHTABLE_MAX_LOAD_FACTOR 1.618 /* Maximum hash table load factor. */

/* Command flags. Please check the definition of struct redisCommand in this file
Expand Down