fstests.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zorro Lang <zlang@redhat.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: fstests@vger.kernel.org, io-uring@vger.kernel.org, jmoyer@redhat.com
Subject: Re: [PATCH v2 1/4] fsstress: add IO_URING read and write operations
Date: Sun, 23 Aug 2020 02:14:46 +0800	[thread overview]
Message-ID: <20200822181445.GS2937@dhcp-12-102.nay.redhat.com> (raw)
In-Reply-To: <01c7353f-338b-99cd-d7d1-fe92b0badd84@kernel.dk>

On Sun, Aug 09, 2020 at 11:51:45AM -0600, Jens Axboe wrote:
> On 8/9/20 12:30 AM, Zorro Lang wrote:
> > @@ -2170,6 +2189,108 @@ do_aio_rw(int opno, long r, int flags)
> >  }
> >  #endif
> >  
> > +#ifdef URING
> > +void
> > +do_uring_rw(int opno, long r, int flags)
> > +{
> > +	char		*buf;
> > +	int		e;
> > +	pathname_t	f;
> > +	int		fd;
> > +	size_t		len;
> > +	int64_t		lr;
> > +	off64_t		off;
> > +	struct stat64	stb;
> > +	int		v;
> > +	char		st[1024];
> > +	struct io_uring_sqe	*sqe;
> > +	struct io_uring_cqe	*cqe;
> > +	struct iovec	iovec;
> > +	int		iswrite = (flags & (O_WRONLY | O_RDWR)) ? 1 : 0;
> > +
> > +	init_pathname(&f);
> > +	if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
> > +		if (v)
> > +			printf("%d/%d: do_uring_rw - no filename\n", procid, opno);
> > +		goto uring_out3;
> > +	}
> > +	fd = open_path(&f, flags);
> > +	e = fd < 0 ? errno : 0;
> > +	check_cwd();
> > +	if (fd < 0) {
> > +		if (v)
> > +			printf("%d/%d: do_uring_rw - open %s failed %d\n",
> > +			       procid, opno, f.path, e);
> > +		goto uring_out3;
> > +	}
> > +	if (fstat64(fd, &stb) < 0) {
> > +		if (v)
> > +			printf("%d/%d: do_uring_rw - fstat64 %s failed %d\n",
> > +			       procid, opno, f.path, errno);
> > +		goto uring_out2;
> > +	}
> > +	inode_info(st, sizeof(st), &stb, v);
> > +	if (!iswrite && stb.st_size == 0) {
> > +		if (v)
> > +			printf("%d/%d: do_uring_rw - %s%s zero size\n", procid, opno,
> > +			       f.path, st);
> > +		goto uring_out2;
> > +	}
> > +	sqe = io_uring_get_sqe(&ring);
> > +	if (!sqe) {
> > +		if (v)
> > +			printf("%d/%d: do_uring_rw - io_uring_get_sqe failed\n",
> > +			       procid, opno);
> > +		goto uring_out2;
> > +	}
> > +	lr = ((int64_t)random() << 32) + random();
> > +	len = (random() % FILELEN_MAX) + 1;
> > +	buf = malloc(len);
> > +	if (!buf) {
> > +		if (v)
> > +			printf("%d/%d: do_uring_rw - malloc failed\n",
> > +			       procid, opno);
> > +		goto uring_out2;
> > +	}
> > +	iovec.iov_base = buf;
> > +	iovec.iov_len = len;
> > +	if (iswrite) {
> > +		off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
> > +		off %= maxfsize;
> > +		memset(buf, nameseq & 0xff, len);
> > +		io_uring_prep_writev(sqe, fd, &iovec, 1, off);
> > +	} else {
> > +		off = (off64_t)(lr % stb.st_size);
> > +		io_uring_prep_readv(sqe, fd, &iovec, 1, off);
> > +	}
> > +
> > +	if ((e = io_uring_submit(&ring)) != 1) {
> > +		if (v)
> > +			printf("%d/%d: %s - io_uring_submit failed %d\n", procid, opno,
> > +			       iswrite ? "uring_write" : "uring_read", e);
> > +		goto uring_out1;
> > +	}
> > +	if ((e = io_uring_wait_cqe(&ring, &cqe)) < 0) {
> > +		if (v)
> > +			printf("%d/%d: %s - io_uring_wait_cqe failed %d\n", procid, opno,
> > +			       iswrite ? "uring_write" : "uring_read", e);
> > +		goto uring_out1;
> > +	}
> 
> You could use io_uring_submit_and_wait() here, that'll save a system
> call for sync IO. Same comment goes for 4/4.

Hi Jens,

Sorry I think I haven't learned about io_uring enough, why the
io_uring_submit_and_wait can save a system call? Is it same with
io_uring_submit(), except a wait_nr ? The io_uring_wait_cqe() and
io_uring_cqe_seen() are still needed, right?

Thanks,
Zorro

> 
> Apart from that, looks pretty straight forward to me.
> 
> -- 
> Jens Axboe
> 


  reply	other threads:[~2020-08-22 18:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-09  6:30 [PATCH v2 0/4] fsstress,fsx: add io_uring test and do some fix Zorro Lang
2020-08-09  6:30 ` [PATCH v2 1/4] fsstress: add IO_URING read and write operations Zorro Lang
2020-08-09 17:51   ` Jens Axboe
2020-08-22 18:14     ` Zorro Lang [this message]
2020-08-22 18:05       ` Jens Axboe
2020-08-09  6:30 ` [PATCH v2 2/4] fsstress: reduce the number of events when io_setup Zorro Lang
2020-08-09  6:30 ` [PATCH v2 3/4] fsstress: fix memory leak in do_aio_rw Zorro Lang
2020-08-09  6:30 ` [PATCH v2 4/4] fsx: add IO_URING test Zorro Lang

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=20200822181445.GS2937@dhcp-12-102.nay.redhat.com \
    --to=zlang@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=fstests@vger.kernel.org \
    --cc=io-uring@vger.kernel.org \
    --cc=jmoyer@redhat.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).