Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Force INFO used_memory_peak to match peak memory #1572

Merged
merged 1 commit into from

2 participants

@mattsta

This is a fix for antirez/redis#1570

used_memory_peak only updates in serverCron every server.hz,
but Redis can use more memory and a user can request memory
INFO before used_memory_peak gets updated in the next
cron run.

This patch updates used_memory_peak to the current
memory usage if the current memory usage is higher
than the recorded used_memory_peak value.

(And it only calls zmalloc_used_memory() once instead of
twice as it was doing before.)

@mattsta mattsta Force INFO used_memory_peak to match peak memory
used_memory_peak only updates in serverCron every server.hz,
but Redis can use more memory and a user can request memory
INFO before used_memory_peak gets updated in the next
cron run.

This patch updates used_memory_peak to the current
memory usage if the current memory usage is higher
than the recorded used_memory_peak value.

(And it only calls zmalloc_used_memory() once instead of
twice as it was doing before.)
f1c9a20
@antirez antirez merged commit 68d6d15 into antirez:unstable
@antirez
Owner

Thanks, merged, just adding a comment to let the casual reader understanding why there is an update of the value there.

@mattsta mattsta deleted the mattsta:consistent-max-memory-info branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 28, 2014
  1. @mattsta

    Force INFO used_memory_peak to match peak memory

    mattsta authored
    used_memory_peak only updates in serverCron every server.hz,
    but Redis can use more memory and a user can request memory
    INFO before used_memory_peak gets updated in the next
    cron run.
    
    This patch updates used_memory_peak to the current
    memory usage if the current memory usage is higher
    than the recorded used_memory_peak value.
    
    (And it only calls zmalloc_used_memory() once instead of
    twice as it was doing before.)
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 2 deletions.
  1. +7 −2 src/redis.c
View
9 src/redis.c
@@ -2407,8 +2407,13 @@ sds genRedisInfoString(char *section) {
if (allsections || defsections || !strcasecmp(section,"memory")) {
char hmem[64];
char peak_hmem[64];
+ size_t zmalloc_used = zmalloc_used_memory();
- bytesToHuman(hmem,zmalloc_used_memory());
+ if (zmalloc_used > server.stat_peak_memory) {
+ server.stat_peak_memory = zmalloc_used;
+ }
+
+ bytesToHuman(hmem,zmalloc_used);
bytesToHuman(peak_hmem,server.stat_peak_memory);
if (sections++) info = sdscat(info,"\r\n");
info = sdscatprintf(info,
@@ -2421,7 +2426,7 @@ sds genRedisInfoString(char *section) {
"used_memory_lua:%lld\r\n"
"mem_fragmentation_ratio:%.2f\r\n"
"mem_allocator:%s\r\n",
- zmalloc_used_memory(),
+ zmalloc_used,
hmem,
zmalloc_get_rss(),
server.stat_peak_memory,
Something went wrong with that request. Please try again.