[CRIU] [PATCH 06/10] uffd: Turn lpi_hash into list

Mike Rapoport rppt at linux.vnet.ibm.com
Sat Nov 12 05:53:55 PST 2016


On Sat, Nov 12, 2016 at 08:25:01AM +0300, Pavel Emelyanov wrote:
> 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 3fed7fa..43d8e7a 100644
> --- a/criu/uffd.c
> +++ b/criu/uffd.c
> @@ -58,11 +58,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)
>  {
> @@ -74,7 +73,7 @@ static struct lazy_pages_info *lpi_init(void)
> 
>  	memset(lpi, 0, sizeof(*lpi));
>  	INIT_LIST_HEAD(&lpi->pages);
> -	INIT_HLIST_NODE(&lpi->hash);
> +	INIT_LIST_HEAD(&lpi->l);
> 
>  	return lpi;
>  }
> @@ -90,25 +89,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;
> @@ -355,7 +335,7 @@ static int ud_open(int client, struct lazy_pages_info **_lpi)
>  	if ((lpi->total_pages = find_vmas(lpi)) == -1)
>  		goto out;
> 
> -	hlist_add_head(&lpi->hash, &lpi_hash[lpi->uffd % LPI_HASH_SIZE]);
> +	list_add_tail(&lpi->l, &lpis);
>  	*_lpi = lpi;
> 
>  	return 0;
> @@ -774,20 +754,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);
> @@ -893,7 +870,6 @@ static int prepare_uffds(int listen, int epollfd)
>  	return 0;
> 
>  close_uffd:
> -	lpi_hash_fini();
>  	close_safe(&client);
>  	close(listen);
>  	return -1;
> @@ -909,8 +885,6 @@ int cr_lazy_pages(bool daemon)
>  	if (check_for_uffd())
>  		return -1;
> 
> -	lpi_hash_init();
> -
>  	if (lazy_pages_prepare_pstree())
>  		return -1;
> 
> @@ -949,7 +923,6 @@ int cr_lazy_pages(bool daemon)
>  		return -1;
> 
>  	ret = handle_requests(epollfd, events);
> -	lpi_hash_fini();
> 
>  	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