[CRIU] [PATCH] image: Use POSIX_FADV_NOREUSE to do not store images in page cache after read

Kirill Tkhai ktkhai at virtuozzo.com
Wed Jul 12 19:55:47 MSK 2017


Please, ignore this patch.

On 12.07.2017 17:57, Kirill Tkhai wrote:
> We read every image block only once, so let's tell the kernel
> not to store pages in page cache for the future.
> 
> [We may also need POSIX_FADV_SEQUENTIAL here, but fadvise fails
> if it's called for DAX files, and it seems there is no way
> to check the file is in such mode].
> 
> Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
> ---
>  criu/image.c |   18 ++++++++++++++++--
>  1 file changed, 16 insertions(+), 2 deletions(-)
> 
> diff --git a/criu/image.c b/criu/image.c
> index 62e8e7109..4508da858 100644
> --- a/criu/image.c
> +++ b/criu/image.c
> @@ -370,11 +370,12 @@ int do_open_remote_image(int dfd, char *path, int flags)
>  
>  static int do_open_image(struct cr_img *img, int dfd, int type, unsigned long oflags, char *path)
>  {
> -	int ret, flags;
> +	int ret, flags, remote;
>  
>  	flags = oflags & ~(O_NOBUF | O_SERVICE | O_FORCE_LOCAL);
> +	remote = (opts.remote && !(oflags & O_FORCE_LOCAL));
>  
> -	if (opts.remote && !(oflags & O_FORCE_LOCAL))
> +	if (remote)
>  		ret = do_open_remote_image(dfd, path, flags);
>  	else
>  		ret = openat(dfd, path, flags, CR_FD_PERM);
> @@ -390,6 +391,19 @@ static int do_open_image(struct cr_img *img, int dfd, int type, unsigned long of
>  	}
>  
>  	img->_x.fd = ret;
> +
> +	if (flags == O_RDONLY && !remote) {
> +		/*
> +		 * Do not keep image pages in page cache after we read them,
> +		 * as we read every block only once.
> +		 */
> +		errno = posix_fadvise(img->_x.fd, 0, 0, POSIX_FADV_NOREUSE);
> +		if (errno) {
> +			pr_perror("Can't fadvice image %s", path);
> +			goto err;
> +		}
> +	}
> +
>  	if (oflags & O_NOBUF)
>  		bfd_setraw(&img->_x);
>  	else {
> 


More information about the CRIU mailing list