[05/10] uffd: Keep lpi pointer on epoll_event, not fd

Submitted by Pavel Emelianov on Nov. 12, 2016, 5:24 a.m.

Details

Message ID 5826A79C.4000002@virtuozzo.com
State Accepted
Series "uffd: A set of improvements over criu/uffd.c"
Commit 8456e6c25269f2c639a617723c9fde3ee955f40f
Headers show

Commit Message

Pavel Emelianov Nov. 12, 2016, 5:24 a.m.
This helps us get lpi MUCH faster on #PF.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
---
 criu/uffd.c | 25 ++++++-------------------
 1 file changed, 6 insertions(+), 19 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/uffd.c b/criu/uffd.c
index 950a5ea..3fed7fa 100644
--- a/criu/uffd.c
+++ b/criu/uffd.c
@@ -98,19 +98,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;
@@ -779,8 +766,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;
@@ -844,13 +831,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;
 	}
@@ -897,7 +884,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;
 	}
 

Comments

Mike Rapoport Nov. 12, 2016, 1:53 p.m.
On Sat, Nov 12, 2016 at 08:24:44AM +0300, Pavel Emelyanov wrote:
> This helps us get lpi MUCH faster on #PF.
> 
> Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>

Acked-by: Mike Rapoport <rppt@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 950a5ea..3fed7fa 100644
> --- a/criu/uffd.c
> +++ b/criu/uffd.c
> @@ -98,19 +98,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;
> @@ -779,8 +766,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;
> @@ -844,13 +831,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;
>  	}
> @@ -897,7 +884,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;
>  	}
> 
> -- 
> 2.5.0
> 
> _______________________________________________
> CRIU mailing list
> CRIU@openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
>