diff --git a/src/childinfo.c b/src/childinfo.c index 85adfe2f6..cae73fe46 100644 --- a/src/childinfo.c +++ b/src/childinfo.c @@ -127,21 +127,9 @@ void receiveChildInfo(void) { int process_type; int on_exit; size_t cow_size; - if (readChildInfo(&process_type, &on_exit, &cow_size)) { - updateChildInfo(process_type, on_exit, cow_size); - } -} - -/* Receive last COW data from child. */ -void receiveLastChildInfo(void) { - if (server.child_info_pipe[0] == -1) return; - - /* Drain the pipe and update child info */ - int process_type; - int on_exit; - size_t cow_size; - - while (readChildInfo(&process_type, &on_exit, &cow_size) > 0) { + + /* Drain the pipe and update child info so that we get the final message. */ + while (readChildInfo(&process_type, &on_exit, &cow_size)) { updateChildInfo(process_type, on_exit, cow_size); } } diff --git a/src/server.h b/src/server.h index 9fe15685e..eb967a042 100644 --- a/src/server.h +++ b/src/server.h @@ -2013,7 +2013,6 @@ void openChildInfoPipe(void); void closeChildInfoPipe(void); void sendChildInfo(int process_type, int on_exit, size_t cow_size); void receiveChildInfo(void); -void receiveLastChildInfo(void); /* Fork helpers */ int redisFork(int type); diff --git a/src/zmalloc.c b/src/zmalloc.c index 86b15b0ee..eacce67bd 100644 --- a/src/zmalloc.c +++ b/src/zmalloc.c @@ -580,15 +580,18 @@ size_t zmalloc_get_smap_bytes_by_field(char *field, long pid) { size_t zmalloc_get_smap_bytes_by_field(char *field, long pid) { #if defined(__APPLE__) struct proc_regioninfo pri; - if (proc_pidinfo(pid, PROC_PIDREGIONINFO, 0, &pri, PROC_PIDREGIONINFO_SIZE) == - PROC_PIDREGIONINFO_SIZE) { - if (!strcmp(field, "Private_Dirty:")) { - return (size_t)pri.pri_pages_dirtied * 4096; - } else if (!strcmp(field, "Rss:")) { - return (size_t)pri.pri_pages_resident * 4096; - } else if (!strcmp(field, "AnonHugePages:")) { + if (pid == -1) pid = getpid(); + if (proc_pidinfo(pid, PROC_PIDREGIONINFO, 0, &pri, + PROC_PIDREGIONINFO_SIZE) == PROC_PIDREGIONINFO_SIZE) + { + int pagesize = getpagesize(); + if (!strcmp(field, "Private_Dirty:")) { + return (size_t)pri.pri_pages_dirtied * pagesize; + } else if (!strcmp(field, "Rss:")) { + return (size_t)pri.pri_pages_resident * pagesize; + } else if (!strcmp(field, "AnonHugePages:")) { return 0; - } + } } return 0; #endif diff --git a/tests/integration/rdb.tcl b/tests/integration/rdb.tcl index cd4dfbadb..99495b2b7 100644 --- a/tests/integration/rdb.tcl +++ b/tests/integration/rdb.tcl @@ -199,6 +199,10 @@ test {client freed during loading} { } } +# Our COW metrics (Private_Dirty) work only on Linux +set system_name [string tolower [exec uname -s]] +if {$system_name eq {linux}} { + start_server {overrides {save ""}} { test {Test child sending COW info} { # make sure that rdb_last_cow_size and current_cow_size are zero (the test using new server), @@ -209,6 +213,7 @@ start_server {overrides {save ""}} { # using a 200us delay, the bgsave is empirically taking about 10 seconds. # we need it to take more than some 5 seconds, since redis only report COW once a second. r config set rdb-key-save-delay 200 + r config set loglevel debug # populate the db with 10k keys of 4k each set rd [redis_deferring_client 0] @@ -247,8 +252,9 @@ start_server {overrides {save ""}} { } else { if {$::verbose} { puts "COW info on fail: [s current_cow_size]" + puts [exec tail -n 100 < [srv 0 stdout]] } - fail "COW info didn't report" + fail "COW info wasn't reported" } # for no accurate, stop after 2 iterations @@ -265,11 +271,21 @@ start_server {overrides {save ""}} { } # make sure we saw report of current_cow_size + if {$iteration < 2 && $::verbose} { + puts [exec tail -n 100 < [srv 0 stdout]] + } assert_morethan_equal $iteration 2 - # if bgsave completed, check that rdb_last_cow_size value is at least as last rdb_active_cow_size. + # if bgsave completed, check that rdb_last_cow_size (fork exit report) + # is at least 90% of last rdb_active_cow_size. if { [s rdb_bgsave_in_progress] == 0 } { - assert_morethan_equal [s rdb_last_cow_size] $cow_size + set final_cow [s rdb_last_cow_size] + set cow_size [expr $cow_size * 0.9] + if {$final_cow < $cow_size && $::verbose} { + puts [exec tail -n 100 < [srv 0 stdout]] + } + assert_morethan_equal $final_cow $cow_size } } -} \ No newline at end of file +} +} ;# system_name