[CRIU] [PATCH v3 1/3] page-read: Do not lseek pages*img file during sequential reads

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


On Sun, Nov 13, 2016 at 09:27:49AM +0200, Mike Rapoport wrote:
> From: Pavel Emelyanov <xemul at virtuozzo.com>
> 
> We keep track of current file position in page_read->pi_off_cur and we use
> page_read->pi_off_next for seek operations. That way we only need to lseek
> when the offsets do not match.

Oops, I missed the s/read/pread change and screwed a big time here...
Not mentioning zdtm.py sneaking in...
Will resend soon.
 
> Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
> Signed-off-by: Mike Rapoport <rppt at linux.vnet.ibm.com>
> ---
>  criu/include/pagemap.h |  4 +++-
>  criu/pagemap.c         | 24 +++++++++++++++---------
>  test/zdtm.py           |  2 +-
>  3 files changed, 19 insertions(+), 11 deletions(-)
> 
> diff --git a/criu/include/pagemap.h b/criu/include/pagemap.h
> index 39227f2..53b5375 100644
> --- a/criu/include/pagemap.h
> +++ b/criu/include/pagemap.h
> @@ -63,7 +63,9 @@ struct page_read {
>  					   go to this guy for page, see
>  					   read_pagemap_page */
>  	unsigned long cvaddr;		/* vaddr we are on */
> -	off_t pi_off;			/* current offset in pages file */
> +	off_t pi_off_cur;		/* current offset in pages file */
> +	off_t pi_off_next;		/* offset to set in pages file after
> +					   seek operations */
> 
>  	struct iovec bunch;		/* record consequent neighbour
>  					   iovecs to punch together */
> diff --git a/criu/pagemap.c b/criu/pagemap.c
> index a2f4c85..69dc9ab 100644
> --- a/criu/pagemap.c
> +++ b/criu/pagemap.c
> @@ -98,7 +98,8 @@ int dedup_one_iovec(struct page_read *pr, struct iovec *iov)
>  		pagemap2iovec(pr->pe, &piov);
>  		piov_end = (unsigned long)piov.iov_base + piov.iov_len;
>  		if (!pagemap_in_parent(pr->pe)) {
> -			ret = punch_hole(pr, pr->pi_off, min(piov_end, iov_end) - off, false);
> +			ret = punch_hole(pr, pr->pi_off_cur,
> +					 min(piov_end, iov_end) - off, false);
>  			if (ret == -1)
>  				return ret;
>  		}
> @@ -161,7 +162,7 @@ static void skip_pagemap_pages(struct page_read *pr, unsigned long len)
> 
>  	pr_debug("\tpr%u Skip %lu bytes from page-dump\n", pr->id, len);
>  	if (pagemap_present(pr->pe))
> -		pr->pi_off += len;
> +		pr->pi_off_next += len;
>  	pr->cvaddr += len;
>  }
> 
> @@ -258,25 +259,28 @@ static int read_local_page(struct page_read *pr, unsigned long vaddr,
>  			   unsigned long len, void *buf)
>  {
>  	int fd = img_raw_fd(pr->pi);
> -	off_t current_vaddr = lseek(fd, pr->pi_off, SEEK_SET);
>  	int ret;
> 
> -	pr_debug("\tpr%u Read page from self %lx/%"PRIx64"\n", pr->id, pr->cvaddr, current_vaddr);
> +	if (pr->pi_off_cur != pr->pi_off_next)
> +		pr->pi_off_cur = lseek(fd, pr->pi_off_next, SEEK_SET);
> +
> +	pr_debug("\tpr%u Read page from self %lx/%"PRIx64"\n", pr->id, pr->cvaddr, pr->pi_off_cur);
>  	ret = read(fd, buf, len);
>  	if (ret != len) {
>  		pr_perror("Can't read mapping page %d", ret);
>  		return -1;
>  	}
> 
> -	pr->pi_off += len;
> -
>  	if (opts.auto_dedup) {
> -		ret = punch_hole(pr, current_vaddr, len, false);
> +		ret = punch_hole(pr, pr->pi_off_cur, len, false);
>  		if (ret == -1) {
>  			return -1;
>  		}
>  	}
> 
> +	pr->pi_off_cur += len;
> +	pr->pi_off_next += len;
> +
>  	return 0;
>  }
> 
> @@ -342,7 +346,8 @@ static void close_page_read(struct page_read *pr)
>  static void reset_pagemap(struct page_read *pr)
>  {
>  	pr->cvaddr = 0;
> -	pr->pi_off = 0;
> +	pr->pi_off_cur = 0;
> +	pr->pi_off_next = 0;
>  	pr->curr_pme = -1;
>  	pr->pe = NULL;
> 
> @@ -484,7 +489,8 @@ int open_page_read_at(int dfd, int pid, struct page_read *pr, int pr_flags)
>  	pr->pe = NULL;
>  	pr->parent = NULL;
>  	pr->cvaddr = 0;
> -	pr->pi_off = 0;
> +	pr->pi_off_cur = 0;
> +	pr->pi_off_next = 0;
>  	pr->bunch.iov_len = 0;
>  	pr->bunch.iov_base = NULL;
>  	pr->pmes = NULL;
> diff --git a/test/zdtm.py b/test/zdtm.py
> index 0d8503f..e4ff1e3 100755
> --- a/test/zdtm.py
> +++ b/test/zdtm.py
> @@ -517,7 +517,7 @@ class zdtm_test:
>  			subprocess.check_call(["make", "zdtm_ct"])
>  		if not os.access("zdtm/lib/libzdtmtst.a", os.F_OK):
>  			subprocess.check_call(["make", "-C", "zdtm/"])
> -		subprocess.check_call(["flock", "zdtm_mount_cgroups.lock", "./zdtm_mount_cgroups"])
> +#		subprocess.check_call(["flock", "zdtm_mount_cgroups.lock", "./zdtm_mount_cgroups"])
> 
> 
>  class inhfd_test:
> -- 
> 1.9.1
> 



More information about the CRIU mailing list