From: antirez Date: Wed, 2 Jun 2010 13:13:53 +0000 (+0200) Subject: better swapout policy while loading RDB file X-Git-Url: https://git.saurik.com/redis.git/commitdiff_plain/7e02fe32d3b95a9c56490b381784e47e2d97dedf?ds=sidebyside better swapout policy while loading RDB file --- diff --git a/redis.c b/redis.c index 949bb58e..9352356d 100644 --- a/redis.c +++ b/redis.c @@ -4120,6 +4120,7 @@ static int rdbLoad(char *filename) { } while(1) { robj *key, *val; + int force_swapout; expiretime = -1; /* Read type. */ @@ -4184,9 +4185,13 @@ static int rdbLoad(char *filename) { continue; } + force_swapout = 0; + if ((zmalloc_used_memory() - server.vm_max_memory) > 1024*1024*32) + force_swapout = 1; + /* If we have still some hope of having some value fitting memory * then we try random sampling. */ - if (!swap_all_values && server.vm_enabled && (loadedkeys % 5000) == 0) { + if (!swap_all_values && server.vm_enabled && force_swapout) { while (zmalloc_used_memory() > server.vm_max_memory) { if (vmSwapOneObjectBlocking() == REDIS_ERR) break; }