linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] Add ioctl FITRIM.
@ 2010-08-04 13:44 Lukas Czerner
  2010-08-04 13:44 ` [PATCH 2/3] Add batched discard support for ext3 Lukas Czerner
                   ` (2 more replies)
  0 siblings, 3 replies; 24+ messages in thread
From: Lukas Czerner @ 2010-08-04 13:44 UTC (permalink / raw)
  To: linux-ext4; +Cc: jmoyer, rwheeler, eshishki, sandeen, jack, tytso, lczerner

Adds an filesystem independent ioctl to allow implementation of file
system batched discard support.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
---
 fs/ioctl.c         |   31 +++++++++++++++++++++++++++++++
 include/linux/fs.h |    2 ++
 2 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/fs/ioctl.c b/fs/ioctl.c
index 2d140a7..6c01c3c 100644
--- a/fs/ioctl.c
+++ b/fs/ioctl.c
@@ -540,6 +540,33 @@ static int ioctl_fsthaw(struct file *filp)
 	return thaw_super(sb);
 }
 
+static int ioctl_fstrim(struct file *filp, unsigned long arg)
+{
+	struct super_block *sb = filp->f_path.dentry->d_inode->i_sb;
+	unsigned int minlen;
+	int err;
+
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	/* If filesystem doesn't support trim feature, return. */
+	if (sb->s_op->trim_fs == NULL)
+		return -EOPNOTSUPP;
+
+	/* If a blockdevice-backed filesystem isn't specified, return EINVAL. */
+	if (sb->s_bdev == NULL)
+		return -EINVAL;
+
+	err = get_user(minlen, (unsigned int __user *) arg);
+	if (err)
+		return err;
+
+	err = sb->s_op->trim_fs(minlen, sb);
+	if (err)
+		return err;
+	return 0;
+}
+
 /*
  * When you add any new common ioctls to the switches above and below
  * please update compat_sys_ioctl() too.
@@ -590,6 +617,10 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd,
 		error = ioctl_fsthaw(filp);
 		break;
 
+	case FITRIM:
+		error = ioctl_fstrim(filp, arg);
+		break;
+
 	case FS_IOC_FIEMAP:
 		return ioctl_fiemap(filp, arg);
 
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 68ca1b0..01632e4 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -315,6 +315,7 @@ struct inodes_stat_t {
 #define FIGETBSZ   _IO(0x00,2)	/* get the block size used for bmap */
 #define FIFREEZE	_IOWR('X', 119, int)	/* Freeze */
 #define FITHAW		_IOWR('X', 120, int)	/* Thaw */
+#define FITRIM		_IOWR('X', 121, int)	/* Trim */
 
 #define	FS_IOC_GETFLAGS			_IOR('f', 1, long)
 #define	FS_IOC_SETFLAGS			_IOW('f', 2, long)
@@ -1580,6 +1581,7 @@ struct super_operations {
 	ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
 #endif
 	int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
+	int (*trim_fs) (unsigned int, struct super_block *);
 };
 
 /*
-- 
1.7.2


^ permalink raw reply related	[flat|nested] 24+ messages in thread
* [PATCH 0/3 ver. 7] Ext3/Ext4 Batched discard support
@ 2010-08-10 14:19 Lukas Czerner
  2010-08-10 14:19 ` [PATCH 3/3] Add batched discard support for ext4 Lukas Czerner
  0 siblings, 1 reply; 24+ messages in thread
From: Lukas Czerner @ 2010-08-10 14:19 UTC (permalink / raw)
  To: linux-ext4
  Cc: dmonakhov, jmoyer, rwheeler, eshishki, sandeen, jack, tytso,
	lczerner

Hi all,

this is "hopefully" the final version of the patch set, since it looks like
everyone agree with this. Since the last version some simple fixes was done.

- As Jan noticed it should subtract the s_first_data_block before modulo when
computing the group starting block.
- As Dimitry proposed cond_reshed() is really useless in the ext4_trim_extent
and rescheduling should be done in the ext4_trim_all_free.

Also from previous version it supports "partial" fs discard see [PATCH 1/3].

The patch set consist of these three patches. Second and third patch are
independent on each other and dependent on the first patch.

[PATCH 1/3] Add ioctl FITRIM.
[PATCH 2/3] Add batched discard support for ext3
[PATCH 3/3] Add batched discard support for ext4

Regards
-Lukas

---
 fs/ext3/balloc.c        |  250 +++++++++++++++++++++++++++++++++++++++++++++++
 fs/ext3/super.c         |    1 +
 fs/ext4/ext4.h          |    2 +
 fs/ext4/mballoc.c       |  200 +++++++++++++++++++++++++++++++++++++
 fs/ext4/super.c         |    1 +
 fs/ioctl.c              |   34 +++++++
 include/linux/ext3_fs.h |    1 +
 include/linux/fs.h      |    2 +
 8 files changed, 491 insertions(+), 0 deletions(-)

^ permalink raw reply	[flat|nested] 24+ messages in thread
* [PATCH 0/3] Batched discard support
@ 2010-08-06 11:31 Lukas Czerner
  2010-08-06 11:31 ` [PATCH 3/3] Add batched discard support for ext4 Lukas Czerner
  0 siblings, 1 reply; 24+ messages in thread
From: Lukas Czerner @ 2010-08-06 11:31 UTC (permalink / raw)
  To: linux-ext4
  Cc: dmonakhov, jmoyer, rwheeler, eshishki, sandeen, jack, tytso,
	lczerner

Hi, all

because people were worried about possibly long stalls appearing
when FITRIM ioctl is working, I have changed the FITRIM interface
as Dimitry suggested. Now you can choose whether to trim whole
file system or just a part of it, resp. you can specify the range
of Bytes to trim.

To be specific you can create something like this:

int main(int argc, char **argv)
{
	int fd;
	uint64_t range[3];

	range[0] = 40960;
	range[1] = 134217728;
	range[2] = 4096;

	fd = open(argv[1], O_RDONLY);
	if (fd < 0) {
		perror("open");
		return 1;
	}

	if (ioctl(fd, FITRIM, range)) {
		if (errno == EOPNOTSUPP)
			fprintf(stderr, "FITRIM not supported\n");
		else
			perror("FITRIM");
		return 1;
	}

	return 0;
}

Range items have following meaning:

range[0] - (start) first Byte to trim
range[1] - (len) number of Bytes to trim from start
range[2] - (minlen) minimum extent length to trim, free extents shorter
than this number of Bytes will be ignored. This number will be rounded
up to the block size.

So in my example it will trim all free extents from block 10 of first
alloc. group to block 10 of second alloc. group, assuming we have
block_size = 4096.

Also, when you want to trim the whole fs, you can simply pass NULL
instead of range into the ioctl, or you can specify the range correctly
to cover the whole fs.

Regards
-Lukas

[PATCH 1/3] Add ioctl FITRIM.
[PATCH 2/3] Add batched discard support for ext3
[PATCH 3/3] Add batched discard support for ext4

 fs/ext3/balloc.c        |  249 +++++++++++++++++++++++++++++++++++++++++++++++
 fs/ext3/super.c         |    1 +
 fs/ext4/ext4.h          |    2 +
 fs/ext4/mballoc.c       |  194 ++++++++++++++++++++++++++++++++++++
 fs/ext4/super.c         |    1 +
 fs/ioctl.c              |   34 +++++++
 include/linux/ext3_fs.h |    1 +
 include/linux/fs.h      |    2 +
 8 files changed, 484 insertions(+), 0 deletions(-)

^ permalink raw reply	[flat|nested] 24+ messages in thread
* [PATCH 0/3 v3] Batched discard support for Ext3/Ext4
@ 2010-07-27 12:41 Lukas Czerner
  2010-07-27 12:41 ` [PATCH 3/3] Add batched discard support for ext4 Lukas Czerner
  0 siblings, 1 reply; 24+ messages in thread
From: Lukas Czerner @ 2010-07-27 12:41 UTC (permalink / raw)
  To: linux-ext4; +Cc: jmoyer, rwheeler, eshishki, sandeen, jack, tytso

Hi all,

since my last post I have changed those patches slightly. Ext3 patch does
not introduce DISCARD/NODISCARD mount option, so there is just FITRIM
ioctl which can be invoked only by user with CAP_SYS_ADMIN.

Ext3 patch also involves journaling because as Jan pointed out not using
journal can cause problems when system crashes. Jan please look at this
I hope it is ok now. Also I am not sure if it would not be better to close
the journal after allocating free space and then start new one after
the TRIM (this was proposed by Josef Bacik).

Ext4 patch does not remove old "online" discard implementation and does not
check for DISCARD mount option. To avoid journaling I have used alloc_sem
semaphore to prevent allocations from the group while it is being trimmed.
It seems sufficient to me.

The general idea of batched discards stays the same. So when FITRIM ioctl
is invoked upon the mount point, it walks through all allocation groups
searching for free extents bigger than minlen, then trim those extents. In
ext3 consistency is assured by allocating these free extents in alloc. group
(with journal involved). In ext4 consistency is assured by use of alloc_sem
semaphore.

-Lukas

[PATCH 1/3] Add ioctl FITRIM.
[PATCH 2/3] Add batched discard support for ext3
[PATCH 3/3] Add batched discard support for ext4

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

end of thread, other threads:[~2010-08-10 14:20 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-04 13:44 [PATCH 1/3] Add ioctl FITRIM Lukas Czerner
2010-08-04 13:44 ` [PATCH 2/3] Add batched discard support for ext3 Lukas Czerner
2010-08-04 14:03   ` Jan Kara
2010-08-04 14:32     ` Lukas Czerner
2010-08-04 19:39   ` Andreas Dilger
2010-08-05 14:00     ` Lukas Czerner
2010-08-04 13:44 ` [PATCH 3/3] Add batched discard support for ext4 Lukas Czerner
2010-08-04 14:17   ` Jan Kara
2010-08-04 14:57 ` [PATCH 1/3] Add ioctl FITRIM Dmitry Monakhov
2010-08-04 15:13   ` Lukas Czerner
2010-08-04 15:26     ` Greg Freemyer
2010-08-05  0:28       ` Ted Ts'o
2010-08-05  6:51         ` Dmitry Monakhov
2010-08-05 15:47         ` Andreas Dilger
2010-08-05  7:00     ` Dmitry Monakhov
2010-08-05  8:36       ` Lukas Czerner
  -- strict thread matches above, loose matches on Subject: below --
2010-08-10 14:19 [PATCH 0/3 ver. 7] Ext3/Ext4 Batched discard support Lukas Czerner
2010-08-10 14:19 ` [PATCH 3/3] Add batched discard support for ext4 Lukas Czerner
2010-08-06 11:31 [PATCH 0/3] Batched discard support Lukas Czerner
2010-08-06 11:31 ` [PATCH 3/3] Add batched discard support for ext4 Lukas Czerner
2010-08-06 13:03   ` Dmitry Monakhov
2010-08-06 13:23     ` Lukas Czerner
2010-08-07 22:25   ` Jan Kara
2010-08-10 11:32     ` Lukas Czerner
2010-07-27 12:41 [PATCH 0/3 v3] Batched discard support for Ext3/Ext4 Lukas Czerner
2010-07-27 12:41 ` [PATCH 3/3] Add batched discard support for ext4 Lukas Czerner
2010-07-27 16:28   ` Jan Kara

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).