[CRIU] [PATCH 08/10] uffd: Don't carry void *page through the callstack
Mike Rapoport
rppt at linux.vnet.ibm.com
Sat Nov 12 06:00:16 PST 2016
On Sat, Nov 12, 2016 at 08:25:44AM +0300, Pavel Emelyanov wrote:
> Since all #PFs are serialized with a mutex it seems reasonable
> to have a global page_szie() buffer nearby.
I don't remember any mutex for #PF syncronization. They might be serialized
because we do things one by one at the moment, but in the future we might
want to have a buffer per process to hold the data.
> Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
> ---
> criu/uffd.c | 39 ++++++++++++++++++---------------------
> 1 file changed, 18 insertions(+), 21 deletions(-)
>
> diff --git a/criu/uffd.c b/criu/uffd.c
> index 96b5ec0..25e13ab 100644
> --- a/criu/uffd.c
> +++ b/criu/uffd.c
> @@ -46,6 +46,7 @@
> #define LAZY_PAGES_SOCK_NAME "lazy-pages.socket"
>
> static mutex_t *lazy_sock_mutex;
> +static void *aux_page;
>
> struct lazy_pages_info {
> int pid;
> @@ -375,21 +376,20 @@ struct uffd_pages_struct {
> int flags;
> };
>
> -static int uffd_copy_page(struct lazy_pages_info *lpi, __u64 address,
> - void *dest)
> +static int uffd_copy_page(struct lazy_pages_info *lpi, __u64 address)
> {
> struct uffdio_copy uffdio_copy;
> int rc;
>
> if (opts.use_page_server)
> - rc = get_remote_pages(lpi->pid, address, 1, dest);
> + rc = get_remote_pages(lpi->pid, address, 1, aux_page);
> else
> - rc = get_page(lpi, address, dest);
> + rc = get_page(lpi, address, aux_page);
> if (rc <= 0)
> return rc;
>
> uffdio_copy.dst = address;
> - uffdio_copy.src = (unsigned long) dest;
> + uffdio_copy.src = (unsigned long) aux_page;
> uffdio_copy.len = page_size();
> uffdio_copy.mode = 0;
> uffdio_copy.copy = 0;
> @@ -437,12 +437,11 @@ static int uffd_zero_page(struct lazy_pages_info *lpi, __u64 address)
> return ps;
> }
>
> -static int uffd_handle_page(struct lazy_pages_info *lpi, __u64 address,
> - void *dest)
> +static int uffd_handle_page(struct lazy_pages_info *lpi, __u64 address)
> {
> int rc;
>
> - rc = uffd_copy_page(lpi, address, dest);
> + rc = uffd_copy_page(lpi, address);
> if (rc == 0)
> rc = uffd_zero_page(lpi, address);
>
> @@ -518,7 +517,7 @@ static int collect_uffd_pages(struct page_read *pr, struct lazy_pages_info *lpi)
> return 0;
> }
>
> -static int handle_remaining_pages(struct lazy_pages_info *lpi, void *dest)
> +static int handle_remaining_pages(struct lazy_pages_info *lpi)
> {
> struct uffd_pages_struct *uffd_pages;
> int rc;
> @@ -529,7 +528,7 @@ static int handle_remaining_pages(struct lazy_pages_info *lpi, void *dest)
> if (uffd_pages->flags & UFFD_FLAG_SENT)
> continue;
>
> - rc = uffd_handle_page(lpi, uffd_pages->addr, dest);
> + rc = uffd_handle_page(lpi, uffd_pages->addr);
> if (rc < 0) {
> pr_err("Error during UFFD copy\n");
> return -1;
> @@ -542,13 +541,12 @@ static int handle_remaining_pages(struct lazy_pages_info *lpi, void *dest)
> }
>
>
> -static int handle_regular_pages(struct lazy_pages_info *lpi, void *dest,
> - __u64 address)
> +static int handle_regular_pages(struct lazy_pages_info *lpi, __u64 address)
> {
> int rc;
> struct uffd_pages_struct *uffd_pages;
>
> - rc = uffd_handle_page(lpi, address, dest);
> + rc = uffd_handle_page(lpi, address);
> if (rc < 0) {
> pr_err("Error during UFFD copy\n");
> return -1;
> @@ -647,7 +645,7 @@ out:
> return ret;
> }
>
> -static int handle_user_fault(struct lazy_pages_info *lpi, void *dest)
> +static int handle_user_fault(struct lazy_pages_info *lpi)
> {
> struct uffd_msg msg;
> __u64 flags;
> @@ -686,7 +684,7 @@ static int handle_user_fault(struct lazy_pages_info *lpi, void *dest)
> flags = msg.arg.pagefault.flags;
> pr_debug("msg.arg.pagefault.flags 0x%llx\n", flags);
>
> - ret = handle_regular_pages(lpi, dest, address);
> + ret = handle_regular_pages(lpi, address);
> if (ret < 0) {
> pr_err("Error during regular page copy\n");
> return -1;
> @@ -718,13 +716,12 @@ static int handle_requests(int epollfd, struct epoll_event *events)
> struct lazy_pages_info *lpi;
> int ret = -1;
> unsigned long ps;
> - void *dest;
> int i;
>
> /* All operations will be done on page size */
> ps = page_size();
> - dest = xmalloc(ps);
> - if (!dest)
> + aux_page = xmalloc(ps);
> + if (!aux_page)
> return ret;
>
> while (1) {
> @@ -748,14 +745,14 @@ static int handle_requests(int epollfd, struct epoll_event *events)
> int err;
>
> lpi = (struct lazy_pages_info *)events[i].data.ptr;
> - err = handle_user_fault(lpi, dest);
> + err = handle_user_fault(lpi);
> if (err < 0)
> goto out;
> }
> }
> pr_debug("Handle remaining pages\n");
> list_for_each_entry(lpi, &lpis, l) {
> - ret = handle_remaining_pages(lpi, dest);
> + ret = handle_remaining_pages(lpi);
> if (ret < 0) {
> pr_err("Error during remaining page copy\n");
> ret = 1;
> @@ -767,7 +764,7 @@ static int handle_requests(int epollfd, struct epoll_event *events)
> ret += lazy_pages_summary(lpi);
>
> out:
> - free(dest);
> + free(aux_page);
> return ret;
>
> }
> --
> 2.5.0
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
>
More information about the CRIU
mailing list