From patchwork Fri Sep 11 07:15:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zorro Lang X-Patchwork-Id: 11769857 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6C75B746 for ; Fri, 11 Sep 2020 07:16:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4ADD922206 for ; Fri, 11 Sep 2020 07:16:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HO7R6zNU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725814AbgIKHQa (ORCPT ); Fri, 11 Sep 2020 03:16:30 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:43384 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725816AbgIKHQ2 (ORCPT ); Fri, 11 Sep 2020 03:16:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599808586; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h6bLJhg+hpwBXEj8Ow6M3waXC4yvl3tleXvO4BbZi1E=; b=HO7R6zNU+mqtqcNQrvGUYAsMvqJorxahNUesvSsXOijg02u9dnam0G7DX4unxIvKIaEGId FwUH3nk9t78M8eD3n+YbmvjRls01TfdoxTtQQR8E62eSJhoOSOnBRArVQjfocmMpO68rg0 jYMzgPblhqFjdeM1XKjF2NQ2CzI5Gfw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-552-6Xt6dmhiPqOqYWQCUt3jAQ-1; Fri, 11 Sep 2020 03:16:11 -0400 X-MC-Unique: 6Xt6dmhiPqOqYWQCUt3jAQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6AE4C8030D2 for ; Fri, 11 Sep 2020 07:16:10 +0000 (UTC) Received: from bogon.redhat.com (ovpn-12-40.pek2.redhat.com [10.72.12.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 85B141002D41 for ; Fri, 11 Sep 2020 07:16:09 +0000 (UTC) From: Zorro Lang To: fstests@vger.kernel.org Subject: [PATCH v5 1/5] fsstress: add IO_URING read and write operations Date: Fri, 11 Sep 2020 15:15:51 +0800 Message-Id: <20200911071555.31506-2-zlang@redhat.com> In-Reply-To: <20200911071555.31506-1-zlang@redhat.com> References: <20200911071555.31506-1-zlang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org IO_URING is a new feature of curent linux kernel, add basic IO_URING read/write into fsstess to cover this kind of IO testing. Signed-off-by: Zorro Lang Reviewed-by: Brian Foster --- README | 4 +- configure.ac | 1 + include/builddefs.in | 1 + ltp/Makefile | 5 ++ ltp/fsstress.c | 139 ++++++++++++++++++++++++++++++++++++++++- m4/Makefile | 1 + m4/package_liburing.m4 | 4 ++ 7 files changed, 152 insertions(+), 3 deletions(-) create mode 100644 m4/package_liburing.m4 diff --git a/README b/README index d0e23fcd..ae0f804d 100644 --- a/README +++ b/README @@ -8,13 +8,13 @@ _______________________ sudo apt-get install xfslibs-dev uuid-dev libtool-bin \ e2fsprogs automake gcc libuuid1 quota attr libattr1-dev make \ libacl1-dev libaio-dev xfsprogs libgdbm-dev gawk fio dbench \ - uuid-runtime python sqlite3 + uuid-runtime python sqlite3 liburing-dev For Fedora, RHEL, or CentOS: yum install acl attr automake bc dbench dump e2fsprogs fio \ gawk gcc indent libtool lvm2 make psmisc quota sed \ xfsdump xfsprogs \ libacl-devel libattr-devel libaio-devel libuuid-devel \ - xfsprogs-devel btrfs-progs-devel python sqlite + xfsprogs-devel btrfs-progs-devel python sqlite liburing-devel (Older distributions may require xfsprogs-qa-devel as well.) (Note that for RHEL and CentOS, you may need the EPEL repo.) - run make diff --git a/configure.ac b/configure.ac index 4bb50b32..8922c47e 100644 --- a/configure.ac +++ b/configure.ac @@ -61,6 +61,7 @@ AC_PACKAGE_NEED_ACLINIT_LIBACL AC_PACKAGE_WANT_GDBM AC_PACKAGE_WANT_AIO +AC_PACKAGE_WANT_URING AC_PACKAGE_WANT_DMAPI AC_PACKAGE_WANT_LINUX_FIEMAP_H AC_PACKAGE_WANT_FALLOCATE diff --git a/include/builddefs.in b/include/builddefs.in index e7894b1a..fded3230 100644 --- a/include/builddefs.in +++ b/include/builddefs.in @@ -61,6 +61,7 @@ RPM_VERSION = @rpm_version@ ENABLE_SHARED = @enable_shared@ HAVE_DB = @have_db@ HAVE_AIO = @have_aio@ +HAVE_URING = @have_uring@ HAVE_FALLOCATE = @have_fallocate@ HAVE_OPEN_BY_HANDLE_AT = @have_open_by_handle_at@ HAVE_DMAPI = @have_dmapi@ diff --git a/ltp/Makefile b/ltp/Makefile index ebf40336..198d930f 100644 --- a/ltp/Makefile +++ b/ltp/Makefile @@ -24,6 +24,11 @@ LCFLAGS += -DAIO LLDLIBS += -laio -lpthread endif +ifeq ($(HAVE_URING), true) +LCFLAGS += -DURING +LLDLIBS += -luring +endif + ifeq ($(HAVE_LIBBTRFSUTIL), true) LLDLIBS += -lbtrfsutil endif diff --git a/ltp/fsstress.c b/ltp/fsstress.c index 709fdeec..d28fcd75 100644 --- a/ltp/fsstress.c +++ b/ltp/fsstress.c @@ -30,6 +30,11 @@ #include io_context_t io_ctx; #endif +#ifdef URING +#include +#define URING_ENTRIES 1 +struct io_uring ring; +#endif #include #include @@ -139,6 +144,8 @@ typedef enum { OP_TRUNCATE, OP_UNLINK, OP_UNRESVSP, + OP_URING_READ, + OP_URING_WRITE, OP_WRITE, OP_WRITEV, OP_LAST @@ -267,6 +274,8 @@ void sync_f(int, long); void truncate_f(int, long); void unlink_f(int, long); void unresvsp_f(int, long); +void uring_read_f(int, long); +void uring_write_f(int, long); void write_f(int, long); void writev_f(int, long); char *xattr_flag_to_string(int); @@ -335,6 +344,8 @@ opdesc_t ops[] = { { OP_TRUNCATE, "truncate", truncate_f, 2, 1 }, { OP_UNLINK, "unlink", unlink_f, 1, 1 }, { OP_UNRESVSP, "unresvsp", unresvsp_f, 1, 1 }, + { OP_URING_READ, "uring_read", uring_read_f, 1, 0 }, + { OP_URING_WRITE, "uring_write", uring_write_f, 1, 1 }, { OP_WRITE, "write", write_f, 4, 1 }, { OP_WRITEV, "writev", writev_f, 4, 1 }, }, *ops_end; @@ -692,6 +703,12 @@ int main(int argc, char **argv) fprintf(stderr, "io_setup failed"); exit(1); } +#endif +#ifdef URING + if (io_uring_queue_init(URING_ENTRIES, &ring, 0)) { + fprintf(stderr, "io_uring_queue_init failed\n"); + exit(1); + } #endif for (i = 0; !loops || (i < loops); i++) doproc(); @@ -701,7 +718,9 @@ int main(int argc, char **argv) return 1; } #endif - +#ifdef URING + io_uring_queue_exit(&ring); +#endif cleanup_flist(); free(freq_table); return 0; @@ -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 = NULL; + int e; + pathname_t f; + int fd = -1; + 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_out; + } + 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_out; + } + 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_out; + } + 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_out; + } + 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_out; + } + 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_out; + } + 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_and_wait(&ring, 1)) != 1) { + if (v) + printf("%d/%d: %s - io_uring_submit failed %d\n", procid, opno, + iswrite ? "uring_write" : "uring_read", e); + goto uring_out; + } + 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_out; + } + if (v) + printf("%d/%d: %s %s%s [%lld, %d(res=%d)] %d\n", + procid, opno, iswrite ? "uring_write" : "uring_read", + f.path, st, (long long)off, (int)len, cqe->res, e); + io_uring_cqe_seen(&ring, cqe); + + uring_out: + if (buf) + free(buf); + if (fd != -1) + close(fd); + free_pathname(&f); +} +#endif + void aread_f(int opno, long r) { @@ -5044,6 +5165,22 @@ unresvsp_f(int opno, long r) close(fd); } +void +uring_read_f(int opno, long r) +{ +#ifdef URING + do_uring_rw(opno, r, O_RDONLY); +#endif +} + +void +uring_write_f(int opno, long r) +{ +#ifdef URING + do_uring_rw(opno, r, O_WRONLY); +#endif +} + void write_f(int opno, long r) { diff --git a/m4/Makefile b/m4/Makefile index 7fbff822..0352534d 100644 --- a/m4/Makefile +++ b/m4/Makefile @@ -14,6 +14,7 @@ LSRCFILES = \ package_dmapidev.m4 \ package_globals.m4 \ package_libcdev.m4 \ + package_liburing.m4 \ package_ncurses.m4 \ package_pthread.m4 \ package_ssldev.m4 \ diff --git a/m4/package_liburing.m4 b/m4/package_liburing.m4 new file mode 100644 index 00000000..c92cc02a --- /dev/null +++ b/m4/package_liburing.m4 @@ -0,0 +1,4 @@ +AC_DEFUN([AC_PACKAGE_WANT_URING], + [ AC_CHECK_HEADERS(liburing.h, [ have_uring=true ], [ have_uring=false ]) + AC_SUBST(have_uring) + ]) From patchwork Fri Sep 11 07:15:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zorro Lang X-Patchwork-Id: 11769849 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 93A71746 for ; Fri, 11 Sep 2020 07:16:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6662C21D81 for ; Fri, 11 Sep 2020 07:16:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CvyQsR1A" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725767AbgIKHQZ (ORCPT ); Fri, 11 Sep 2020 03:16:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:29684 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725766AbgIKHQR (ORCPT ); Fri, 11 Sep 2020 03:16:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599808575; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yucsKbL87LjM4TM3OZDclNFUAuNxAhk3GWjIVL0E4LI=; b=CvyQsR1Ab1Z+mnQXEl16RcOV4AyiitL2WEFeCUl3ngkbTKtK2cVSXh0o6oqJV6ZYmIohWh KH9mEFlHn4H2AVkEr3oc1lU1YhYESN4zsyULxSsfJx0raJbAdiOyLfqky4ahCn1TzA+rkZ nUO4TFS1f31X5BR5UoFs/Scy/2AobrU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-39-6kj73kIaNDuW9wjyPeOWGg-1; Fri, 11 Sep 2020 03:16:13 -0400 X-MC-Unique: 6kj73kIaNDuW9wjyPeOWGg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0DD64100854F for ; Fri, 11 Sep 2020 07:16:13 +0000 (UTC) Received: from bogon.redhat.com (ovpn-12-40.pek2.redhat.com [10.72.12.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3BC7810013BD for ; Fri, 11 Sep 2020 07:16:11 +0000 (UTC) From: Zorro Lang To: fstests@vger.kernel.org Subject: [PATCH v5 2/5] fsstress: reduce the number of events when io_setup Date: Fri, 11 Sep 2020 15:15:52 +0800 Message-Id: <20200911071555.31506-3-zlang@redhat.com> In-Reply-To: <20200911071555.31506-1-zlang@redhat.com> References: <20200911071555.31506-1-zlang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org The original number(128) of aio events for io_setup too big. When try to run lots of fsstress processes(e.g. -p 1000) always hit io_setup EAGAIN error, due to the nr_events exceeds the limit of available events. Due to each fsstress process only does once libaio read/write operation each time. So reduce the aio events number to 1, to make more fsstress processes can do AIO test. Signed-off-by: Zorro Lang Reviewed-by: Brian Foster --- ltp/fsstress.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ltp/fsstress.c b/ltp/fsstress.c index d28fcd75..68fbf7a5 100644 --- a/ltp/fsstress.c +++ b/ltp/fsstress.c @@ -28,6 +28,7 @@ #endif #ifdef AIO #include +#define AIO_ENTRIES 1 io_context_t io_ctx; #endif #ifdef URING @@ -699,8 +700,8 @@ int main(int argc, char **argv) } procid = i; #ifdef AIO - if (io_setup(128, &io_ctx) != 0) { - fprintf(stderr, "io_setup failed"); + if (io_setup(AIO_ENTRIES, &io_ctx) != 0) { + fprintf(stderr, "io_setup failed\n"); exit(1); } #endif From patchwork Fri Sep 11 07:15:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zorro Lang X-Patchwork-Id: 11769851 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DB00E1580 for ; Fri, 11 Sep 2020 07:16:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B988B22206 for ; Fri, 11 Sep 2020 07:16:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="jLZ/Ag1U" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725766AbgIKHQ0 (ORCPT ); Fri, 11 Sep 2020 03:16:26 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:21116 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725800AbgIKHQX (ORCPT ); Fri, 11 Sep 2020 03:16:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599808579; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xUX9+Uqronuw2LQLKM0qPs+cbua4QkBc9rAbkuj5dmI=; b=jLZ/Ag1UCgkvW7UYbmMfKZRHt4fa2sTR62L0f6lRHACF9hZuheEe2MquUEA0awliSji2a2 ZQ1G2tnqxQi6vQ6lQf9t7po7yz9KwEgPA2cQeJzrQRaAQJLx7hKQtpBEcuS1fRzwO9YYYr IAOet8LupTOUDEEu0Fd3SIfOhGHDMH0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-82-weOB55Z9PDi8a9ZHOcHNmA-1; Fri, 11 Sep 2020 03:16:17 -0400 X-MC-Unique: weOB55Z9PDi8a9ZHOcHNmA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D744C1008550 for ; Fri, 11 Sep 2020 07:16:16 +0000 (UTC) Received: from bogon.redhat.com (ovpn-12-40.pek2.redhat.com [10.72.12.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id E354210013BD for ; Fri, 11 Sep 2020 07:16:14 +0000 (UTC) From: Zorro Lang To: fstests@vger.kernel.org Subject: [PATCH v5 3/5] fsstress: fix memory leak in do_aio_rw Date: Fri, 11 Sep 2020 15:15:53 +0800 Message-Id: <20200911071555.31506-4-zlang@redhat.com> In-Reply-To: <20200911071555.31506-1-zlang@redhat.com> References: <20200911071555.31506-1-zlang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org If io_submit or io_getevents fails, the do_aio_rw() won't free the "buf" and cause memory leak. Signed-off-by: Zorro Lang Reviewed-by: Brian Foster --- ltp/fsstress.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/ltp/fsstress.c b/ltp/fsstress.c index 68fbf7a5..1238fcf5 100644 --- a/ltp/fsstress.c +++ b/ltp/fsstress.c @@ -2078,11 +2078,11 @@ void do_aio_rw(int opno, long r, int flags) { int64_t align; - char *buf; + char *buf = NULL; struct dioattr diob; int e; pathname_t f; - int fd; + int fd = -1; size_t len; int64_t lr; off64_t off; @@ -2099,8 +2099,7 @@ do_aio_rw(int opno, long r, int flags) if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) { if (v) printf("%d/%d: do_aio_rw - no filename\n", procid, opno); - free_pathname(&f); - return; + goto aio_out; } fd = open_path(&f, flags|O_DIRECT); e = fd < 0 ? errno : 0; @@ -2109,25 +2108,20 @@ do_aio_rw(int opno, long r, int flags) if (v) printf("%d/%d: do_aio_rw - open %s failed %d\n", procid, opno, f.path, e); - free_pathname(&f); - return; + goto aio_out; } if (fstat64(fd, &stb) < 0) { if (v) printf("%d/%d: do_aio_rw - fstat64 %s failed %d\n", procid, opno, f.path, errno); - free_pathname(&f); - close(fd); - return; + goto aio_out; } inode_info(st, sizeof(st), &stb, v); if (!iswrite && stb.st_size == 0) { if (v) printf("%d/%d: do_aio_rw - %s%s zero size\n", procid, opno, f.path, st); - free_pathname(&f); - close(fd); - return; + goto aio_out; } if (xfsctl(f.path, fd, XFS_IOC_DIOINFO, &diob) < 0) { if (v) @@ -2150,6 +2144,12 @@ do_aio_rw(int opno, long r, int flags) else if (len > diob.d_maxiosz) len = diob.d_maxiosz; buf = memalign(diob.d_mem, len); + if (!buf) { + if (v) + printf("%d/%d: do_aio_rw - memalign failed\n", + procid, opno); + goto aio_out; + } if (iswrite) { off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE)); @@ -2166,27 +2166,26 @@ do_aio_rw(int opno, long r, int flags) if (v) printf("%d/%d: %s - io_submit failed %d\n", procid, opno, iswrite ? "awrite" : "aread", e); - free_pathname(&f); - close(fd); - return; + goto aio_out; } if ((e = io_getevents(io_ctx, 1, 1, &event, NULL)) != 1) { if (v) printf("%d/%d: %s - io_getevents failed %d\n", procid, opno, iswrite ? "awrite" : "aread", e); - free_pathname(&f); - close(fd); - return; + goto aio_out; } e = event.res != len ? event.res2 : 0; - free(buf); if (v) printf("%d/%d: %s %s%s [%lld,%d] %d\n", procid, opno, iswrite ? "awrite" : "aread", f.path, st, (long long)off, (int)len, e); + aio_out: + if (buf) + free(buf); + if (fd != -1) + close(fd); free_pathname(&f); - close(fd); } #endif From patchwork Fri Sep 11 07:15:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zorro Lang X-Patchwork-Id: 11769853 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 22DF8159A for ; Fri, 11 Sep 2020 07:16:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EF44622208 for ; Fri, 11 Sep 2020 07:16:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EovliEpG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725800AbgIKHQ0 (ORCPT ); Fri, 11 Sep 2020 03:16:26 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:21556 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725562AbgIKHQY (ORCPT ); Fri, 11 Sep 2020 03:16:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599808582; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Rt6Kn4ld0tHdCI5yNqBMzjXzNbrsGJujxH5HRp8yV0A=; b=EovliEpGy41RUYtzewKibfeWzi+qKtpgNW2/Y4SUOPOEflvhFMZWCYjE5sp90UhY/tyB0C mAIfBJw7fbyC4HOEtmJ49Taxlw7qZiT5yr3oU1PIgP2Gt5GnFrZ4CfDp/YyQ8vF0UlgmG9 /O7DpJB2l+jU+hydEShj1cTbXsmOiHw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-445-i459qmqwOyup7wHYYU1DXw-1; Fri, 11 Sep 2020 03:16:20 -0400 X-MC-Unique: i459qmqwOyup7wHYYU1DXw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9BD8781F00B for ; Fri, 11 Sep 2020 07:16:19 +0000 (UTC) Received: from bogon.redhat.com (ovpn-12-40.pek2.redhat.com [10.72.12.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id AAE6C1001281 for ; Fri, 11 Sep 2020 07:16:18 +0000 (UTC) From: Zorro Lang To: fstests@vger.kernel.org Subject: [PATCH v5 4/5] fsx: introduce fsx_rw to combine aio_rw with general read and write Date: Fri, 11 Sep 2020 15:15:54 +0800 Message-Id: <20200911071555.31506-5-zlang@redhat.com> In-Reply-To: <20200911071555.31506-1-zlang@redhat.com> References: <20200911071555.31506-1-zlang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org The fsx contains different read and write operations, especially the AIO and general IO read/write. The fsx chooses one kind of read/write from AIO and general IO to run. To make the logic clear, use a common fsx_rw() function to swith between these two kinds of read/write. Signed-off-by: Zorro Lang Reviewed-by: Brian Foster --- ltp/fsx.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/ltp/fsx.c b/ltp/fsx.c index 7c76655a..92f506ba 100644 --- a/ltp/fsx.c +++ b/ltp/fsx.c @@ -181,16 +181,11 @@ int mark_nr = 0; int page_size; int page_mask; int mmap_mask; -#ifdef AIO -int aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset); +int fsx_rw(int rw, int fd, char *buf, unsigned len, unsigned offset); #define READ 0 #define WRITE 1 -#define fsxread(a,b,c,d) aio_rw(READ, a,b,c,d) -#define fsxwrite(a,b,c,d) aio_rw(WRITE, a,b,c,d) -#else -#define fsxread(a,b,c,d) read(a,b,c) -#define fsxwrite(a,b,c,d) write(a,b,c) -#endif +#define fsxread(a,b,c,d) fsx_rw(READ, a,b,c,d) +#define fsxwrite(a,b,c,d) fsx_rw(WRITE, a,b,c,d) const char *replayops = NULL; const char *recordops = NULL; @@ -2347,7 +2342,8 @@ getnum(char *s, char **e) io_context_t io_ctx; struct iocb iocb; -int aio_setup() +int +aio_setup() { int ret; ret = io_queue_init(QSZ, &io_ctx); @@ -2360,7 +2356,7 @@ int aio_setup() } int -__aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset) +aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset) { struct io_event event; static struct timespec ts; @@ -2425,13 +2421,21 @@ out_error: errno = -ret; return -1; } +#else +aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset) +{ + fprintf(stderr, "io_rw: need AIO support!\n"); + exit(111); +} +#endif -int aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset) +int +fsx_rw(int rw, int fd, char *buf, unsigned len, unsigned offset) { int ret; if (aio) { - ret = __aio_rw(rw, fd, buf, len, offset); + ret = aio_rw(rw, fd, buf, len, offset); } else { if (rw == READ) ret = read(fd, buf, len); @@ -2441,8 +2445,6 @@ int aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset) return ret; } -#endif - #define test_fallocate(mode) __test_fallocate(mode, #mode) int @@ -2602,7 +2604,7 @@ main(int argc, char **argv) do_fsync = 1; break; case 'A': - aio = 1; + aio = 1; break; case 'D': debugstart = getnum(optarg, &endp); From patchwork Fri Sep 11 07:15:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zorro Lang X-Patchwork-Id: 11769855 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 282221580 for ; Fri, 11 Sep 2020 07:16:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 052F221D81 for ; Fri, 11 Sep 2020 07:16:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="a9+f5XEN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725562AbgIKHQ3 (ORCPT ); Fri, 11 Sep 2020 03:16:29 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:46001 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725815AbgIKHQ1 (ORCPT ); Fri, 11 Sep 2020 03:16:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599808585; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nlhIGoXNfcqDJQ1A41DuftfwPhAVONhJpSYSNuyAfD4=; b=a9+f5XENzZXxeGkZDfmsMzV5t1Kxz7twW9TMXasX10iJUcq/63UEohkeIxFJRA5PhRVm63 yAWZhwEPRnsHlu9vd99oUJkVbAORSu+vjwbRB+IAMF00HwR/mol3cNtSTP+ZZrHTaZ9Lpv Rk6zT2rBj5A78gVvY8+++8BetoXq00U= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-225-xWGW3BUBNuGMzqCs4jUE-Q-1; Fri, 11 Sep 2020 03:16:24 -0400 X-MC-Unique: xWGW3BUBNuGMzqCs4jUE-Q-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4FABB64082 for ; Fri, 11 Sep 2020 07:16:23 +0000 (UTC) Received: from bogon.redhat.com (ovpn-12-40.pek2.redhat.com [10.72.12.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D4E21001281 for ; Fri, 11 Sep 2020 07:16:21 +0000 (UTC) From: Zorro Lang To: fstests@vger.kernel.org Subject: [PATCH v5 5/5] fsx: add IO_URING test Date: Fri, 11 Sep 2020 15:15:55 +0800 Message-Id: <20200911071555.31506-6-zlang@redhat.com> In-Reply-To: <20200911071555.31506-1-zlang@redhat.com> References: <20200911071555.31506-1-zlang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org New IO_URING test for fsx, use -U option to enable IO_URING test. Signed-off-by: Zorro Lang Reviewed-by: Brian Foster --- ltp/fsx.c | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 130 insertions(+), 3 deletions(-) diff --git a/ltp/fsx.c b/ltp/fsx.c index 92f506ba..0abd7de1 100644 --- a/ltp/fsx.c +++ b/ltp/fsx.c @@ -34,6 +34,9 @@ #ifdef AIO #include #endif +#ifdef URING +#include +#endif #include #ifndef MAP_FILE @@ -176,6 +179,7 @@ int integrity = 0; /* -i flag */ int fsxgoodfd = 0; int o_direct; /* -Z */ int aio = 0; +int uring = 0; int mark_nr = 0; int page_size; @@ -2237,7 +2241,7 @@ void usage(void) { fprintf(stdout, "usage: %s", - "fsx [-dknqxABEFJLOWZ] [-b opnum] [-c Prob] [-g filldata] [-i logdev] [-j logid] [-l flen] [-m start:end] [-o oplen] [-p progressinterval] [-r readbdy] [-s style] [-t truncbdy] [-w writebdy] [-D startingop] [-N numops] [-P dirpath] [-S seed] fname\n\ + "fsx [-dknqxBEFJLOWZ][-A|-U] [-b opnum] [-c Prob] [-g filldata] [-i logdev] [-j logid] [-l flen] [-m start:end] [-o oplen] [-p progressinterval] [-r readbdy] [-s style] [-t truncbdy] [-w writebdy] [-D startingop] [-N numops] [-P dirpath] [-S seed] fname\n\ -b opnum: beginning operation number (default 1)\n\ -c P: 1 in P chance of file close+open at each op (default infinity)\n\ -d: debug output for all operations\n\ @@ -2260,8 +2264,11 @@ usage(void) -y synchronize changes to a file\n" #ifdef AIO -" -A: Use the AIO system calls\n" +" -A: Use the AIO system calls, -A excludes -U\n" #endif +#ifdef URING +" -U: Use the IO_URING system calls, -U excludes -A\n" + #endif " -D startingop: debug output starting at specified operation\n" #ifdef HAVE_LINUX_FALLOC_H " -F: Do not use fallocate (preallocation) calls\n" @@ -2429,6 +2436,112 @@ aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset) } #endif +#ifdef URING + +struct io_uring ring; +#define URING_ENTRIES 1024 + +int +uring_setup() +{ + int ret; + + ret = io_uring_queue_init(URING_ENTRIES, &ring, 0); + if (ret != 0) { + fprintf(stderr, "uring_setup: io_uring_queue_init failed: %s\n", + strerror(ret)); + return -1; + } + return 0; +} + +int +uring_rw(int rw, int fd, char *buf, unsigned len, unsigned offset) +{ + struct io_uring_sqe *sqe; + struct io_uring_cqe *cqe; + struct iovec iovec; + int ret; + int res = 0; + char *p = buf; + unsigned l = len; + unsigned o = offset; + + /* + * Due to io_uring tries non-blocking IOs (especially read), that + * always cause 'normal' short reading. To avoid this short read + * fail, try to loop read/write (escpecilly read) data. + */ + while (l > 0) { + sqe = io_uring_get_sqe(&ring); + if (!sqe) { + fprintf(stderr, "uring_rw: io_uring_get_sqe failed: %s\n", + strerror(errno)); + return -1; + } + + iovec.iov_base = p; + iovec.iov_len = l; + if (rw == READ) { + io_uring_prep_readv(sqe, fd, &iovec, 1, o); + } else { + io_uring_prep_writev(sqe, fd, &iovec, 1, o); + } + + ret = io_uring_submit_and_wait(&ring, 1); + if (ret != 1) { + fprintf(stderr, "errcode=%d\n", -ret); + fprintf(stderr, "uring %s: io_uring_submit failed: %s\n", + rw == READ ? "read":"write", strerror(-ret)); + goto uring_error; + } + + ret = io_uring_wait_cqe(&ring, &cqe); + if (ret != 0) { + fprintf(stderr, "errcode=%d\n", -ret); + fprintf(stderr, "uring %s: io_uring_wait_cqe failed: %s\n", + rw == READ ? "read":"write", strerror(-ret)); + goto uring_error; + } + + ret = cqe->res; + io_uring_cqe_seen(&ring, cqe); + + if (ret > 0) { + o += ret; + l -= ret; + p += ret; + res += ret; + } else if (ret < 0) { + fprintf(stderr, "errcode=%d\n", -ret); + fprintf(stderr, "uring %s: io_uring failed: %s\n", + rw == READ ? "read":"write", strerror(-ret)); + goto uring_error; + } else { + fprintf(stderr, "uring %s bad io length: %d instead of %u\n", + rw == READ ? "read":"write", res, len); + break; + } + } + return res; + + uring_error: + /* + * The caller expects error return in traditional libc + * convention, i.e. -1 and the errno set to error. + */ + errno = -ret; + return -1; +} +#else +int +uring_rw(int rw, int fd, char *buf, unsigned len, unsigned offset) +{ + fprintf(stderr, "io_rw: need IO_URING support!\n"); + exit(111); +} +#endif + int fsx_rw(int rw, int fd, char *buf, unsigned len, unsigned offset) { @@ -2436,6 +2549,8 @@ fsx_rw(int rw, int fd, char *buf, unsigned len, unsigned offset) if (aio) { ret = aio_rw(rw, fd, buf, len, offset); + } else if (uring) { + ret = uring_rw(rw, fd, buf, len, offset); } else { if (rw == READ) ret = read(fd, buf, len); @@ -2498,7 +2613,7 @@ main(int argc, char **argv) setvbuf(stdout, (char *)0, _IOLBF, 0); /* line buffered stdout */ while ((ch = getopt_long(argc, argv, - "b:c:dfg:i:j:kl:m:no:p:qr:s:t:w:xyABD:EFJKHzCILN:OP:RS:WXZ", + "b:c:dfg:i:j:kl:m:no:p:qr:s:t:w:xyABD:EFJKHzCILN:OP:RS:UWXZ", longopts, NULL)) != EOF) switch (ch) { case 'b': @@ -2606,6 +2721,9 @@ main(int argc, char **argv) case 'A': aio = 1; break; + case 'U': + uring = 1; + break; case 'D': debugstart = getnum(optarg, &endp); if (debugstart < 1) @@ -2696,6 +2814,11 @@ main(int argc, char **argv) if (argc != 1) usage(); + if (aio && uring) { + fprintf(stderr, "-A and -U shouldn't be used together\n"); + usage(); + } + if (integrity && !dirpath) { fprintf(stderr, "option -i requires -P \n"); usage(); @@ -2786,6 +2909,10 @@ main(int argc, char **argv) if (aio) aio_setup(); #endif +#ifdef URING + if (uring) + uring_setup(); +#endif if (!(o_flags & O_TRUNC)) { off_t ret;