[CRIU] [PATCH v2 07/11] uffd: Keep lpi pointer on epoll_event, not fd

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


From: Pavel Emelyanov <xemul at virtuozzo.com>

This helps us get lpi MUCH faster on #PF.

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

diff --git a/criu/uffd.c b/criu/uffd.c
index 777d18b..80e9980 100644
--- a/criu/uffd.c
+++ b/criu/uffd.c
@@ -108,19 +108,6 @@ static void lpi_hash_init(void)
 		INIT_HLIST_HEAD(&lpi_hash[i]);
 }
 
-struct lazy_pages_info *uffd_to_lpi(int uffd)
-{
-	struct lazy_pages_info *lpi;
-	struct hlist_head *head;
-
-	head = &lpi_hash[uffd % LPI_HASH_SIZE];
-	hlist_for_each_entry(lpi, head, hash)
-		if (lpi->uffd == uffd)
-			return lpi;
-
-	return NULL;
-}
-
 static void lpi_hash_fini(void)
 {
 	struct lazy_pages_info *p;
@@ -759,8 +746,8 @@ static int handle_requests(int epollfd, struct epoll_event *events)
 
 		for (i = 0; i < ret; i++) {
 			int err;
-			lpi = uffd_to_lpi(events[i].data.fd);
-			BUG_ON(!lpi);
+
+			lpi = (struct lazy_pages_info *)events[i].data.ptr;
 			err = handle_user_fault(lpi, dest);
 			if (err < 0)
 				goto out;
@@ -824,13 +811,13 @@ free_events:
 	return -1;
 }
 
-static int epoll_add_fd(int epollfd, int fd)
+static int epoll_add_lpi(int epollfd, struct lazy_pages_info *lpi)
 {
 	struct epoll_event ev;
 
 	ev.events = EPOLLIN;
-	ev.data.fd = fd;
-	if (epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &ev) == -1) {
+	ev.data.ptr = lpi;
+	if (epoll_ctl(epollfd, EPOLL_CTL_ADD, lpi->uffd, &ev) == -1) {
 		pr_perror("epoll_ctl failed");
 		return -1;
 	}
@@ -877,7 +864,7 @@ static int prepare_uffds(int listen, int epollfd)
 			goto close_uffd;
 		if (lpi == NULL)
 			continue;
-		if (epoll_add_fd(epollfd, lpi->uffd))
+		if (epoll_add_lpi(epollfd, lpi))
 			goto close_uffd;
 	}
 
-- 
1.9.1



More information about the CRIU mailing list