[CRIU] [PATCH v2 3/6] log_dirty: add dirty-log to save dirty memory pages stats
Pavel Tikhomirov
ptikhomirov at virtuozzo.com
Fri May 27 01:01:47 PDT 2016
v2: use protobuf service image, changed name to "dirty-log"
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
criu/dirty-logger.c | 21 +++++++++++++++++++++
criu/image-desc.c | 6 ++++++
criu/include/image-desc.h | 2 ++
criu/include/magic.h | 1 +
criu/include/protobuf-desc.h | 1 +
images/stats.proto | 7 +++++++
lib/py/images/images.py | 3 ++-
7 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/criu/dirty-logger.c b/criu/dirty-logger.c
index 6620626..745c289 100644
--- a/criu/dirty-logger.c
+++ b/criu/dirty-logger.c
@@ -1,6 +1,27 @@
#include <pthread.h>
+#include "imgset.h"
+
+void img_cleanup(void *arg)
+{
+ close_image((struct cr_img *)arg);
+}
+
+#define CR_DIRTY_LOG "dirty-log.img"
+
void *dirty_logger_pthread(void *arg)
{
+ int *pret = (int *)arg;
+ struct cr_img *img;
+
+ img = open_image_at(AT_FDCWD, CR_FD_DIRTY_LOG, O_DUMP);
+ if (!img) {
+ *pret = -1;
+ pthread_exit(NULL);
+ }
+ pthread_cleanup_push(img_cleanup, (void *)img);
+
+ *pret = 0;
+ pthread_cleanup_pop(1);
pthread_exit(NULL);
}
diff --git a/criu/image-desc.c b/criu/image-desc.c
index 2b31354..38ac978 100644
--- a/criu/image-desc.c
+++ b/criu/image-desc.c
@@ -111,6 +111,12 @@ struct cr_fd_desc_tmpl imgset_template[CR_FD_MAX] = {
.oflags = O_SERVICE,
},
+ [CR_FD_DIRTY_LOG] = {
+ .fmt = "dirty-log",
+ .magic = DIRTY_LOG_MAGIC,
+ .oflags = O_SERVICE,
+ },
+
[CR_FD_FILE_LOCKS_PID] = {
.fmt = "filelocks-%d.img",
.magic = FILE_LOCKS_MAGIC,
diff --git a/criu/include/image-desc.h b/criu/include/image-desc.h
index 7e75ede..40199d2 100644
--- a/criu/include/image-desc.h
+++ b/criu/include/image-desc.h
@@ -107,6 +107,8 @@ enum {
CR_FD_AUTOFS,
+ CR_FD_DIRTY_LOG,
+
CR_FD_MAX
};
diff --git a/criu/include/magic.h b/criu/include/magic.h
index a458c62..7134234 100644
--- a/criu/include/magic.h
+++ b/criu/include/magic.h
@@ -113,5 +113,6 @@
*/
#define STATS_MAGIC 0x57093306 /* Ostashkov */
#define IRMAP_CACHE_MAGIC 0x57004059 /* Ivanovo */
+#define DIRTY_LOG_MAGIC 0x59363949 /* Ges */
#endif /* __CR_MAGIC_H__ */
diff --git a/criu/include/protobuf-desc.h b/criu/include/protobuf-desc.h
index 4cff5db..5b82651 100644
--- a/criu/include/protobuf-desc.h
+++ b/criu/include/protobuf-desc.h
@@ -59,6 +59,7 @@ enum {
PB_BINFMT_MISC, /* 50 */
PB_AUTOFS,
PB_TTY_DATA,
+ PB_DIRTY_LOG,
/* PB_AUTOGEN_STOP */
diff --git a/images/stats.proto b/images/stats.proto
index 16acf34..c6093aa 100644
--- a/images/stats.proto
+++ b/images/stats.proto
@@ -26,3 +26,10 @@ message stats_entry {
optional dump_stats_entry dump = 1;
optional restore_stats_entry restore = 2;
}
+
+message dirty_log_entry {
+ required uint64 sec = 1;
+ required uint64 usec = 2;
+ required uint64 total_pages = 3;
+ required uint64 total_dirty_pages = 4;
+}
diff --git a/lib/py/images/images.py b/lib/py/images/images.py
index c593a3b..394c027 100644
--- a/lib/py/images/images.py
+++ b/lib/py/images/images.py
@@ -454,6 +454,7 @@ handlers = {
'USERNS' : entry_handler(userns_entry),
'SECCOMP' : entry_handler(seccomp_entry),
'AUTOFS' : entry_handler(autofs_entry),
+ 'DIRTY_LOG' : entry_handler(dirty_log_entry),
}
def __rhandler(f):
@@ -518,7 +519,7 @@ handlers = {
# Images v1.1 NOTE: use "second" magic to identify what "first"
# should be written.
if m != 'INVENTORY':
- if m in ('STATS', 'IRMAP_CACHE'):
+ if m in ('STATS', 'IRMAP_CACHE', 'DIRTY_LOG'):
f.write(struct.pack('i', magic.by_name['IMG_SERVICE']))
else:
f.write(struct.pack('i', magic.by_name['IMG_COMMON']))
--
2.5.5
More information about the CRIU
mailing list