linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Huang Jianan <huangjianan@oppo.com>
To: linux-erofs@lists.ozlabs.org
Cc: huangjianan@oppo.com, guoweichao@oppo.com, zhangshiming@oppo.com,
	linux-kernel@vger.kernel.org
Subject: [PATCH] fsstress: support direct IO
Date: Mon, 14 Dec 2020 22:04:28 +0800	[thread overview]
Message-ID: <20201214140428.44944-2-huangjianan@oppo.com> (raw)
In-Reply-To: <20201214140428.44944-1-huangjianan@oppo.com>

From: huangjianan <huangjianan@oppo.com>

add direct IO test for the stress tool which was mentioned here:
https://lore.kernel.org/linux-erofs/20200206135631.1491-1-hsiangkao@aol.com/

Signed-off-by: Huang Jianan <huangjianan@oppo.com>
Signed-off-by: Guo Weichao <guoweichao@oppo.com>
---
 stress.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/stress.c b/stress.c
index f4bf874..7e7cc93 100644
--- a/stress.c
+++ b/stress.c
@@ -4,12 +4,14 @@
  *
  * Copyright (C) 2019-2020 Gao Xiang <hsiangkao@aol.com>
  */
+#define _GNU_SOURCE
 #define _LARGEFILE64_SOURCE
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
+#include <stdbool.h>
 #include <string.h>
 #include <sys/types.h>
 #include <sys/wait.h>
@@ -21,6 +23,7 @@
 #define MAX_CHUNKSIZE	(4 * 1024 * 1024)
 #define MAX_SCAN_CHUNKSIZE	(256 * 1024)
 
+bool direct_io = false;
 unsigned int nprocs = 512;
 sig_atomic_t should_stop = 0;
 
@@ -98,7 +101,7 @@ int drop_file_cache(int fd, int mode)
 
 int tryopen(char *filename)
 {
-	int fd = open(filename, O_RDONLY);
+	int fd = open(filename, direct_io ? O_RDONLY : O_RDONLY | O_DIRECT);
 
 	if (fd < 0)
 		return -errno;
@@ -166,6 +169,13 @@ int randread(int fd, int chkfd, uint64_t filesize)
 	if (start + length > filesize)
 		length = filesize - start;
 
+	if (direct_io) {
+		length = (((length - 1) >> PAGE_SHIFT) + 1)
+			<< PAGE_SHIFT;
+		if (!length || start + length > filesize)
+			return 0;
+	}
+
 	printf("randread(%u): %llu bytes @ %llu\n",
 	       getpid(), (unsigned long long)length,
 	       (unsigned long long)start);
@@ -212,7 +222,7 @@ int testfd(int fd, int chkfd, int mode)
 		err = doscan(fd, chkfd, filesize, chunksize);
 		if (err)
 			return err;
-	} else if (mode == RANDSCAN_UNALIGNED) {
+	} else if (mode == RANDSCAN_UNALIGNED && !direct_io) {
 		chunksize = (random() * random() % MAX_SCAN_CHUNKSIZE) + 1;
 		err = doscan(fd, chkfd, filesize, chunksize);
 		if (err)
@@ -252,8 +262,11 @@ static int parse_options(int argc, char *argv[])
 {
 	int opt;
 
-	while ((opt = getopt(argc, argv, "p:")) != -1) {
+	while ((opt = getopt(argc, argv, "dp:")) != -1) {
 		switch (opt) {
+		case 'd':
+			direct_io = true;
+			break;
 		case 'p':
 			nprocs = atoi(optarg);
 			if (nprocs < 0) {
@@ -281,6 +294,7 @@ void usage(void)
 {
 	fputs("usage: [options] TESTFILE [COMPRFILE]\n\n"
 	      "stress tester for read-only filesystems\n"
+	      " -d      use direct io\n"
 	      " -p#     set workers to #\n", stderr);
 }
 
-- 
2.7.4


  reply	other threads:[~2020-12-14 14:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-14 14:04 [PATCH] erofs: support direct IO for uncompressed file Huang Jianan
2020-12-14 14:04 ` Huang Jianan [this message]
2020-12-22 13:21 ` Gao Xiang
2020-12-22 14:22 ` Christoph Hellwig
2020-12-22 19:39   ` Gao Xiang
2020-12-23  7:44     ` Christoph Hellwig
2020-12-23  8:48       ` Huang Jianan
2020-12-23  8:54         ` Christoph Hellwig
2020-12-23  9:03           ` Gao Xiang

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=20201214140428.44944-2-huangjianan@oppo.com \
    --to=huangjianan@oppo.com \
    --cc=guoweichao@oppo.com \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=zhangshiming@oppo.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).