Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed memory human style memory reporting, removed server.usedmemory,…

… now zmalloc_used_memory() is used always.
  • Loading branch information...
commit b72f6a4b70ef642a085f700243ebf885ca7b09f4 1 parent b0d8747
Salvatore Sanfilippo antirez authored

Showing 2 changed files with 9 additions and 9 deletions. Show diff stats Hide diff stats

  1. +2 0  TODO
  2. +7 9 redis.c
2  TODO
@@ -14,6 +14,8 @@ Virtual Memory sub-TODO:
14 14 * Divide swappability of objects by refcount
15 15 * it should be possible to give the vm-max-memory option in megabyte, gigabyte, ..., just using 2GB, 100MB, and so forth.
16 16 * 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?).
  17 +* EXISTS should avoid loading the object if possible without too make the code too specialized.
  18 +* vm-min-age <seconds> option
17 19
18 20 * Hashes (HSET, HGET, HDEL, HEXISTS, HLEN, ...).
19 21
16 redis.c
@@ -336,7 +336,6 @@ struct redisServer {
336 336 int cronloops; /* number of times the cron function run */
337 337 list *objfreelist; /* A list of freed objects to avoid malloc() */
338 338 time_t lastsave; /* Unix time of last save succeeede */
339   - size_t usedmemory; /* Used memory in megabytes */
340 339 /* Fields used only for stats */
341 340 time_t stat_starttime; /* server start time */
342 341 long long stat_numcommands; /* number of processed commands */
@@ -1165,9 +1164,6 @@ static int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientD
1165 1164 * To access a global var is faster than calling time(NULL) */
1166 1165 server.unixtime = time(NULL);
1167 1166
1168   - /* Update the global state with the amount of used memory */
1169   - server.usedmemory = zmalloc_used_memory();
1170   -
1171 1167 /* Show some info about non-empty databases */
1172 1168 for (j = 0; j < server.dbnum; j++) {
1173 1169 long long size, used, vkeys;
@@ -1194,7 +1190,7 @@ static int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientD
1194 1190 redisLog(REDIS_VERBOSE,"%d clients connected (%d slaves), %zu bytes in use, %d shared objects",
1195 1191 listLength(server.clients)-listLength(server.slaves),
1196 1192 listLength(server.slaves),
1197   - server.usedmemory,
  1193 + zmalloc_used_memory(),
1198 1194 dictSize(server.sharingpool));
1199 1195 }
1200 1196
@@ -1437,7 +1433,6 @@ static void initServer() {
1437 1433 server.bgrewritebuf = sdsempty();
1438 1434 server.lastsave = time(NULL);
1439 1435 server.dirty = 0;
1440   - server.usedmemory = 0;
1441 1436 server.stat_numcommands = 0;
1442 1437 server.stat_numconnections = 0;
1443 1438 server.stat_starttime = time(NULL);
@@ -5581,7 +5576,7 @@ static void bytesToHuman(char *s, unsigned long long n) {
5581 5576 sprintf(s,"%.2fM",d);
5582 5577 } else if (n < (1024LL*1024*1024*1024)) {
5583 5578 d = (double)n/(1024LL*1024*1024);
5584   - sprintf(s,"%.2fM",d);
  5579 + sprintf(s,"%.2fG",d);
5585 5580 }
5586 5581 }
5587 5582
@@ -5594,7 +5589,7 @@ static sds genRedisInfoString(void) {
5594 5589 int j;
5595 5590 char hmem[64];
5596 5591
5597   - bytesToHuman(hmem,server.usedmemory);
  5592 + bytesToHuman(hmem,zmalloc_used_memory());
5598 5593 info = sdscatprintf(sdsempty(),
5599 5594 "redis_version:%s\r\n"
5600 5595 "arch_bits:%s\r\n"
@@ -5624,7 +5619,7 @@ static sds genRedisInfoString(void) {
5624 5619 listLength(server.clients)-listLength(server.slaves),
5625 5620 listLength(server.slaves),
5626 5621 server.blockedclients,
5627   - server.usedmemory,
  5622 + zmalloc_used_memory(),
5628 5623 hmem,
5629 5624 server.dirty,
5630 5625 server.bgsavechildpid != -1,
@@ -7396,6 +7391,9 @@ static int vmSwapOneObject(int usethreads) {
7396 7391
7397 7392 for (j = 0; j < server.dbnum; j++) {
7398 7393 redisDb *db = server.db+j;
  7394 + /* Why maxtries is set to 100?
  7395 + * Because this way (usually) we'll find 1 object even if just 1% - 2%
  7396 + * are swappable objects */
7399 7397 int maxtries = 100;
7400 7398
7401 7399 if (dictSize(db->dict) == 0) continue;

0 comments on commit b72f6a4

Please sign in to comment.
Something went wrong with that request. Please try again.