restore: Merge self vmas alltogether

Submitted by Pavel Emelianov on May 24, 2016, 9:34 a.m.

Details

Message ID 5744200E.504@virtuozzo.com
State Accepted
Series "restore: Merge self vmas alltogether"
Commit 88abf2f9c4f15e5de7866a29d8f16e0c373fb638
Headers show

Commit Message

Pavel Emelianov May 24, 2016, 9:34 a.m.
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@virtuozzo.com>
---
 criu/proc_parse.c | 33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)

Patch hide | download patch | download mbox

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);
 	}

Comments

Cyrill Gorcunov May 24, 2016, 11:35 a.m.
On Tue, May 24, 2016 at 12:34:06PM +0300, Pavel Emelyanov wrote:
> 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@virtuozzo.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>