[CRIU] [PATCH 2/3] shmem: Save pages stats too

Pavel Emelianov xemul at virtuozzo.com
Thu May 16 18:23:10 MSK 2019


Shmem pages are written in the same set of images as regular
pages are, but stats for those are not collected. Fix this, but
keep the counts separate to have more info.

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/include/stats.h |  4 ++++
 criu/shmem.c         | 17 +++++++++++++++--
 criu/stats.c         |  7 +++++++
 images/stats.proto   |  4 ++++
 4 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/criu/include/stats.h b/criu/include/stats.h
index 07690b8..bab9a05 100644
--- a/criu/include/stats.h
+++ b/criu/include/stats.h
@@ -29,6 +29,10 @@ enum {
 	CNT_PAGE_PIPES,
 	CNT_PAGE_PIPE_BUFS,
 
+	CNT_SHPAGES_SCANNED,
+	CNT_SHPAGES_SKIPPED_PARENT,
+	CNT_SHPAGES_WRITTEN,
+
 	DUMP_CNT_NR_STATS,
 };
 
diff --git a/criu/shmem.c b/criu/shmem.c
index a3c7c5c..03b088f 100644
--- a/criu/shmem.c
+++ b/criu/shmem.c
@@ -11,6 +11,7 @@
 #include "image.h"
 #include "cr_options.h"
 #include "kerndat.h"
+#include "stats.h"
 #include "page-pipe.h"
 #include "page-xfer.h"
 #include "rst-malloc.h"
@@ -676,6 +677,7 @@ static int do_dump_one_shmem(int fd, void *addr, struct shmem_info *si)
 	struct page_xfer xfer;
 	int err, ret = -1;
 	unsigned long pfn, nrpages, next_data_pnf = 0, next_hole_pfn = 0;
+	unsigned long pages[2] = {};
 
 	nrpages = (si->size + PAGE_SIZE - 1) / PAGE_SIZE;
 
@@ -693,6 +695,7 @@ static int do_dump_one_shmem(int fd, void *addr, struct shmem_info *si)
 		unsigned int pgstate = PST_DIRTY;
 		bool use_mc = true;
 		unsigned long pgaddr;
+		int st = -1;
 
 		if (pfn >= next_hole_pfn &&
 		    next_data_segment(fd, pfn, &next_data_pnf, &next_hole_pfn))
@@ -714,10 +717,13 @@ static int do_dump_one_shmem(int fd, void *addr, struct shmem_info *si)
 again:
 		if (pgstate == PST_ZERO)
 			ret = 0;
-		else if (xfer.parent && page_in_parent(pgstate == PST_DIRTY))
+		else if (xfer.parent && page_in_parent(pgstate == PST_DIRTY)) {
 			ret = page_pipe_add_hole(pp, pgaddr, PP_HOLE_PARENT);
-		else
+			st = 0;
+		} else {
 			ret = page_pipe_add_page(pp, pgaddr, 0);
+			st = 1;
+		}
 
 		if (ret == -EAGAIN) {
 			ret = dump_pages(pp, &xfer);
@@ -727,8 +733,15 @@ again:
 			goto again;
 		} else if (ret)
 			goto err_xfer;
+
+		if (st >= 0)
+			pages[st]++;
 	}
 
+	cnt_add(CNT_SHPAGES_SCANNED, nrpages);
+	cnt_add(CNT_SHPAGES_SKIPPED_PARENT, pages[0]);
+	cnt_add(CNT_SHPAGES_WRITTEN, pages[1]);
+
 	ret = dump_pages(pp, &xfer);
 
 err_xfer:
diff --git a/criu/stats.c b/criu/stats.c
index 64679b1..a643835 100644
--- a/criu/stats.c
+++ b/criu/stats.c
@@ -165,6 +165,13 @@ void write_stats(int what)
 		ds_entry.page_pipe_bufs = dstats->counts[CNT_PAGE_PIPE_BUFS];
 		ds_entry.has_page_pipe_bufs = true;
 
+		ds_entry.shpages_scanned = dstats->counts[CNT_SHPAGES_SCANNED];
+		ds_entry.has_shpages_scanned = true;
+		ds_entry.shpages_skipped_parent = dstats->counts[CNT_SHPAGES_SKIPPED_PARENT];
+		ds_entry.has_shpages_skipped_parent = true;
+		ds_entry.shpages_written = dstats->counts[CNT_SHPAGES_WRITTEN];
+		ds_entry.has_shpages_written = true;
+
 		name = "dump";
 	} else if (what == RESTORE_STATS) {
 		stats.restore = &rs_entry;
diff --git a/images/stats.proto b/images/stats.proto
index d765034..68d2f1b 100644
--- a/images/stats.proto
+++ b/images/stats.proto
@@ -16,6 +16,10 @@ message dump_stats_entry {
 	required uint64			pages_lazy		= 9;
 	optional uint64			page_pipes		= 10;
 	optional uint64			page_pipe_bufs		= 11;
+
+	optional uint64			shpages_scanned		= 12;
+	optional uint64			shpages_skipped_parent	= 13;
+	optional uint64			shpages_written		= 14;
 }
 
 message restore_stats_entry {
-- 
2.1.4



More information about the CRIU mailing list