[CRIU] [PATCH v2 08/11] uffd: Turn lpi_hash into list

Mike Rapoport rppt at linux.vnet.ibm.com
Sun Nov 13 01:52:41 PST 2016


From: Pavel Emelyanov <xemul at virtuozzo.com>

After previous patch we no longer need this hash since
we don't need fd -> lpi conversion.

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
Acked-by: Mike Rapoport <rppt at linux.vnet.ibm.com>
---
 criu/uffd.c | 51 ++++++++++++---------------------------------------
 1 file changed, 12 insertions(+), 39 deletions(-)

diff --git a/criu/uffd.c b/criu/uffd.c
index 80e9980..be75744 100644
--- a/criu/uffd.c
+++ b/criu/uffd.c
@@ -64,11 +64,10 @@ struct lazy_pages_info {
 	unsigned long total_pages;
 	unsigned long copied_pages;
 
-	struct hlist_node hash;
+	struct list_head l;
 };
 
-#define LPI_HASH_SIZE	16
-static struct hlist_head lpi_hash[LPI_HASH_SIZE];
+static LIST_HEAD(lpis);
 
 static struct lazy_pages_info *lpi_init(void)
 {
@@ -80,7 +79,7 @@ static struct lazy_pages_info *lpi_init(void)
 
 	memset(lpi, 0, sizeof(*lpi));
 	INIT_LIST_HEAD(&lpi->iovs);
-	INIT_HLIST_NODE(&lpi->hash);
+	INIT_LIST_HEAD(&lpi->l);
 
 	return lpi;
 }
@@ -100,25 +99,6 @@ static void lpi_fini(struct lazy_pages_info *lpi)
 	free(lpi);
 }
 
-static void lpi_hash_init(void)
-{
-	int i;
-
-	for (i = 0; i < LPI_HASH_SIZE; i++)
-		INIT_HLIST_HEAD(&lpi_hash[i]);
-}
-
-static void lpi_hash_fini(void)
-{
-	struct lazy_pages_info *p;
-	struct hlist_node *n;
-	int i;
-
-	for (i = 0; i < LPI_HASH_SIZE; i++)
-		hlist_for_each_entry_safe(p, n, &lpi_hash[i], hash)
-			lpi_fini(p);
-}
-
 static int prepare_sock_addr(struct sockaddr_un *saddr)
 {
 	int len;
@@ -504,7 +484,7 @@ static int ud_open(int client, struct lazy_pages_info **_lpi)
 
 	pr_debug("Found %ld pages to be handled by UFFD\n", lpi->total_pages);
 
-	hlist_add_head(&lpi->hash, &lpi_hash[lpi->uffd % LPI_HASH_SIZE]);
+	list_add_tail(&lpi->l, &lpis);
 	*_lpi = lpi;
 
 	return 0;
@@ -754,20 +734,17 @@ static int handle_requests(int epollfd, struct epoll_event *events)
 		}
 	}
 	pr_debug("Handle remaining pages\n");
-	for (i = 0; i < LPI_HASH_SIZE; i++) {
-		hlist_for_each_entry(lpi, &lpi_hash[i], hash) {
-			ret = handle_remaining_pages(lpi, dest);
-			if (ret < 0) {
-				pr_err("Error during remaining page copy\n");
-				ret = 1;
-				goto out;
-			}
+	list_for_each_entry(lpi, &lpis, l) {
+		ret = handle_remaining_pages(lpi, dest);
+		if (ret < 0) {
+			pr_err("Error during remaining page copy\n");
+			ret = 1;
+			goto out;
 		}
 	}
 
-	for (i = 0; i < LPI_HASH_SIZE; i++)
-		hlist_for_each_entry(lpi, &lpi_hash[i], hash)
-			ret += lazy_pages_summary(lpi);
+	list_for_each_entry(lpi, &lpis, l)
+		ret += lazy_pages_summary(lpi);
 
 out:
 	free(dest);
@@ -873,7 +850,6 @@ static int prepare_uffds(int listen, int epollfd)
 	return 0;
 
 close_uffd:
-	lpi_hash_fini();
 	close_safe(&client);
 	close(listen);
 	return -1;
@@ -889,8 +865,6 @@ int cr_lazy_pages(bool daemon)
 	if (check_for_uffd())
 		return -1;
 
-	lpi_hash_init();
-
 	if (lazy_pages_prepare_pstree())
 		return -1;
 
@@ -929,7 +903,6 @@ int cr_lazy_pages(bool daemon)
 		return -1;
 
 	ret = handle_requests(epollfd, events);
-	lpi_hash_fini();
 
 	return ret;
 }
-- 
1.9.1



More information about the CRIU mailing list