[CRIU] [PATCH v2 3/5] uffd.c: make some variable static global

Adrian Reber adrian at lisas.de
Thu Mar 24 08:52:52 PDT 2016


From: Adrian Reber <areber at redhat.com>

To better track how many pages have been handled by UFFD a few variables
have been made static global to easier access them and to reduce the
number of parameters passed around.

Signed-off-by: Adrian Reber <areber at redhat.com>
---
 criu/uffd.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/criu/uffd.c b/criu/uffd.c
index 88748bb..041af54 100644
--- a/criu/uffd.c
+++ b/criu/uffd.c
@@ -242,6 +242,9 @@ struct uffd_pages_struct {
 	int flags;
 };
 
+static unsigned long total_pages;
+static unsigned long uffd_copied_pages;
+
 static int uffd_copy_page(int uffd, __u64 address, void *dest)
 {
 	struct uffdio_copy uffdio_copy;
@@ -345,12 +348,9 @@ static int collect_uffd_pages(struct page_read *pr, struct list_head *uffd_list)
 
 static int handle_remaining_pages(int uffd, struct list_head *uffd_list, void *dest)
 {
-	unsigned long uffd_copied_pages = 0;
 	struct uffd_pages_struct *uffd_pages;
 	int rc;
 
-	pr_debug("uffd_copied_pages:    %ld\n", uffd_copied_pages);
-
 	list_for_each_entry(uffd_pages, uffd_list, list) {
 		pr_debug("Checking remaining pages 0x%lx (flags 0x%x)\n",
 			 uffd_pages->addr, uffd_pages->flags);
@@ -367,7 +367,7 @@ static int handle_remaining_pages(int uffd, struct list_head *uffd_list, void *d
 		uffd_pages->flags |= UFFD_FLAG_SENT;
 	}
 
-	return uffd_copied_pages;
+	return 0;
 }
 
 
@@ -382,6 +382,7 @@ static int handle_regular_pages(int uffd, struct list_head *uffd_list, void *des
 		return -1;
 	}
 
+	uffd_copied_pages++;
 	/*
 	 * Mark this page as having been already transferred, so
 	 * that it has not to be copied again later.
@@ -391,15 +392,13 @@ static int handle_regular_pages(int uffd, struct list_head *uffd_list, void *des
 			uffd_pages->flags |= UFFD_FLAG_SENT;
 	}
 
-
-	return 1;
+	return 0;
 }
 
 static int handle_vdso_pages(int uffd, struct list_head *uffd_list, void *dest)
 {
 	int rc;
 	struct uffd_pages_struct *uffd_pages;
-	int uffd_copied_pages = 0;
 
 	list_for_each_entry(uffd_pages, uffd_list, list) {
 		if (!(uffd_pages->flags & UFFD_FLAG_VDSO))
@@ -412,7 +411,7 @@ static int handle_vdso_pages(int uffd, struct list_head *uffd_list, void *dest)
 		uffd_copied_pages++;
 		uffd_pages->flags |= UFFD_FLAG_SENT;
 	}
-	return uffd_copied_pages;
+	return 0;
 }
 
 /*
@@ -521,8 +520,6 @@ int uffd_listen()
 	fd_set set;
 	struct timeval timeout;
 	int uffd;
-	unsigned long uffd_copied_pages = 0;
-	unsigned long total_pages = 0;
 	int uffd_flags;
 	struct uffd_pages_struct *uffd_pages;
 	bool vdso_sent = false;
@@ -607,7 +604,6 @@ int uffd_listen()
 				rc = 1;
 				goto out;
 			}
-			uffd_copied_pages += rc;
 			vdso_sent = true;
 		}
 
@@ -639,9 +635,6 @@ int uffd_listen()
 			rc = 1;
 			goto out;
 		}
-
-		uffd_copied_pages += rc;
-
 	}
 	pr_debug("Handle remaining pages\n");
 	rc = handle_remaining_pages(uffd, &uffd_list, dest);
@@ -651,7 +644,6 @@ int uffd_listen()
 		goto out;
 	}
 
-	uffd_copied_pages += rc;
 	pr_debug("With UFFD transferred pages: (%ld/%ld)\n", uffd_copied_pages, total_pages);
 	if (uffd_copied_pages != total_pages) {
 		pr_warn("Only %ld of %ld pages transferred via UFFD\n", uffd_copied_pages,
-- 
1.8.3.1



More information about the CRIU mailing list