From: antirez Date: Tue, 12 Jan 2010 20:23:52 +0000 (-0500) Subject: support for blocking VM in config file X-Git-Url: https://git.saurik.com/redis.git/commitdiff_plain/72e9fd40b63924355dd158ab552e5f339ad1f19b?ds=sidebyside support for blocking VM in config file --- diff --git a/TODO b/TODO index ca8e6ddc..cfd21b76 100644 --- a/TODO +++ b/TODO @@ -16,6 +16,7 @@ Virtual Memory sub-TODO: * Divide swappability of objects by refcount * vm-swap-file . The swap file should go where the user wants, and if it's already there and of the right size we can avoid to create it again. * it should be possible to give the vm-max-memory option in megabyte, gigabyte, ..., just using 2GB, 100MB, and so forth. +* Make sure to wait all the IO threads are done before to fork() for BGSAVE and BGREWRITEAOF VERSION 1.6 TODO (Virtual memory) ================================= diff --git a/redis.c b/redis.c index 43a0bf78..009493eb 100644 --- a/redis.c +++ b/redis.c @@ -1262,18 +1262,23 @@ static int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientD while (server.vm_enabled && zmalloc_used_memory() > server.vm_max_memory) { + int retval; + if (tryFreeOneObjectFromFreelist() == REDIS_OK) continue; - if (vmSwapOneObjectThreaded() == REDIS_ERR) { - if ((loops % 30) == 0 && zmalloc_used_memory() > - (server.vm_max_memory+server.vm_max_memory/10)) { - redisLog(REDIS_WARNING,"WARNING: vm-max-memory limit exceeded by more than 10%% but unable to swap more objects out!"); - } + retval = (server.vm_max_threads == 0) ? + vmSwapOneObjectBlocking() : + vmSwapOneObjectThreaded(); + if (retval == REDIS_ERR && (loops % 30) == 0 && + zmalloc_used_memory() > + (server.vm_max_memory+server.vm_max_memory/10)) + { + redisLog(REDIS_WARNING,"WARNING: vm-max-memory limit exceeded by more than 10%% but unable to swap more objects out!"); } - /* Note that we freed just one object, because anyway when - * the I/O thread in charge to swap this object out will - * do its work, the handler of completed jobs will try to swap - * more objects if we are out of memory. */ - break; + /* Note that when using threade I/O we free just one object, + * because anyway when the I/O thread in charge to swap this + * object out will finish, the handler of completed jobs + * will try to swap more objects if we are still out of memory. */ + if (retval == REDIS_ERR || server.vm_max_threads > 0) break; } } diff --git a/redis.conf b/redis.conf index b541cbe2..f675ac20 100644 --- a/redis.conf +++ b/redis.conf @@ -222,6 +222,9 @@ vm-pages 104857600 # number of threads can help with big objects even if they can't help with # I/O itself as the physical device may not be able to couple with many # reads/writes operations at the same time. +# +# The special value of 0 turn off threaded I/O and enables the blocking +# Virtual Memory implementation. vm-max-threads 4 ############################### ADVANCED CONFIG ###############################