[CRIU] [PATCH 5/5] mm: Move VmaEntries from separate image into Mm one

Pavel Emelyanov xemul at parallels.com
Mon Feb 3 12:09:00 PST 2014


When writing VMAs we perform too many small writes into vma-.img files.
This can be easily fixed by moving the vma-s into mm-s, all the more
so they cannot be splitted from each other.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 cr-dump.c            | 12 +++++++-----
 include/image-desc.h |  2 +-
 mem.c                | 19 ++++---------------
 protobuf/mm.proto    |  4 ++++
 4 files changed, 16 insertions(+), 21 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index 183441a..2e5c542 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -408,13 +408,16 @@ static int dump_task_mm(pid_t pid, const struct proc_pid_stat *stat,
 {
 	MmEntry mme = MM_ENTRY__INIT;
 	struct vma_area *vma_area;
-	int ret = -1, fd;
+	int ret = -1, i = 0;
 
 	pr_info("\n");
 	pr_info("Dumping mm (pid: %d)\n", pid);
 	pr_info("----------------------------------------\n");
 
-	fd = fdset_fd(fdset, CR_FD_VMAS);
+	mme.n_vmas = vma_area_list->nr;
+	mme.vmas = xmalloc(mme.n_vmas * sizeof(VmaEntry *));
+	if (!mme.vmas)
+		goto err;
 
 	list_for_each_entry(vma_area, &vma_area_list->h, list) {
 		VmaEntry *vma = vma_area->e;
@@ -434,11 +437,10 @@ static int dump_task_mm(pid_t pid, const struct proc_pid_stat *stat,
 			ret = dump_socket_map(vma_area);
 		else
 			ret = 0;
-
-		if (!ret)
-			ret = pb_write_one(fd, vma, PB_VMA);
 		if (ret)
 			goto err;
+
+		mme.vmas[i++] = vma;
 	}
 
 	mme.mm_start_code = stat->start_code;
diff --git a/include/image-desc.h b/include/image-desc.h
index 47603f5..2fe7cae 100644
--- a/include/image-desc.h
+++ b/include/image-desc.h
@@ -15,7 +15,6 @@ enum {
 	CR_FD_CORE,
 	CR_FD_IDS,
 	CR_FD_MM,
-	CR_FD_VMAS,
 	CR_FD_SIGACT,
 	CR_FD_ITIMERS,
 	CR_FD_POSIX_TIMERS,
@@ -84,6 +83,7 @@ enum {
 	CR_FD_PAGES,
 	CR_FD_PSIGNAL,
 
+	CR_FD_VMAS,
 	CR_FD_PAGES_OLD,
 	CR_FD_SHM_PAGES_OLD,
 
diff --git a/mem.c b/mem.c
index c5c775a..2acb968 100644
--- a/mem.c
+++ b/mem.c
@@ -344,7 +344,7 @@ int parasite_dump_pages_seized(struct parasite_ctl *ctl,
 int prepare_mm_pid(struct pstree_item *i)
 {
 	pid_t pid = i->pid.virt;
-	int fd, ret = -1;
+	int fd, ret = -1, vn = 0;
 	struct rst_info *ri = i->rst;
 
 	fd = open_image(CR_FD_MM, O_RSTR, pid);
@@ -359,27 +359,17 @@ int prepare_mm_pid(struct pstree_item *i)
 	if (ret < 0)
 		return -1;
 
-	fd = open_image(CR_FD_VMAS, O_RSTR, pid);
-	if (fd < 0)
-		return -1;
-
-	while (1) {
+	while (vn < ri->mm->n_vmas) {
 		struct vma_area *vma;
-		VmaEntry *vi;
 
 		ret = -1;
 		vma = alloc_vma_area();
 		if (!vma)
 			break;
 
-		ret = pb_read_one_eof(fd, &vi, PB_VMA);
-		if (ret <= 0) {
-			xfree(vma);
-			break;
-		}
-
+		ret = 0;
 		ri->vmas.nr++;
-		vma->e = vi;
+		vma->e = ri->mm->vmas[vn++];
 		list_add_tail(&vma->list, &ri->vmas.h);
 
 		if (vma_priv(vma->e)) {
@@ -399,7 +389,6 @@ int prepare_mm_pid(struct pstree_item *i)
 			break;
 	}
 
-	close(fd);
 	return ret;
 }
 
diff --git a/protobuf/mm.proto b/protobuf/mm.proto
index d366562..b809061 100644
--- a/protobuf/mm.proto
+++ b/protobuf/mm.proto
@@ -1,3 +1,5 @@
+import "vma.proto";
+
 message mm_entry {
 	required uint64	mm_start_code	=  1;
 	required uint64	mm_end_code	=  2;
@@ -13,4 +15,6 @@ message mm_entry {
 	required uint32	exe_file_id	= 12;
 
 	repeated uint64	mm_saved_auxv	= 13;
+
+	repeated vma_entry vmas		= 14;
 }
-- 
1.8.4.2


More information about the CRIU mailing list