image: Use POSIX_FADV_NOREUSE to do not store images in page cache after read

Submitted by Kirill Tkhai on July 12, 2017, 2:57 p.m.

Details

Message ID 149987135720.10089.16794154438895038488.stgit@localhost.localdomain
State Rejected
Series "image: Use POSIX_FADV_NOREUSE to do not store images in page cache after read"
Headers show

Commit Message

Kirill Tkhai July 12, 2017, 2:57 p.m.
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@virtuozzo.com>
---
 criu/image.c |   18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

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 {

Comments

Kirill Tkhai July 12, 2017, 4:55 p.m.
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@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 {
>