[CRIU] [PATCH] restore: Merge self vmas alltogether

Pavel Emelyanov xemul at virtuozzo.com
Tue May 24 02:34:06 PDT 2016


When getting hint for restorer blob we scan the list of
vmas in criu address space. Since these vmas are only
required to find holes, we can merge vmas alltogether
and make restorer_get_vma_hint's work easier.

Reduces list of items in small zdtm tests from 71 to 9.

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/proc_parse.c | 33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)

diff --git a/criu/proc_parse.c b/criu/proc_parse.c
index 32cc6ab..01b0871 100644
--- a/criu/proc_parse.c
+++ b/criu/proc_parse.c
@@ -385,6 +385,7 @@ static int vma_get_mapfile(char *fname, struct vma_area *vma, DIR *mfd,
 int parse_self_maps_lite(struct vm_area_list *vms)
 {
 	FILE *maps;
+	struct vma_area *prev = NULL;
 
 	vm_area_list_init(vms);
 
@@ -397,17 +398,31 @@ int parse_self_maps_lite(struct vm_area_list *vms)
 	while (fgets(buf, BUF_SIZE, maps) != NULL) {
 		struct vma_area *vma;
 		char *end;
+		unsigned long s, e;
 
-		vma = alloc_vma_area();
-		if (!vma) {
-			fclose(maps);
-			return -1;
-		}
+		s = strtoul(buf, &end, 16);
+		e = strtoul(end + 1, NULL, 16);
 
-		vma->e->start = strtoul(buf, &end, 16);
-		vma->e->end = strtoul(end + 1, NULL, 16);
-		list_add_tail(&vma->list, &vms->h);
-		vms->nr++;
+		if (prev && prev->e->end == s)
+			/*
+			 * This list is needed for one thing only -- to
+			 * get the idea of what parts of current address
+			 * space are busy. So merge them alltogether.
+			 */
+			prev->e->end = e;
+		else {
+			vma = alloc_vma_area();
+			if (!vma) {
+				fclose(maps);
+				return -1;
+			}
+
+			vma->e->start = s;
+			vma->e->end = e;
+			list_add_tail(&vma->list, &vms->h);
+			vms->nr++;
+			prev = vma;
+		}
 
 		pr_debug("Parsed %"PRIx64"-%"PRIx64" vma\n", vma->e->start, vma->e->end);
 	}
-- 
2.5.0


More information about the CRIU mailing list