All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: "Theodore Ts'o" <tytso@mit.edu>
Cc: linux-ext4@vger.kernel.org, Andreas Dilger <andreas.dilger@intel.com>
Subject: [PATCH 23/25 v2] ext2fs: add readahead method to improve scanning
Date: Thu, 11 Sep 2014 14:29:49 -0700	[thread overview]
Message-ID: <20140911212949.GY10351@birch.djwong.org> (raw)
In-Reply-To: <20140911211031.GA17990@thunk.org>

Sure thing.  Here's the patch again, but with the test_io.c bits added.
---
From: Andreas Dilger <adilger@whamcloud.com>

Add a readahead method for prefetching ranges of disk blocks.  This is
useful for inode table scanning, and other large contiguous ranges of
blocks, and may also prove useful for random block prefetch, since it
will allow reordering of the IO without waiting synchronously for the
reads to complete.

It is currently using the posix_fadvise(POSIX_FADV_WILLNEED)
interface, as this proved most efficient during our testing.

[darrick.wong@oracle.com]
Make the arguments to the readahead function take the same ULL values
as the other IO functions, and return an appropriate error code when
fadvise isn't available.

v2: Plumb in test_io.c for cache readahead.

Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 lib/ext2fs/ext2_io.h    |    8 +++++++-
 lib/ext2fs/io_manager.c |    9 +++++++++
 lib/ext2fs/test_io.c    |   22 ++++++++++++++++++++++
 lib/ext2fs/unix_io.c    |   27 ++++++++++++++++++++++++---
 4 files changed, 62 insertions(+), 4 deletions(-)

diff --git a/lib/ext2fs/ext2_io.h b/lib/ext2fs/ext2_io.h
index 1894fb8..4c5a5c5 100644
--- a/lib/ext2fs/ext2_io.h
+++ b/lib/ext2fs/ext2_io.h
@@ -90,7 +90,10 @@ struct struct_io_manager {
 					int count, const void *data);
 	errcode_t (*discard)(io_channel channel, unsigned long long block,
 			     unsigned long long count);
-	long	reserved[16];
+	errcode_t (*cache_readahead)(io_channel channel,
+				     unsigned long long block,
+				     unsigned long long count);
+	long	reserved[15];
 };
 
 #define IO_FLAG_RW		0x0001
@@ -124,6 +127,9 @@ extern errcode_t io_channel_discard(io_channel channel,
 				    unsigned long long count);
 extern errcode_t io_channel_alloc_buf(io_channel channel,
 				      int count, void *ptr);
+extern errcode_t io_channel_cache_readahead(io_channel io,
+					    unsigned long long block,
+					    unsigned long long count);
 
 /* unix_io.c */
 extern io_manager unix_io_manager;
diff --git a/lib/ext2fs/io_manager.c b/lib/ext2fs/io_manager.c
index 34e4859..dc5888d 100644
--- a/lib/ext2fs/io_manager.c
+++ b/lib/ext2fs/io_manager.c
@@ -128,3 +128,12 @@ errcode_t io_channel_alloc_buf(io_channel io, int count, void *ptr)
 	else
 		return ext2fs_get_mem(size, ptr);
 }
+
+errcode_t io_channel_cache_readahead(io_channel io, unsigned long long block,
+				     unsigned long long count)
+{
+	if (!io->manager->cache_readahead)
+		return EXT2_ET_OP_NOT_SUPPORTED;
+
+	return io->manager->cache_readahead(io, block, count);
+}
diff --git a/lib/ext2fs/test_io.c b/lib/ext2fs/test_io.c
index 6f0d035..b03a939 100644
--- a/lib/ext2fs/test_io.c
+++ b/lib/ext2fs/test_io.c
@@ -85,6 +85,7 @@ void (*test_io_cb_write_byte)
 #define TEST_FLAG_DUMP			0x10
 #define TEST_FLAG_SET_OPTION		0x20
 #define TEST_FLAG_DISCARD		0x40
+#define TEST_FLAG_READAHEAD		0x80
 
 static void test_dump_block(io_channel channel,
 			    struct test_private_data *data,
@@ -486,6 +487,26 @@ static errcode_t test_discard(io_channel channel, unsigned long long block,
 	return retval;
 }
 
+static errcode_t test_cache_readahead(io_channel channel,
+				      unsigned long long block,
+				      unsigned long long count)
+{
+	struct test_private_data *data;
+	errcode_t	retval = 0;
+
+	EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
+	data = (struct test_private_data *) channel->private_data;
+	EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_TEST_IO_CHANNEL);
+
+	if (data->real)
+		retval = io_channel_cache_readahead(data->real, block, count);
+	if (data->flags & TEST_FLAG_READAHEAD)
+		fprintf(data->outfile,
+			"Test_io: readahead(%llu, %llu) returned %s\n",
+			block, count, retval ? error_message(retval) : "OK");
+	return retval;
+}
+
 static struct struct_io_manager struct_test_manager = {
 	.magic		= EXT2_ET_MAGIC_IO_MANAGER,
 	.name		= "Test I/O Manager",
@@ -501,6 +522,7 @@ static struct struct_io_manager struct_test_manager = {
 	.read_blk64	= test_read_blk64,
 	.write_blk64	= test_write_blk64,
 	.discard	= test_discard,
+	.cache_readahead	= test_cache_readahead,
 };
 
 io_manager test_io_manager = &struct_test_manager;
diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c
index eb39b28..189adce 100644
--- a/lib/ext2fs/unix_io.c
+++ b/lib/ext2fs/unix_io.c
@@ -15,6 +15,9 @@
  * %End-Header%
  */
 
+#define _XOPEN_SOURCE 600
+#define _DARWIN_C_SOURCE
+#define _FILE_OFFSET_BITS 64
 #define _LARGEFILE_SOURCE
 #define _LARGEFILE64_SOURCE
 #ifndef _GNU_SOURCE
@@ -35,6 +38,9 @@
 #ifdef __linux__
 #include <sys/utsname.h>
 #endif
+#if HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
 #ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #endif
@@ -44,9 +50,6 @@
 #if HAVE_SYS_STAT_H
 #include <sys/stat.h>
 #endif
-#if HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
 #if HAVE_SYS_RESOURCE_H
 #include <sys/resource.h>
 #endif
@@ -830,6 +833,23 @@ static errcode_t unix_write_blk64(io_channel channel, unsigned long long block,
 #endif /* NO_IO_CACHE */
 }
 
+static errcode_t unix_cache_readahead(io_channel channel,
+				      unsigned long long block,
+				      unsigned long long count)
+{
+#ifdef POSIX_FADV_WILLNEED
+	struct unix_private_data *data;
+
+	data = (struct unix_private_data *)channel->private_data;
+	return posix_fadvise(data->dev,
+			     (ext2_loff_t)block * channel->block_size,
+			     (ext2_loff_t)count * channel->block_size,
+			     POSIX_FADV_WILLNEED);
+#else
+	return EXT2_ET_OP_NOT_SUPPORTED;
+#endif
+}
+
 static errcode_t unix_write_blk(io_channel channel, unsigned long block,
 				int count, const void *buf)
 {
@@ -981,6 +1001,7 @@ static struct struct_io_manager struct_unix_manager = {
 	.read_blk64	= unix_read_blk64,
 	.write_blk64	= unix_write_blk64,
 	.discard	= unix_discard,
+	.cache_readahead	= unix_cache_readahead,
 };
 
 io_manager unix_io_manager = &struct_unix_manager;

  reply	other threads:[~2014-09-11 21:29 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-08 23:11 [PATCH 00/25] e2fsprogs Summer 2014 patchbomb, part 5.2 Darrick J. Wong
2014-09-08 23:11 ` [PATCH 01/25] e2fsck/debugfs: fix descriptor block size handling errors with journal_csum Darrick J. Wong
2014-09-11 16:43   ` Theodore Ts'o
2014-09-08 23:11 ` [PATCH 02/25] libext2fs: report bad magic over bad sb checksum Darrick J. Wong
2014-09-11 16:43   ` Theodore Ts'o
2014-09-08 23:11 ` [PATCH 03/25] misc: don't return ENOMEM if we run out of disk space Darrick J. Wong
2014-09-11 16:43   ` Theodore Ts'o
2014-09-08 23:12 ` [PATCH 04/25] libext2fs: write_journal_inode should check iterate return value Darrick J. Wong
2014-09-11 16:43   ` Theodore Ts'o
2014-09-08 23:12 ` [PATCH 05/25] mke2fs: allow creation of journal device with superblock checksum Darrick J. Wong
2014-09-11 16:43   ` Theodore Ts'o
2014-09-08 23:12 ` [PATCH 06/25] e2fsck: detect and repair external journal superblock checksum errors Darrick J. Wong
2014-09-11 16:43   ` Theodore Ts'o
2014-09-08 23:12 ` [PATCH 07/25] tune2fs: explicitly disallow tuning of journal devices Darrick J. Wong
2014-09-11 16:44   ` Theodore Ts'o
2014-09-08 23:12 ` [PATCH 08/25] dumpe2fs: display external journal feature flags Darrick J. Wong
2014-09-11 16:44   ` Theodore Ts'o
2014-09-08 23:12 ` [PATCH 09/25] misc: zero s_jnl_blocks when removing internal journal Darrick J. Wong
2014-09-11 16:44   ` Theodore Ts'o
2014-09-08 23:12 ` [PATCH 10/25] debugfs: create journal handling routines Darrick J. Wong
2014-09-11 18:53   ` Theodore Ts'o
2014-09-11 19:03     ` Darrick J. Wong
2014-09-11 20:14       ` Theodore Ts'o
2014-09-11 20:25         ` Darrick J. Wong
2014-09-08 23:12 ` [PATCH 11/25] e2fsck: fix minor errors in journal handling Darrick J. Wong
2014-09-11 20:58   ` Theodore Ts'o
2014-09-08 23:12 ` [PATCH 12/25] debugfs: add the ability to write transactions to the journal Darrick J. Wong
2014-09-11 20:58   ` Theodore Ts'o
2014-09-08 23:13 ` [PATCH 13/25] tests: test writing and recovering checksum-free 32/64bit journals Darrick J. Wong
2014-09-11 20:59   ` Theodore Ts'o
2014-09-08 23:13 ` [PATCH 14/25] tests: test writing and recovering 64bit csum_v3 journals Darrick J. Wong
2014-09-11 20:59   ` Theodore Ts'o
2014-09-08 23:13 ` [PATCH 15/25] tests: test writing and recovering 32bit " Darrick J. Wong
2014-09-11 20:59   ` Theodore Ts'o
2014-09-08 23:13 ` [PATCH 16/25] tests: write and replay blocks with the old journal checksum Darrick J. Wong
2014-09-11 20:59   ` Theodore Ts'o
2014-09-08 23:13 ` [PATCH 17/25] tests: test recovery of 32 and 64-bit journals with checksum v2 Darrick J. Wong
2014-09-11 20:59   ` Theodore Ts'o
2014-09-08 23:13 ` [PATCH 18/25] tests: test how e2fsck recovers from corrupt journal superblocks Darrick J. Wong
2014-09-11 21:04   ` Theodore Ts'o
2014-09-08 23:13 ` [PATCH 19/25] tests: test e2fsck recovery of corrupt revoke blocks Darrick J. Wong
2014-09-11 21:04   ` Theodore Ts'o
2014-09-08 23:13 ` [PATCH 20/25] tests: test e2fsck recovery with broken commit blocks Darrick J. Wong
2014-09-11 21:04   ` Theodore Ts'o
2014-09-08 23:13 ` [PATCH 21/25] tests: test e2fsck recovery of corrupt descriptor blocks Darrick J. Wong
2014-09-10  1:15   ` Darrick J. Wong
2014-09-11 17:33     ` Darrick J. Wong
2014-09-11 18:18       ` Theodore Ts'o
2014-09-11 18:40         ` Darrick J. Wong
2014-09-11 19:31   ` [PATCH 21/25 v2] " Darrick J. Wong
2014-09-11 22:34     ` Theodore Ts'o
2014-09-08 23:14 ` [PATCH 22/25] tests: test recovery from an external journal Darrick J. Wong
2014-09-11 21:04   ` Theodore Ts'o
2014-09-08 23:14 ` [PATCH 23/25] ext2fs: add readahead method to improve scanning Darrick J. Wong
2014-09-11 21:10   ` Theodore Ts'o
2014-09-11 21:29     ` Darrick J. Wong [this message]
2014-09-08 23:14 ` [PATCH 24/25] libext2fs/e2fsck: provide routines to read-ahead metadata Darrick J. Wong
2014-09-08 23:14 ` [PATCH 25/25] e2fsck: read-ahead metadata during passes 1, 2, and 4 Darrick J. Wong
2014-09-09 22:53 ` [PATCH 00/25] e2fsprogs Summer 2014 patchbomb, part 5.2 Andreas Dilger
2014-09-10  1:13   ` Darrick J. Wong
2014-09-11 19:41 ` [PATCH 26/25] libext2fs: call get_alloc_block hook when allocating blocks Darrick J. Wong
2014-09-11 22:05   ` Theodore Ts'o
2014-09-11 22:34     ` Darrick J. Wong
2014-09-12 17:35       ` Theodore Ts'o
2014-09-12 17:57         ` Darrick J. Wong
2014-09-12 22:17           ` Theodore Ts'o
2014-09-13  0:13             ` Darrick J. Wong
2014-09-11 19:43 ` [PATCH 27/25] tune2fs: always check disable_uninit_bg() return code Darrick J. Wong
2014-09-11 22:07   ` Theodore Ts'o
2014-09-11 19:44 ` [PATCH 28/25] e2fsck: ignore badblocks if it says badblocks inode is bad Darrick J. Wong
2014-09-11 22:09   ` Theodore Ts'o
2014-09-11 19:48 ` [PATCH 29/25] e2fsck: expand root dir if linking l+f fails Darrick J. Wong
2014-09-11 22:10   ` Theodore Ts'o
2014-09-11 20:17 ` [PATCH 30/25] libext2fs: check ea value offset when loading Darrick J. Wong
2014-09-11 22:11   ` Theodore Ts'o
2014-09-11 22:33 ` [PATCH 00/25] e2fsprogs Summer 2014 patchbomb, part 5.2 Theodore Ts'o
2014-09-11 22:50   ` Darrick J. Wong
2014-09-11 22:52     ` Theodore Ts'o
2014-09-11 23:07       ` Darrick J. Wong
2014-09-11 23:14         ` Theodore Ts'o
2014-09-11 23:30           ` Darrick J. Wong

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=20140911212949.GY10351@birch.djwong.org \
    --to=darrick.wong@oracle.com \
    --cc=andreas.dilger@intel.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.