[CRIU] [PATCH] mem: Don't track memory changes if --track-mem is not specified

Pavel Emelyanov xemul at parallels.com
Thu Jan 16 02:43:06 PST 2014


We have a big mistake in how we track for ptes to be SOFT_DIRTY -- no
need in these checks if the --track-mem is not given.

While fixing this, remember proper checks for the kernel memory tracker.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>

---

diff --git a/kerndat.c b/kerndat.c
index c371e06..78b22f8 100644
--- a/kerndat.c
+++ b/kerndat.c
@@ -12,6 +12,7 @@
 #include "compiler.h"
 #include "sysctl.h"
 #include "asm/types.h"
+#include "cr_options.h"
 
 dev_t kerndat_shmem_dev;
 
@@ -96,8 +97,13 @@ int kerndat_get_dirty_track(void)
 	if (pmap & PME_SOFT_DIRTY) {
 		pr_info("Dirty track supported on kernel\n");
 		kerndat_has_dirty_track = true;
-	} else
+	} else {
 		pr_info("Dirty tracking support is OFF\n");
+		if (opts.track_mem) {
+			pr_err("Tracking memory is not available\n");
+			return -1;
+		}
+	}
 
 	return 0;
 }
diff --git a/mem.c b/mem.c
index 67d249e..e5a6889 100644
--- a/mem.c
+++ b/mem.c
@@ -43,11 +43,7 @@ static int task_reset_dirty_track(int pid)
 	if (!opts.track_mem)
 		return 0;
 
-	if (!kerndat_has_dirty_track) {
-		pr_err("Kernel doesn't support dirty tracking. "
-				"No snapshot available.\n");
-		return -1;
-	}
+	BUG_ON(!kerndat_has_dirty_track);
 
 	return do_task_reset_dirty_track(pid);
 }
@@ -81,6 +77,17 @@ static struct mem_snap_ctx *mem_snap_init(struct parasite_ctl *ctl)
 	int p_fd, pm_fd;
 	PagemapHead *h;
 
+	/*
+	 * If we're not tracking memory changes, then it doesn't
+	 * matter whether we have parent images or not. Just
+	 * proceed with full memory dump.
+	 */
+
+	if (!opts.track_mem)
+		return NULL;
+
+	BUG_ON(!kerndat_has_dirty_track);
+
 	p_fd = get_service_fd(PARENT_FD_OFF);
 	if (p_fd < 0) {
 		pr_debug("Will do full memory dump\n");
diff --git a/test/mem-snap/run-predump-2.sh b/test/mem-snap/run-predump-2.sh
index 3fc2f74..a15f987 100755
--- a/test/mem-snap/run-predump-2.sh
+++ b/test/mem-snap/run-predump-2.sh
@@ -58,7 +58,7 @@ ${CRIU} pre-dump -D "$IMGDIR/dump-2/pre/" -o dump.log -t ${PID} -v4 || fail "Fai
 
 echo "Plain dump"
 mkdir "$IMGDIR/dump-2/plain/"
-${CRIU} dump -D "$IMGDIR/dump-2/plain/" -o dump.log -t ${PID} -v4 --prev-images-dir=../pre/ || fail "Fail to dump"
+${CRIU} dump -D "$IMGDIR/dump-2/plain/" -o dump.log -t ${PID} -v4 --prev-images-dir=../pre/ --track-mem || fail "Fail to dump"
 
 sleep 1
 echo "Restore"
diff --git a/test/mem-snap/run-predump.sh b/test/mem-snap/run-predump.sh
index 741d8eb..c861952 100755
--- a/test/mem-snap/run-predump.sh
+++ b/test/mem-snap/run-predump.sh
@@ -46,7 +46,7 @@ for SNAP in $(seq 1 $NRSNAP); do
 	elif [ $SNAP -eq $NRSNAP ]; then
 		# Last dump
 		cmd="dump"
-		args="--prev-images-dir=../$((SNAP - 1))/"
+		args="--prev-images-dir=../$((SNAP - 1))/ --track-mem"
 	else
 		# Other pre-dumps
 		cmd="pre-dump"
diff --git a/test/mem-snap/run-snap-auto-dedup.sh b/test/mem-snap/run-snap-auto-dedup.sh
index 7339b5a..955fcf9 100755
--- a/test/mem-snap/run-snap-auto-dedup.sh
+++ b/test/mem-snap/run-snap-auto-dedup.sh
@@ -45,7 +45,7 @@ for SNAP in $(seq 1 $NRSNAP); do
 	elif [ $SNAP -eq $NRSNAP ]; then
 		# Last snapshot -- has parent, kill afterwards
 		size_first=$(du -sh -BK  dump/2/pages-*.img | grep -Eo '[0-9]+' | head -1)
-		args="--prev-images-dir=../$((SNAP - 1))/ --auto-dedup"
+		args="--prev-images-dir=../$((SNAP - 1))/ --track-mem --auto-dedup"
 	else
 		# Other snapshots -- have parent, keep running
 		args="--prev-images-dir=../$((SNAP - 1))/ --track-mem -R"
diff --git a/test/mem-snap/run-snap-dedup.sh b/test/mem-snap/run-snap-dedup.sh
index 6926c8c..c8bf9a1 100755
--- a/test/mem-snap/run-snap-dedup.sh
+++ b/test/mem-snap/run-snap-dedup.sh
@@ -44,7 +44,7 @@ for SNAP in $(seq 1 $NRSNAP); do
 		args="--track-mem -R"
 	elif [ $SNAP -eq $NRSNAP ]; then
 		# Last snapshot -- has parent, kill afterwards
-		args="--prev-images-dir=../$((SNAP - 1))/"
+		args="--prev-images-dir=../$((SNAP - 1))/ --track-mem"
 	else
 		# Other snapshots -- have parent, keep running
 		args="--prev-images-dir=../$((SNAP - 1))/ --track-mem -R"
diff --git a/test/mem-snap/run-snap.sh b/test/mem-snap/run-snap.sh
index d2a6207..6e0b0f8 100755
--- a/test/mem-snap/run-snap.sh
+++ b/test/mem-snap/run-snap.sh
@@ -44,7 +44,7 @@ for SNAP in $(seq 1 $NRSNAP); do
 		args="--track-mem -R"
 	elif [ $SNAP -eq $NRSNAP ]; then
 		# Last snapshot -- has parent, kill afterwards
-		args="--prev-images-dir=../$((SNAP - 1))/"
+		args="--prev-images-dir=../$((SNAP - 1))/ --track-mem"
 	else
 		# Other snapshots -- have parent, keep running
 		args="--prev-images-dir=../$((SNAP - 1))/ --track-mem -R"


More information about the CRIU mailing list