mirror of
https://github.com/fluencelabs/redis
synced 2025-06-25 06:51:32 +00:00
Add zcalloc and use it where appropriate
calloc is more effecient than malloc+memset when the system uses mmap to allocate memory. mmap always returns zeroed memory so the memset can be avoided. The threshold to use mmap is 16k in osx libc and 128k in bsd libc and glibc. The kernel can lazily allocate the pages, this reduces memory usage when we have a page table or hash table that is mostly empty. This change is most visible when you start a new redis instance with vm enabled. You'll see no increased memory usage no matter how big your page table is.
This commit is contained in:
@ -148,14 +148,12 @@ int dictExpand(dict *d, unsigned long size)
|
||||
if (dictIsRehashing(d) || d->ht[0].used > size)
|
||||
return DICT_ERR;
|
||||
|
||||
/* Allocate the new hashtable and initialize all pointers to NULL */
|
||||
n.size = realsize;
|
||||
n.sizemask = realsize-1;
|
||||
n.table = zmalloc(realsize*sizeof(dictEntry*));
|
||||
n.table = zcalloc(realsize*sizeof(dictEntry*));
|
||||
n.used = 0;
|
||||
|
||||
/* Initialize all the pointers to NULL */
|
||||
memset(n.table, 0, realsize*sizeof(dictEntry*));
|
||||
|
||||
/* Is this the first initialization? If so it's not really a rehashing
|
||||
* we just set the first hash table so that it can accept keys. */
|
||||
if (d->ht[0].table == NULL) {
|
||||
|
Reference in New Issue
Block a user