From b72f6a4b70ef642a085f700243ebf885ca7b09f4 Mon Sep 17 00:00:00 2001 From: antirez Date: Sat, 23 Jan 2010 11:55:04 -0500 Subject: [PATCH] Fixed memory human style memory reporting, removed server.usedmemory, now zmalloc_used_memory() is used always. --- TODO | 2 ++ redis.c | 16 +++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/TODO b/TODO index 015a01a1a..0771cafe9 100644 --- a/TODO +++ b/TODO @@ -14,6 +14,8 @@ Virtual Memory sub-TODO: * Divide swappability of objects by refcount * it should be possible to give the vm-max-memory option in megabyte, gigabyte, ..., just using 2GB, 100MB, and so forth. * Try to understand what can be moved into I/O threads that currently is instead handled by the main thread. For instance swapping file table scannig to find contiguous page could be a potential candidate (but I'm not convinced it's a good idea, better to improve the algorithm, for instance double the fast forward at every step?). +* EXISTS should avoid loading the object if possible without too make the code too specialized. +* vm-min-age option * Hashes (HSET, HGET, HDEL, HEXISTS, HLEN, ...). diff --git a/redis.c b/redis.c index c187b266f..21c547c05 100644 --- a/redis.c +++ b/redis.c @@ -336,7 +336,6 @@ struct redisServer { int cronloops; /* number of times the cron function run */ list *objfreelist; /* A list of freed objects to avoid malloc() */ time_t lastsave; /* Unix time of last save succeeede */ - size_t usedmemory; /* Used memory in megabytes */ /* Fields used only for stats */ time_t stat_starttime; /* server start time */ long long stat_numcommands; /* number of processed commands */ @@ -1165,9 +1164,6 @@ static int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientD * To access a global var is faster than calling time(NULL) */ server.unixtime = time(NULL); - /* Update the global state with the amount of used memory */ - server.usedmemory = zmalloc_used_memory(); - /* Show some info about non-empty databases */ for (j = 0; j < server.dbnum; j++) { long long size, used, vkeys; @@ -1194,7 +1190,7 @@ static int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientD redisLog(REDIS_VERBOSE,"%d clients connected (%d slaves), %zu bytes in use, %d shared objects", listLength(server.clients)-listLength(server.slaves), listLength(server.slaves), - server.usedmemory, + zmalloc_used_memory(), dictSize(server.sharingpool)); } @@ -1437,7 +1433,6 @@ static void initServer() { server.bgrewritebuf = sdsempty(); server.lastsave = time(NULL); server.dirty = 0; - server.usedmemory = 0; server.stat_numcommands = 0; server.stat_numconnections = 0; server.stat_starttime = time(NULL); @@ -5581,7 +5576,7 @@ static void bytesToHuman(char *s, unsigned long long n) { sprintf(s,"%.2fM",d); } else if (n < (1024LL*1024*1024*1024)) { d = (double)n/(1024LL*1024*1024); - sprintf(s,"%.2fM",d); + sprintf(s,"%.2fG",d); } } @@ -5594,7 +5589,7 @@ static sds genRedisInfoString(void) { int j; char hmem[64]; - bytesToHuman(hmem,server.usedmemory); + bytesToHuman(hmem,zmalloc_used_memory()); info = sdscatprintf(sdsempty(), "redis_version:%s\r\n" "arch_bits:%s\r\n" @@ -5624,7 +5619,7 @@ static sds genRedisInfoString(void) { listLength(server.clients)-listLength(server.slaves), listLength(server.slaves), server.blockedclients, - server.usedmemory, + zmalloc_used_memory(), hmem, server.dirty, server.bgsavechildpid != -1, @@ -7396,6 +7391,9 @@ static int vmSwapOneObject(int usethreads) { for (j = 0; j < server.dbnum; j++) { redisDb *db = server.db+j; + /* Why maxtries is set to 100? + * Because this way (usually) we'll find 1 object even if just 1% - 2% + * are swappable objects */ int maxtries = 100; if (dictSize(db->dict) == 0) continue;