All of lore.kernel.org
 help / color / mirror / Atom feed
* Ext4: batched discard support
@ 2010-04-19 10:55 Lukas Czerner
  2010-04-19 10:55 ` [PATCH 1/2] Add ioctl FITRIM Lukas Czerner
  2010-04-19 16:20 ` Ext4: batched discard support Greg Freemyer
  0 siblings, 2 replies; 54+ messages in thread
From: Lukas Czerner @ 2010-04-19 10:55 UTC (permalink / raw)
  To: linux-ext4
  Cc: Jeff Moyer, Edward Shishkin, Eric Sandeen, Ric Wheeler, Lukas Czerner

Hi all,

I would like to present a new way to deal with TRIM in ext4 file system.
The current solution is not ideal because of its bad performance impact.
So basic idea to improve things is to avoid discarding every time some
blocks are freed. and instead batching is together into bigger trims,
which tends to be more effective.

The basic idea behind my discard support is to create an ioctl which
walks through all the free extents in each allocating group and discard
those extents. As an addition to improve its performance one can specify
minimum free extent length, so ioctl will not bother with shorter extents.

This of course means, that with each invocation the ioctl must walk
through whole file system, checking and discarding free extents, which
is not very efficient. The best way to avoid this is to keep track of
deleted (freed) blocks. Then the ioctl have to trim just those free
extents which were recently freed.

In order to implement this I have added new bitmap into ext4_group_info
(bb_bitmap_deleted) which stores recently freed blocks. The ioctl then
walk through bb_bitmap_deleted, compare deleted extents with free
extents trim them and then removes it from the bb_bitmap_deleted. 

But you may notice, that there is one problem. bb_bitmap_deleted does
not survive umount. To bypass the problem the first ioctl call have to
walk through whole file system trimming all free extents. But there is a
better solution to this problem. The bb_bitmap_deleted can be stored on
disk an can be restored in mount time along with other bitmaps, but I
think it is a quite big change and should be discussed further.

I have also benchmarked it a little. You can find results here:

people.redhat.com/jmoyer/discard/ext4_batched_discard/

comparison with current solution included. Keep in mind that ideal ioctl
invocation interval is yet to be determined, so in benchmark I have used
the performance-worst scenario - without any sleep between execution.


There are two patches for this. The first one just creates file system
independent ioctl for this and the second one it the batched discard
support itself.

I will very much appreciate any comment on this, your opinions, ideas to
make this better etc. Thanks.

If you want to try it, just create EXT4 file system mount it and invoke
ioctl on the mount point. You can use following code for this (I have
taken this from xfs patch for the same thing). You can also see some
debugging messages, but you may want to set EXT4FS_DEBUG for this.

#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdint.h>
#include <sys/ioctl.h>

#define FITRIM		_IOWR('X', 121, int)

int main(int argc, char **argv)
{
	int minsize = 4096;
	int fd;

	if (argc != 2) {
		fprintf(stderr, "usage: %s mountpoint\n", argv[0]);
		return 1;
	}

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

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

	return 0;
}

 fs/ioctl.c         |   31 +++++++++++++++++++++++++++++++
 include/linux/fs.h |    2 ++
 2 files changed, 33 insertions(+), 0 deletions(-)

 fs/ext4/ext4.h    |    4 +
 fs/ext4/mballoc.c |  207 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 fs/ext4/super.c   |    1 +
 3 files changed, 202 insertions(+), 10 deletions(-)

^ permalink raw reply	[flat|nested] 54+ messages in thread
* Ext4: batched discard support - simplified version
@ 2010-07-07  7:53 Lukas Czerner
  2010-07-07  7:53 ` [PATCH 2/2] Add batched discard support for ext4 Lukas Czerner
  0 siblings, 1 reply; 54+ messages in thread
From: Lukas Czerner @ 2010-07-07  7:53 UTC (permalink / raw)
  To: eshishki; +Cc: lczerner, jmoyer, rwheeler, linux-ext4, sandeen


Hi all,

since my last post I have done some more testing with various SSD's and the
trend is clear. Trim performance is getting better and the performance loss
without trim is getting lower. So I have decided to abandon the initial idea
to track free blocks within some internal data structure - it takes time and
memory.

Today there are some SSD's which performance does not seems to degrade over
the time (writes). I have filled those devices up to 200% and still did not
seen any performance loss. On the other hand, there are still some devices
which shows about 300% performance degradation, so I suppose TRIM will be
still needed for some time.

You can try it out with the simple program attached below. Just create ext4
fs, mount it with -o discard and invoke attached program on ext4 mount point.

>From my experience the time needed to trim whole file system is strongly device
dependent. It may take few seconds on one device up to one minute on another,
under the heavy io load the time to trim whole fs gets longer.

There are two pathes:

[PATCH 1/2] Add ioctl FITRIM.
 fs/ioctl.c         |   31 +++++++++++++++++++++++++++++++
 include/linux/fs.h |    2 ++
 2 files changed, 33 insertions(+), 0 deletions(-)

[PATCH 2/2] Add batched discard support for ext4
 fs/ext4/ext4.h    |    2 +
 fs/ext4/mballoc.c |  126 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 fs/ext4/super.c   |    1 +
 3 files changed, 118 insertions(+), 11 deletions(-)

Signed-off-by: "Lukas Czerner" <lczerner@redhat.com>


#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdint.h>
#include <sys/ioctl.h>

#define FITRIM		_IOWR('X', 121, int)

int main(int argc, char **argv)
{
	int minsize = 4096;
	int fd;

	if (argc != 2) {
		fprintf(stderr, "usage: %s mountpoint\n", argv[0]);
		return 1;
	}

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

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

	return 0;
}

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

end of thread, other threads:[~2010-07-14 11:43 UTC | newest]

Thread overview: 54+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-19 10:55 Ext4: batched discard support Lukas Czerner
2010-04-19 10:55 ` [PATCH 1/2] Add ioctl FITRIM Lukas Czerner
2010-04-19 10:55   ` [PATCH 2/2] Add batched discard support for ext4 Lukas Czerner
2010-04-20 21:21     ` Greg Freemyer
2010-04-21  2:26       ` Mark Lord
2010-04-21  2:45         ` Eric Sandeen
2010-04-21 18:59           ` Greg Freemyer
2010-04-21 19:04             ` Ric Wheeler
2010-04-21 19:22               ` Jeff Moyer
2010-04-21 20:44                 ` Greg Freemyer
2010-04-21 20:53                   ` Greg Freemyer
2010-04-21 21:01                   ` Eric Sandeen
2010-04-21 21:03                     ` Ric Wheeler
2010-04-21 21:47                       ` Greg Freemyer
2010-04-21 21:56                         ` James Bottomley
2010-04-21 21:59                         ` Mark Lord
2010-04-23  8:23                   ` Lukas Czerner
2010-04-24 13:24                     ` Greg Freemyer
2010-04-24 13:48                       ` Ric Wheeler
2010-04-24 14:30                         ` Greg Freemyer
2010-04-24 14:43                           ` Eric Sandeen
2010-04-24 15:03                             ` Greg Freemyer
2010-04-24 17:04                               ` Ric Wheeler
2010-04-24 18:30                                 ` Greg Freemyer
2010-04-24 18:41                                   ` Ric Wheeler
2010-04-26 14:00                                     ` Mark Lord
2010-04-26 14:42                                       ` Martin K. Petersen
2010-04-26 15:27                                         ` Greg Freemyer
2010-04-26 15:51                                           ` Lukas Czerner
2010-04-28  1:25                                           ` Mark Lord
2010-04-26 15:48                                         ` Ric Wheeler
2010-04-24 19:06                                   ` Martin K. Petersen
2010-04-26 14:03                                     ` Mark Lord
2010-04-24 18:39                       ` Martin K. Petersen
2010-04-26 16:55                     ` Jan Kara
2010-04-26 17:46                       ` Lukas Czerner
2010-04-26 17:52                         ` Ric Wheeler
2010-04-26 18:14                           ` Lukas Czerner
2010-04-26 18:28                             ` Jeff Moyer
2010-04-26 18:38                               ` [PATCH 2/2] Add batched discard support for ext4 - using rbtree Lukas Czerner
2010-04-26 18:42                                 ` Lukas Czerner
2010-04-27 15:29                                   ` Edward Shishkin
2010-04-21 20:52                 ` [PATCH 2/2] Add batched discard support for ext4 Greg Freemyer
2010-04-19 16:20 ` Ext4: batched discard support Greg Freemyer
2010-04-19 16:30   ` Eric Sandeen
2010-04-19 17:58     ` Greg Freemyer
2010-04-19 18:04       ` Ric Wheeler
2010-04-20 20:24   ` Mark Lord
2010-04-20 20:34     ` Mark Lord
2010-07-07  7:53 Ext4: batched discard support - simplified version Lukas Czerner
2010-07-07  7:53 ` [PATCH 2/2] Add batched discard support for ext4 Lukas Czerner
2010-07-14  8:33   ` Dmitry Monakhov
2010-07-14  9:40     ` Lukas Czerner
2010-07-14 10:03       ` Dmitry Monakhov
2010-07-14 11:43         ` Lukas Czerner

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.