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

Add hashtable-on-dram option #198

Open
wants to merge 1 commit into
base: memkeydb-3.2.12
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions redis.conf
Original file line number Diff line number Diff line change
Expand Up @@ -1122,3 +1122,6 @@ dynamic-threshold-max 10000

# DRAM/PMEM ratio period measured in miliseconds
memory-ratio-check-period 100

# Keep hashtable structure always on DRAM
hashtable-on-dram yes
6 changes: 6 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ void loadServerConfigFromString(char *config) {
if (server.ratio_check_period < 1) {
err = "Invalid number of memory ratio check period"; goto loaderr;
}
} else if (!strcasecmp(argv[0],"hashtable-on-dram") && argc == 2) {
if ((server.hashtable_on_dram = yesnotoi(argv[1])) == -1) {
err = "argument must be 'yes' or 'no'"; goto loaderr;
}
} else if (!strcasecmp(argv[0],"maxmemory") && argc == 2) {
server.maxmemory = memtoll(argv[1],NULL);
} else if (!strcasecmp(argv[0],"maxmemory-policy") && argc == 2) {
Expand Down Expand Up @@ -1210,6 +1214,8 @@ void configGetCommand(client *c) {
server.aof_rewrite_incremental_fsync);
config_get_bool_field("aof-load-truncated",
server.aof_load_truncated);
config_get_bool_field("hashtable-on-dram",
server.hashtable_on_dram);

/* Enum values */
config_get_enum_field("maxmemory-policy",
Expand Down
11 changes: 8 additions & 3 deletions src/dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
* the number of elements and the buckets > dict_force_resize_ratio. */
static int dict_can_resize = 1;
static unsigned int dict_force_resize_ratio = 5;
static int dict_always_on_dram = 1;

/* -------------------------- private prototypes ---------------------------- */

Expand Down Expand Up @@ -89,6 +90,10 @@ uint32_t dictGetHashFunctionSeed(void) {
return dict_hash_function_seed;
}

void dictSetAllocPolicy(int policy) {
dict_always_on_dram = policy;
}

/* MurmurHash2, by Austin Appleby
* Note - This code makes a few assumptions about how your machine behaves -
* 1. We can read a 4-byte value from any address without crashing
Expand Down Expand Up @@ -217,7 +222,7 @@ int dictExpand(dict *d, unsigned long size)
/* Allocate the new hash table and initialize all pointers to NULL */
n.size = realsize;
n.sizemask = realsize-1;
n.table = zcalloc_dram(realsize*sizeof(dictEntry*));
n.table = (dict_always_on_dram) ? zcalloc_dram(realsize*sizeof(dictEntry*)) : zcalloc(realsize*sizeof(dictEntry*));
n.used = 0;

/* Is this the first initialization? If so it's not really a rehashing
Expand Down Expand Up @@ -276,7 +281,7 @@ int dictRehash(dict *d, int n) {

/* Check if we already rehashed the whole table... */
if (d->ht[0].used == 0) {
zfree_dram(d->ht[0].table);
zfree(d->ht[0].table);
d->ht[0] = d->ht[1];
_dictReset(&d->ht[1]);
d->rehashidx = -1;
Expand Down Expand Up @@ -475,7 +480,7 @@ int _dictClear(dict *d, dictht *ht, void(callback)(void *)) {
}
}
/* Free the table and the allocated cache structure */
zfree_dram(ht->table);
zfree(ht->table);
/* Re-initialize the table */
_dictReset(ht);
return DICT_OK; /* never fails */
Expand Down
1 change: 1 addition & 0 deletions src/dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ void dictDisableResize(void);
int dictRehash(dict *d, int n);
int dictRehashMilliseconds(dict *d, int ms);
void dictSetHashFunctionSeed(unsigned int initval);
void dictSetAllocPolicy(int policy);
unsigned int dictGetHashFunctionSeed(void);
unsigned long dictScan(dict *d, unsigned long v, dictScanFunction *fn, void *privdata);

Expand Down
2 changes: 2 additions & 0 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,7 @@ void initServerConfig(void) {
server.activerehashing = CONFIG_DEFAULT_ACTIVE_REHASHING;
server.notify_keyspace_events = 0;
server.maxclients = CONFIG_DEFAULT_MAX_CLIENTS;
server.hashtable_on_dram = 1;
server.bpop_blocked_clients = 0;
server.maxmemory = CONFIG_DEFAULT_MAXMEMORY;
server.maxmemory_policy = CONFIG_DEFAULT_MAXMEMORY_POLICY;
Expand Down Expand Up @@ -2015,6 +2016,7 @@ void initServer(void) {
slowlogInit();
latencyMonitorInit();
pmemThresholdInit();
dictSetAllocPolicy(server.hashtable_on_dram);
bioInit();
}

Expand Down
1 change: 1 addition & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,7 @@ struct redisServer {
ratioDramPmemConfig dram_pmem_ratio; /* DRAM/Persistent Memory ratio */
double target_pmem_dram_ratio; /* Target PMEM/DRAM ratio */
int ratio_check_period; /* Period of checking ratio in Cron*/
int hashtable_on_dram; /* Keep hashtable always on DRAM */
/* Blocked clients */
unsigned int bpop_blocked_clients; /* Number of clients blocked by lists */
list *unblocked_clients; /* list of clients to unblock before next loop */
Expand Down