public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH liburing 0/3] test reg buffers more
@ 2020-12-06 12:51 Pavel Begunkov
  2020-12-06 12:51 ` [PATCH liburing 1/3] test/rw: name flags for clearness Pavel Begunkov
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Pavel Begunkov @ 2020-12-06 12:51 UTC (permalink / raw)
  To: Jens Axboe, io-uring

This test registered buffers with non-zero offsets and varying IO
lengths. The first 2 patches are just cleanups for the 3rd one.

Pavel Begunkov (3):
  test/rw: name flags for clearness
  test/rw: remove not used mixed_fixed flag
  test/rw: test reg bufs with non-align sizes/offset

 test/read-write.c | 111 ++++++++++++++++++++++++++++++++++------------
 1 file changed, 82 insertions(+), 29 deletions(-)

-- 
2.24.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH liburing 1/3] test/rw: name flags for clearness
  2020-12-06 12:51 [PATCH liburing 0/3] test reg buffers more Pavel Begunkov
@ 2020-12-06 12:51 ` Pavel Begunkov
  2020-12-06 12:51 ` [PATCH liburing 2/3] test/rw: remove not used mixed_fixed flag Pavel Begunkov
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2020-12-06 12:51 UTC (permalink / raw)
  To: Jens Axboe, io-uring

Replace obscure v1-v6 with more readable flag names.

Signed-off-by: Pavel Begunkov <[email protected]>
---
 test/read-write.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/test/read-write.c b/test/read-write.c
index 3bea26f..d47bebb 100644
--- a/test/read-write.c
+++ b/test/read-write.c
@@ -696,18 +696,19 @@ int main(int argc, char *argv[])
 		nr = 32;
 
 	for (i = 0; i < nr; i++) {
-		int v1, v2, v3, v4, v5, v6;
-
-		v1 = (i & 1) != 0;
-		v2 = (i & 2) != 0;
-		v3 = (i & 4) != 0;
-		v4 = (i & 8) != 0;
-		v5 = (i & 16) != 0;
-		v6 = (i & 32) != 0;
-		ret = test_io(fname, v1, v2, v3, v4, v5, v6);
+		int write = (i & 1) != 0;
+		int buffered = (i & 2) != 0;
+		int sqthread = (i & 4) != 0;
+		int fixed = (i & 8) != 0;
+		int mixed_fixed = (i & 16) != 0;
+		int nonvec = (i & 32) != 0;
+
+		ret = test_io(fname, write, buffered, sqthread, fixed,
+			      mixed_fixed, nonvec);
 		if (ret) {
 			fprintf(stderr, "test_io failed %d/%d/%d/%d/%d/%d\n",
-					v1, v2, v3, v4, v5, v6);
+					write, buffered, sqthread, fixed,
+					mixed_fixed, nonvec);
 			goto err;
 		}
 	}
-- 
2.24.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH liburing 2/3] test/rw: remove not used mixed_fixed flag
  2020-12-06 12:51 [PATCH liburing 0/3] test reg buffers more Pavel Begunkov
  2020-12-06 12:51 ` [PATCH liburing 1/3] test/rw: name flags for clearness Pavel Begunkov
@ 2020-12-06 12:51 ` Pavel Begunkov
  2020-12-06 12:51 ` [PATCH liburing 3/3] test/rw: test reg bufs with non-align sizes/offset Pavel Begunkov
  2020-12-07 15:49 ` [PATCH liburing 0/3] test reg buffers more Jens Axboe
  3 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2020-12-06 12:51 UTC (permalink / raw)
  To: Jens Axboe, io-uring

mixed_fixed is not used, kill it

Signed-off-by: Pavel Begunkov <[email protected]>
---
 test/read-write.c | 37 +++++++++++++++----------------------
 1 file changed, 15 insertions(+), 22 deletions(-)

diff --git a/test/read-write.c b/test/read-write.c
index d47bebb..2399c32 100644
--- a/test/read-write.c
+++ b/test/read-write.c
@@ -56,8 +56,8 @@ static int create_file(const char *file)
 	return ret != FILE_SIZE;
 }
 
-static int __test_io(const char *file, struct io_uring *ring, int write, int buffered,
-		     int sqthread, int fixed, int mixed_fixed, int nonvec,
+static int __test_io(const char *file, struct io_uring *ring, int write,
+		     int buffered, int sqthread, int fixed, int nonvec,
 		     int buf_select, int seq, int exp_len)
 {
 	struct io_uring_sqe *sqe;
@@ -67,10 +67,9 @@ static int __test_io(const char *file, struct io_uring *ring, int write, int buf
 	off_t offset;
 
 #ifdef VERBOSE
-	fprintf(stdout, "%s: start %d/%d/%d/%d/%d/%d: ", __FUNCTION__, write,
+	fprintf(stdout, "%s: start %d/%d/%d/%d/%d: ", __FUNCTION__, write,
 							buffered, sqthread,
-							fixed, mixed_fixed,
-							nonvec);
+							fixed, nonvec);
 #endif
 	if (sqthread && geteuid()) {
 #ifdef VERBOSE
@@ -239,7 +238,7 @@ err:
 	return 1;
 }
 static int test_io(const char *file, int write, int buffered, int sqthread,
-		   int fixed, int mixed_fixed, int nonvec)
+		   int fixed, int nonvec)
 {
 	struct io_uring ring;
 	int ret, ring_flags;
@@ -263,8 +262,8 @@ static int test_io(const char *file, int write, int buffered, int sqthread,
 		return 1;
 	}
 
-	ret = __test_io(file, &ring, write, buffered, sqthread, fixed,
-			mixed_fixed, nonvec, 0, 0, BS);
+	ret = __test_io(file, &ring, write, buffered, sqthread, fixed, nonvec,
+			0, 0, BS);
 
 	io_uring_queue_exit(&ring);
 	return ret;
@@ -442,7 +441,7 @@ static int test_buf_select_short(const char *filename, int nonvec)
 		io_uring_cqe_seen(&ring, cqe);
 	}
 
-	ret = __test_io(filename, &ring, 0, 0, 0, 0, 0, nonvec, 1, 1, exp_len);
+	ret = __test_io(filename, &ring, 0, 0, 0, 0, nonvec, 1, 1, exp_len);
 
 	io_uring_queue_exit(&ring);
 	return ret;
@@ -476,7 +475,7 @@ static int test_buf_select(const char *filename, int nonvec)
 	for (i = 0; i < BUFFERS; i++)
 		memset(vecs[i].iov_base, i, vecs[i].iov_len);
 
-	ret = __test_io(filename, &ring, 1, 0, 0, 0, 0, 0, 0, 1, BS);
+	ret = __test_io(filename, &ring, 1, 0, 0, 0, 0, 0, 1, BS);
 	if (ret) {
 		fprintf(stderr, "failed writing data\n");
 		return 1;
@@ -506,7 +505,7 @@ static int test_buf_select(const char *filename, int nonvec)
 		io_uring_cqe_seen(&ring, cqe);
 	}
 
-	ret = __test_io(filename, &ring, 0, 0, 0, 0, 0, nonvec, 1, 1, BS);
+	ret = __test_io(filename, &ring, 0, 0, 0, 0, nonvec, 1, 1, BS);
 
 	io_uring_queue_exit(&ring);
 	return ret;
@@ -690,25 +689,19 @@ int main(int argc, char *argv[])
 	}
 
 	/* if we don't have nonvec read, skip testing that */
-	if (has_nonvec_read())
-		nr = 64;
-	else
-		nr = 32;
+	nr = has_nonvec_read() ? 32 : 16;
 
 	for (i = 0; i < nr; i++) {
 		int write = (i & 1) != 0;
 		int buffered = (i & 2) != 0;
 		int sqthread = (i & 4) != 0;
 		int fixed = (i & 8) != 0;
-		int mixed_fixed = (i & 16) != 0;
-		int nonvec = (i & 32) != 0;
+		int nonvec = (i & 16) != 0;
 
-		ret = test_io(fname, write, buffered, sqthread, fixed,
-			      mixed_fixed, nonvec);
+		ret = test_io(fname, write, buffered, sqthread, fixed, nonvec);
 		if (ret) {
-			fprintf(stderr, "test_io failed %d/%d/%d/%d/%d/%d\n",
-					write, buffered, sqthread, fixed,
-					mixed_fixed, nonvec);
+			fprintf(stderr, "test_io failed %d/%d/%d/%d/%d\n",
+				write, buffered, sqthread, fixed, nonvec);
 			goto err;
 		}
 	}
-- 
2.24.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH liburing 3/3] test/rw: test reg bufs with non-align sizes/offset
  2020-12-06 12:51 [PATCH liburing 0/3] test reg buffers more Pavel Begunkov
  2020-12-06 12:51 ` [PATCH liburing 1/3] test/rw: name flags for clearness Pavel Begunkov
  2020-12-06 12:51 ` [PATCH liburing 2/3] test/rw: remove not used mixed_fixed flag Pavel Begunkov
@ 2020-12-06 12:51 ` Pavel Begunkov
  2020-12-07 15:49 ` [PATCH liburing 0/3] test reg buffers more Jens Axboe
  3 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2020-12-06 12:51 UTC (permalink / raw)
  To: Jens Axboe, io-uring

Broaden registered buffers coverage with registering buffers with
non-aligned random offsets and sizes. That in particular test how we're
setting and advancing in-kernel bvecs.

Pass exp_len==-1 for that, so it compares against iov_len with which it
was initialised. Also, direct IO requires alignment, so do it in
buffered mode.

Signed-off-by: Pavel Begunkov <[email protected]>
---
 test/read-write.c | 71 +++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 65 insertions(+), 6 deletions(-)

diff --git a/test/read-write.c b/test/read-write.c
index 2399c32..84ea3a2 100644
--- a/test/read-write.c
+++ b/test/read-write.c
@@ -37,6 +37,23 @@ static int create_buffers(void)
 	return 0;
 }
 
+static int create_nonaligned_buffers(void)
+{
+	int i;
+
+	vecs = malloc(BUFFERS * sizeof(struct iovec));
+	for (i = 0; i < BUFFERS; i++) {
+		char *p = malloc(3 * BS);
+
+		if (!p)
+			return 1;
+		vecs[i].iov_base = p + (rand() % BS);
+		vecs[i].iov_len = 1 + (rand() % BS);
+	}
+
+	return 0;
+}
+
 static int create_file(const char *file)
 {
 	ssize_t ret;
@@ -155,6 +172,7 @@ static int __test_io(const char *file, struct io_uring *ring, int write,
 			}
 
 		}
+		sqe->user_data = i;
 		if (sqthread)
 			sqe->flags |= IOSQE_FIXED_FILE;
 		if (buf_select) {
@@ -162,7 +180,6 @@ static int __test_io(const char *file, struct io_uring *ring, int write,
 				sqe->addr = 0;
 			sqe->flags |= IOSQE_BUFFER_SELECT;
 			sqe->buf_group = buf_select;
-			sqe->user_data = i;
 		}
 		if (seq)
 			offset += BS;
@@ -187,6 +204,14 @@ static int __test_io(const char *file, struct io_uring *ring, int write,
 				warned = 1;
 				no_read = 1;
 			}
+		} else if (exp_len == -1) {
+			int iov_len = vecs[cqe->user_data].iov_len;
+
+			if (cqe->res != iov_len) {
+				fprintf(stderr, "cqe res %d, wanted %d\n",
+					cqe->res, iov_len);
+				goto err;
+			}
 		} else if (cqe->res != exp_len) {
 			fprintf(stderr, "cqe res %d, wanted %d\n", cqe->res, exp_len);
 			goto err;
@@ -238,7 +263,7 @@ err:
 	return 1;
 }
 static int test_io(const char *file, int write, int buffered, int sqthread,
-		   int fixed, int nonvec)
+		   int fixed, int nonvec, int exp_len)
 {
 	struct io_uring ring;
 	int ret, ring_flags;
@@ -263,7 +288,7 @@ static int test_io(const char *file, int write, int buffered, int sqthread,
 	}
 
 	ret = __test_io(file, &ring, write, buffered, sqthread, fixed, nonvec,
-			0, 0, BS);
+			0, 0, exp_len);
 
 	io_uring_queue_exit(&ring);
 	return ret;
@@ -593,14 +618,15 @@ static int test_write_efbig(void)
 	struct io_uring_sqe *sqe;
 	struct io_uring_cqe *cqe;
 	struct io_uring ring;
-	struct rlimit rlim;
+	struct rlimit rlim, old_rlim;
 	int i, fd, ret;
 	loff_t off;
 
-	if (getrlimit(RLIMIT_FSIZE, &rlim) < 0) {
+	if (getrlimit(RLIMIT_FSIZE, &old_rlim) < 0) {
 		perror("getrlimit");
 		return 1;
 	}
+	rlim = old_rlim;
 	rlim.rlim_cur = 64 * 1024;
 	rlim.rlim_max = 64 * 1024;
 	if (setrlimit(RLIMIT_FSIZE, &rlim) < 0) {
@@ -660,6 +686,11 @@ static int test_write_efbig(void)
 	io_uring_queue_exit(&ring);
 	close(fd);
 	unlink(".efbig");
+
+	if (setrlimit(RLIMIT_FSIZE, &old_rlim) < 0) {
+		perror("setrlimit");
+		return 1;
+	}
 	return 0;
 err:
 	if (fd != -1)
@@ -698,7 +729,8 @@ int main(int argc, char *argv[])
 		int fixed = (i & 8) != 0;
 		int nonvec = (i & 16) != 0;
 
-		ret = test_io(fname, write, buffered, sqthread, fixed, nonvec);
+		ret = test_io(fname, write, buffered, sqthread, fixed, nonvec,
+			      BS);
 		if (ret) {
 			fprintf(stderr, "test_io failed %d/%d/%d/%d/%d\n",
 				write, buffered, sqthread, fixed, nonvec);
@@ -754,6 +786,33 @@ int main(int argc, char *argv[])
 		goto err;
 	}
 
+	srand((unsigned)time(NULL));
+	if (create_nonaligned_buffers()) {
+		fprintf(stderr, "file creation failed\n");
+		goto err;
+	}
+
+	/* test fixed bufs with non-aligned len/offset */
+	for (i = 0; i < nr; i++) {
+		int write = (i & 1) != 0;
+		int buffered = (i & 2) != 0;
+		int sqthread = (i & 4) != 0;
+		int fixed = (i & 8) != 0;
+		int nonvec = (i & 16) != 0;
+
+		/* direct IO requires alignment, skip it */
+		if (!buffered || !fixed || nonvec)
+			continue;
+
+		ret = test_io(fname, write, buffered, sqthread, fixed, nonvec,
+			      -1);
+		if (ret) {
+			fprintf(stderr, "test_io failed %d/%d/%d/%d/%d\n",
+				write, buffered, sqthread, fixed, nonvec);
+			goto err;
+		}
+	}
+
 	if (fname != argv[1])
 		unlink(fname);
 	return 0;
-- 
2.24.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH liburing 0/3] test reg buffers more
  2020-12-06 12:51 [PATCH liburing 0/3] test reg buffers more Pavel Begunkov
                   ` (2 preceding siblings ...)
  2020-12-06 12:51 ` [PATCH liburing 3/3] test/rw: test reg bufs with non-align sizes/offset Pavel Begunkov
@ 2020-12-07 15:49 ` Jens Axboe
  3 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2020-12-07 15:49 UTC (permalink / raw)
  To: Pavel Begunkov, io-uring

On 12/6/20 5:51 AM, Pavel Begunkov wrote:
> This test registered buffers with non-zero offsets and varying IO
> lengths. The first 2 patches are just cleanups for the 3rd one.
> 
> Pavel Begunkov (3):
>   test/rw: name flags for clearness
>   test/rw: remove not used mixed_fixed flag
>   test/rw: test reg bufs with non-align sizes/offset
> 
>  test/read-write.c | 111 ++++++++++++++++++++++++++++++++++------------
>  1 file changed, 82 insertions(+), 29 deletions(-)

Applied, thanks.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-12-07 15:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-06 12:51 [PATCH liburing 0/3] test reg buffers more Pavel Begunkov
2020-12-06 12:51 ` [PATCH liburing 1/3] test/rw: name flags for clearness Pavel Begunkov
2020-12-06 12:51 ` [PATCH liburing 2/3] test/rw: remove not used mixed_fixed flag Pavel Begunkov
2020-12-06 12:51 ` [PATCH liburing 3/3] test/rw: test reg bufs with non-align sizes/offset Pavel Begunkov
2020-12-07 15:49 ` [PATCH liburing 0/3] test reg buffers more Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox