summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2012-10-05 10:48:49 +0200
committerantirez <antirez@gmail.com>2012-10-05 10:56:35 +0200
commit05e06e154332cf107d30092dddb94b6b35967ce5 (patch)
tree03829020b9d32d0514a9b921e228eff1ceeb3b83
parente2f2dab3efbe2ffdcad013eaa9131529c82b6fd4 (diff)
downloadredis-05e06e154332cf107d30092dddb94b6b35967ce5.tar.gz
Warn when configured maxmemory value seems odd.
This commit warns the user with a log at "warning" level if: 1) After the server startup the maxmemory limit was found to be < 1MB. 2) After a CONFIG SET command modifying the maxmemory setting the limit is set to a value that is smaller than the currently used memory. The behaviour of the Redis server is unmodified, and this wil not make the CONFIG SET command or a wrong configuration in redis.conf less likely to create problems, but at least this will make aware most users about a possbile error they committed without resorting to external help. However no warning is issued if, as a result of loading the AOF or RDB file, we are very near the maxmemory setting, or key eviction will be needed in order to go under the specified maxmemory setting. The reason is that in servers configured as a cache with an aggressive maxmemory-policy most of the times restarting the server will cause this condition to happen if persistence is not switched off. This fixes issue #429.
-rw-r--r--src/config.c7
-rw-r--r--src/redis.c5
2 files changed, 11 insertions, 1 deletions
diff --git a/src/config.c b/src/config.c
index 768db1e9a..a36eb9a39 100644
--- a/src/config.c
+++ b/src/config.c
@@ -438,7 +438,12 @@ void configSetCommand(redisClient *c) {
if (getLongLongFromObject(o,&ll) == REDIS_ERR ||
ll < 0) goto badfmt;
server.maxmemory = ll;
- if (server.maxmemory) freeMemoryIfNeeded();
+ if (server.maxmemory) {
+ if (server.maxmemory < zmalloc_used_memory()) {
+ redisLog(REDIS_WARNING,"WARNING: the new maxmemory value set via CONFIG SET is smaller than the current memory usage. This will result in keys eviction and/or inability to accept new write commands depending on the maxmemory-policy.");
+ }
+ freeMemoryIfNeeded();
+ }
} else if (!strcasecmp(c->argv[2]->ptr,"maxmemory-policy")) {
if (!strcasecmp(o->ptr,"volatile-lru")) {
server.maxmemory_policy = REDIS_MAXMEMORY_VOLATILE_LRU;
diff --git a/src/redis.c b/src/redis.c
index 0656d7c29..aa5a73f2a 100644
--- a/src/redis.c
+++ b/src/redis.c
@@ -2578,6 +2578,11 @@ int main(int argc, char **argv) {
redisLog(REDIS_NOTICE,"The server is now ready to accept connections at %s", server.unixsocket);
}
+ /* Warning the user about suspicious maxmemory setting. */
+ if (server.maxmemory > 0 && server.maxmemory < 1024*1024) {
+ redisLog(REDIS_WARNING,"WARNING: You specified a maxmemory value that is less than 1MB (current value is %llu bytes). Are you sure this is what you really want?", server.maxmemory);
+ }
+
aeSetBeforeSleepProc(server.el,beforeSleep);
aeMain(server.el);
aeDeleteEventLoop(server.el);