linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
To: Cyrill Gorcunov <gorcunov@gmail.com>, Al Viro <viro@zeniv.linux.org.uk>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Pavel Emelyanov <xemul@parallels.com>,
	kirill.shutemov@linux.intel.com
Subject: RE: [linux-next] splice call weird results
Date: Tue, 27 May 2014 13:20:13 +0300 (EEST)	[thread overview]
Message-ID: <20140527102013.3BF61E009B@blue.fi.intel.com> (raw)
In-Reply-To: <20140527091335.GC20436@moon>

Cyrill Gorcunov wrote:
> Hi! While been trying to run criu on linux-next (due to recent Kirill's patch related
> to /proc/pid/clear_refs with THP enabled) I noticed that it fails dumping programs when
> moves data from memory pages into an image file. So I wrote pretty idiotic test and
> run it on current fedora 20 kernel and then on linux-next.
> 

+Al. He reworked splice code in linux-next.

> fedora-20 output
> ----------------
> [cyrill@moon criu] ~/pipe 
> Opened pipe-test.SQBcJa
> vmspliced 8192 bytes
> spliced 4096 bytes
> 
> linux-next
> ----------
> [root@fc criu]# ~/pipe
> Opened pipe-test.9nZSW7
> vmspliced 8192 bytes
> spliced 8192 bytes
> 
> In test I fill pipe with 8K data then splice 4K of it into a file (the test
> is below). Is it intended, or I did some silly mistake?
> ---
> #define _GNU_SOURCE
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> #include <string.h>
> #include <fcntl.h>
> 
> #include <sys/uio.h>
> 
> #define ARRAY_SIZE(x)	(sizeof(x)/sizeof(x[0]))
> 
> static char buf[8 << 20];
> 
> int main(int argc, char *argv[])
> {
> 	char *tmpname, t[64] = "pipe-test.XXXXXX";
> 	int _pipe[2], fd, ret = 0;
> 
> 	struct iovec iov[] = {
> 		[0] = {
> 			.iov_base	= &buf[0],
> 			.iov_len	= 4096,
> 		},
> 
> 		[1] = {
> 			.iov_base	= &buf[4096],
> 			.iov_len	= 4096,
> 		},
> 	};
> 
> 	if (pipe(_pipe)) {
> 		perror("Can't create pipe");
> 		exit(1);
> 	}
> 
> 	memset(buf, 0x1, sizeof(buf));
> 	tmpname = mktemp(t);
> 
> 	fd = open(tmpname, O_RDWR | O_CREAT | O_TRUNC);
> 	if (fd < 0) {
> 		perror("Can't open temp file");
> 		close(_pipe[0]);
> 		close(_pipe[1]);
> 		exit(1);
> 	}
> 	printf("Opened %s\n", tmpname);
> 
> 	ret = vmsplice(_pipe[1], iov, ARRAY_SIZE(iov), SPLICE_F_GIFT);
> 	printf("vmspliced %li bytes\n", (long)ret);
> 
> 	ret = splice(_pipe[0], NULL, fd, NULL, iov[0].iov_len, SPLICE_F_MOVE);
> 	printf("spliced %li bytes\n", (long)ret);
> 
> out:
> 	close(_pipe[0]);
> 	close(_pipe[1]);
> 	close(fd);
> 	unlink(tmpname);
> 	return ret;
> }

-- 
 Kirill A. Shutemov

  reply	other threads:[~2014-05-27 10:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-27  9:13 [linux-next] splice call weird results Cyrill Gorcunov
2014-05-27 10:20 ` Kirill A. Shutemov [this message]
2014-05-27 10:27   ` Cyrill Gorcunov
2014-05-27 17:20     ` Cong Wang
2014-05-27 17:51       ` Cyrill Gorcunov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140527102013.3BF61E009B@blue.fi.intel.com \
    --to=kirill.shutemov@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=gorcunov@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=xemul@parallels.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).