summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2010-10-11 13:20:17 +0200
committerantirez <antirez@gmail.com>2010-10-11 13:20:17 +0200
commita58426fb158d8d96112743fd7740536d7742a203 (patch)
tree85417d695d9023f2c5ce6bab7cf7a1b148e2a8a1
parentd7554adadedd91eb4a2f4477e6d052f86cf72bef (diff)
downloadredis-a58426fb158d8d96112743fd7740536d7742a203.tar.gz
maxmemory fixed, we now try to release memory just before we check for the memory limit. Before fixing there was code between the attempt to free memory and the check for memory limits, and this code could result into allocations going again after the memory limit.
-rw-r--r--redis.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/redis.c b/redis.c
index 86c478281..e927aa065 100644
--- a/redis.c
+++ b/redis.c
@@ -2296,9 +2296,6 @@ static void call(redisClient *c, struct redisCommand *cmd) {
static int processCommand(redisClient *c) {
struct redisCommand *cmd;
- /* Free some memory if needed (maxmemory setting) */
- if (server.maxmemory) freeMemoryIfNeeded();
-
/* Handle the multi bulk command type. This is an alternative protocol
* supported by Redis in order to receive commands that are composed of
* multiple binary-safe "bulk" arguments. The latency of processing is
@@ -2430,7 +2427,12 @@ static int processCommand(redisClient *c) {
return 1;
}
- /* Handle the maxmemory directive */
+ /* Handle the maxmemory directive.
+ *
+ * First we try to free some memory if possible (if there are volatile
+ * keys in the dataset). If there are not the only thing we can do
+ * is returning an error. */
+ if (server.maxmemory) freeMemoryIfNeeded();
if (server.maxmemory && (cmd->flags & REDIS_CMD_DENYOOM) &&
zmalloc_used_memory() > server.maxmemory)
{