* [PATCH] mke2fs: Inform user of ongoing discard
@ 2010-12-13 9:45 Lukas Czerner
2010-12-13 15:40 ` Tao Ma
0 siblings, 1 reply; 5+ messages in thread
From: Lukas Czerner @ 2010-12-13 9:45 UTC (permalink / raw)
To: linux-ext4; +Cc: tytso, lczerner
For some time now we are doing initial discard of the device prior to
filesystem creation. However, there is no feedback for the user and
hence on some devices with slow TRIM implementation it may appear that
mke2fs is stuck.
This commit introduce new function mke2fs_discard_device(), which is a
wrapper for io_channel_discard(). The discard is done per-partes and
discard progress is being reported back to the user. The discard step
has been set to 2GB size, which works reasonably well on both slow and
fast devices.
I gave up on doing fancy things like align discard according to
discard_alignment, checking for discard granularity and computing
estimate time. First of all, because it would require either new ioctl
to retrieve those information or use of libudev library, none of it
seems to be worth it. Regarding discard_granularity, I doubt there is
any sane device with discard granularity that big it would affect this.
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
---
misc/mke2fs.c | 55 ++++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 42 insertions(+), 13 deletions(-)
diff --git a/misc/mke2fs.c b/misc/mke2fs.c
index bc1211d..16b4826 100644
--- a/misc/mke2fs.c
+++ b/misc/mke2fs.c
@@ -72,6 +72,9 @@ extern int optind;
#define ZAP_BOOTBLOCK
#endif
+#define DISCARD_STEP_MB (2048)
+#define MB (1024*1024)
+
extern int isatty(int);
extern FILE *fpopen(const char *cmd, const char *mode);
@@ -1922,6 +1925,44 @@ static int mke2fs_setup_tdb(const char *name, io_manager *io_ptr)
return retval;
}
+static int mke2fs_discard_device(ext2_filsys fs)
+{
+ struct ext2fs_numeric_progress_struct progress;
+ blk64_t blocks = ext2fs_blocks_count(fs->super);
+ blk64_t count = DISCARD_STEP_MB;
+ blk64_t cur = 0;
+ int retval = 0;
+
+ count *= MB;
+ count /= fs->blocksize;
+
+ ext2fs_numeric_progress_init(fs, &progress,
+ _("Discarding device blocks: "),
+ blocks);
+ while (cur < blocks) {
+ ext2fs_numeric_progress_update(fs, &progress, cur);
+
+ retval = io_channel_discard(fs->io, cur, count, fs->blocksize);
+ if (retval)
+ break;
+
+ cur += count;
+ if (cur + count > blocks)
+ count = blocks - cur;
+ }
+
+ if (retval) {
+ ext2fs_numeric_progress_close(fs, &progress,
+ _("Error - "));
+ if (!quiet)
+ printf("%s\n",error_message(retval));
+ } else
+ ext2fs_numeric_progress_close(fs, &progress,
+ _("done \n"));
+
+ return retval;
+}
+
int main (int argc, char *argv[])
{
errcode_t retval = 0;
@@ -1982,19 +2023,7 @@ int main (int argc, char *argv[])
/* Can't undo discard ... */
if (discard && (io_ptr != undo_io_manager)) {
- blk64_t blocks = ext2fs_blocks_count(fs->super);
- if (verbose)
- printf(_("Calling BLKDISCARD from 0 to %llu... "),
- (unsigned long long) blocks);
- retval = io_channel_discard(fs->io, 0, blocks, fs->blocksize);
- if (verbose) {
- if (retval)
- printf(_("failed (%s)\n"),
- error_message(retval));
- else
- printf(_("succeeded\n"));
- }
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] mke2fs: Inform user of ongoing discard
2010-12-13 9:45 [PATCH] mke2fs: Inform user of ongoing discard Lukas Czerner
@ 2010-12-13 15:40 ` Tao Ma
2010-12-13 16:56 ` Lukas Czerner
0 siblings, 1 reply; 5+ messages in thread
From: Tao Ma @ 2010-12-13 15:40 UTC (permalink / raw)
To: Lukas Czerner; +Cc: linux-ext4, tytso
Hi Lukas,
On 12/13/2010 05:45 PM, Lukas Czerner wrote:
<snip>
> @@ -1922,6 +1925,44 @@ static int mke2fs_setup_tdb(const char *name, io_manager *io_ptr)
> return retval;
> }
>
> +static int mke2fs_discard_device(ext2_filsys fs)
> +{
> + struct ext2fs_numeric_progress_struct progress;
> + blk64_t blocks = ext2fs_blocks_count(fs->super);
> + blk64_t count = DISCARD_STEP_MB;
> + blk64_t cur = 0;
> + int retval = 0;
> +
> + count *= MB;
> + count /= fs->blocksize;
> +
> + ext2fs_numeric_progress_init(fs,&progress,
> + _("Discarding device blocks: "),
> + blocks);
> + while (cur< blocks) {
> + ext2fs_numeric_progress_update(fs,&progress, cur);
> +
> + retval = io_channel_discard(fs->io, cur, count, fs->blocksize);
Here we need to limit 'count' within ext4's block range for the 1st
round, otherwise it will discard the blocks outside our ext4 volume in
case the size is less than 2GB.
Regards,
Tao
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] mke2fs: Inform user of ongoing discard
2010-12-13 15:40 ` Tao Ma
@ 2010-12-13 16:56 ` Lukas Czerner
2010-12-13 17:08 ` Lukas Czerner
0 siblings, 1 reply; 5+ messages in thread
From: Lukas Czerner @ 2010-12-13 16:56 UTC (permalink / raw)
To: Tao Ma; +Cc: Lukas Czerner, linux-ext4, tytso
On Mon, 13 Dec 2010, Tao Ma wrote:
> Hi Lukas,
> On 12/13/2010 05:45 PM, Lukas Czerner wrote:
> <snip>
> > @@ -1922,6 +1925,44 @@ static int mke2fs_setup_tdb(const char *name,
> > io_manager *io_ptr)
> > return retval;
> > }
> >
> > +static int mke2fs_discard_device(ext2_filsys fs)
> > +{
> > + struct ext2fs_numeric_progress_struct progress;
> > + blk64_t blocks = ext2fs_blocks_count(fs->super);
> > + blk64_t count = DISCARD_STEP_MB;
> > + blk64_t cur = 0;
> > + int retval = 0;
> > +
> > + count *= MB;
> > + count /= fs->blocksize;
> > +
> > + ext2fs_numeric_progress_init(fs,&progress,
> > + _("Discarding device blocks: "),
> > + blocks);
> > + while (cur< blocks) {
> > + ext2fs_numeric_progress_update(fs,&progress, cur);
> > +
> > + retval = io_channel_discard(fs->io, cur, count,
> > fs->blocksize);
> Here we need to limit 'count' within ext4's block range for the 1st round,
> otherwise it will discard the blocks outside our ext4 volume in case the size
> is less than 2GB.
>
> Regards,
> Tao
>
Oh, of course. Thanks, I'll fix that.
-Lukas
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH] mke2fs: Inform user of ongoing discard
2010-12-13 16:56 ` Lukas Czerner
@ 2010-12-13 17:08 ` Lukas Czerner
2011-01-03 11:06 ` Lukas Czerner
0 siblings, 1 reply; 5+ messages in thread
From: Lukas Czerner @ 2010-12-13 17:08 UTC (permalink / raw)
To: linux-ext4; +Cc: tytso, lczerner, tm
For some time now we are doing initial discard of the device prior to
filesystem creation. However, there is no feedback for the user and
hence on some devices with slow TRIM implementation it may appear that
mke2fs is stuck.
This commit introduce new function mke2fs_discard_device(), which is a
wrapper for io_channel_discard(). The discard is done per-partes and
discard progress is being reported back to the user. The discard step
has been set to 2GB size, which works reasonably well on both slow and
fast devices.
I gave up on doing fancy things like align discard according to
discard_alignment, checking for discard granularity and computing
estimate time. First of all, because it would require either new ioctl
to retrieve those information or use of libudev library, none of it
seems to be worth it. Regarding discard_granularity, I doubt there is
any sane device with discard granularity that big it would affect this.
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
---
misc/mke2fs.c | 55 ++++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 42 insertions(+), 13 deletions(-)
diff --git a/misc/mke2fs.c b/misc/mke2fs.c
index bc1211d..75b07bb 100644
--- a/misc/mke2fs.c
+++ b/misc/mke2fs.c
@@ -72,6 +72,9 @@ extern int optind;
#define ZAP_BOOTBLOCK
#endif
+#define DISCARD_STEP_MB (2048)
+#define MB (1024*1024)
+
extern int isatty(int);
extern FILE *fpopen(const char *cmd, const char *mode);
@@ -1922,6 +1925,44 @@ static int mke2fs_setup_tdb(const char *name, io_manager *io_ptr)
return retval;
}
+static int mke2fs_discard_device(ext2_filsys fs)
+{
+ struct ext2fs_numeric_progress_struct progress;
+ blk64_t blocks = ext2fs_blocks_count(fs->super);
+ blk64_t count = DISCARD_STEP_MB;
+ blk64_t cur = 0;
+ int retval = 0;
+
+ count *= MB;
+ count /= fs->blocksize;
+
+ ext2fs_numeric_progress_init(fs, &progress,
+ _("Discarding device blocks: "),
+ blocks);
+ while (cur < blocks) {
+ ext2fs_numeric_progress_update(fs, &progress, cur);
+
+ if (cur + count > blocks)
+ count = blocks - cur;
+
+ retval = io_channel_discard(fs->io, cur, count, fs->blocksize);
+ if (retval)
+ break;
+ cur += count;
+ }
+
+ if (retval) {
+ ext2fs_numeric_progress_close(fs, &progress,
+ _("failed - "));
+ if (!quiet)
+ printf("%s\n",error_message(retval));
+ } else
+ ext2fs_numeric_progress_close(fs, &progress,
+ _("done \n"));
+
+ return retval;
+}
+
int main (int argc, char *argv[])
{
errcode_t retval = 0;
@@ -1982,19 +2023,7 @@ int main (int argc, char *argv[])
/* Can't undo discard ... */
if (discard && (io_ptr != undo_io_manager)) {
- blk64_t blocks = ext2fs_blocks_count(fs->super);
- if (verbose)
- printf(_("Calling BLKDISCARD from 0 to %llu... "),
- (unsigned long long) blocks);
- retval = io_channel_discard(fs->io, 0, blocks, fs->blocksize);
- if (verbose) {
- if (retval)
- printf(_("failed (%s)\n"),
- error_message(retval));
- else
- printf(_("succeeded\n"));
- }
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] mke2fs: Inform user of ongoing discard
2010-12-13 17:08 ` Lukas Czerner
@ 2011-01-03 11:06 ` Lukas Czerner
0 siblings, 0 replies; 5+ messages in thread
From: Lukas Czerner @ 2011-01-03 11:06 UTC (permalink / raw)
To: Lukas Czerner; +Cc: linux-ext4, tytso, tm
On Mon, 13 Dec 2010, Lukas Czerner wrote:
> For some time now we are doing initial discard of the device prior to
> filesystem creation. However, there is no feedback for the user and
> hence on some devices with slow TRIM implementation it may appear that
> mke2fs is stuck.
>
> This commit introduce new function mke2fs_discard_device(), which is a
> wrapper for io_channel_discard(). The discard is done per-partes and
> discard progress is being reported back to the user. The discard step
> has been set to 2GB size, which works reasonably well on both slow and
> fast devices.
>
> I gave up on doing fancy things like align discard according to
> discard_alignment, checking for discard granularity and computing
> estimate time. First of all, because it would require either new ioctl
> to retrieve those information or use of libudev library, none of it
> seems to be worth it. Regarding discard_granularity, I doubt there is
> any sane device with discard granularity that big it would affect this.
>
> Signed-off-by: Lukas Czerner <lczerner@redhat.com>
> ---
> misc/mke2fs.c | 55 ++++++++++++++++++++++++++++++++++++++++++-------------
> 1 files changed, 42 insertions(+), 13 deletions(-)
>
> diff --git a/misc/mke2fs.c b/misc/mke2fs.c
> index bc1211d..75b07bb 100644
> --- a/misc/mke2fs.c
> +++ b/misc/mke2fs.c
> @@ -72,6 +72,9 @@ extern int optind;
> #define ZAP_BOOTBLOCK
> #endif
>
> +#define DISCARD_STEP_MB (2048)
> +#define MB (1024*1024)
> +
> extern int isatty(int);
> extern FILE *fpopen(const char *cmd, const char *mode);
>
> @@ -1922,6 +1925,44 @@ static int mke2fs_setup_tdb(const char *name, io_manager *io_ptr)
> return retval;
> }
>
> +static int mke2fs_discard_device(ext2_filsys fs)
> +{
> + struct ext2fs_numeric_progress_struct progress;
> + blk64_t blocks = ext2fs_blocks_count(fs->super);
> + blk64_t count = DISCARD_STEP_MB;
> + blk64_t cur = 0;
> + int retval = 0;
> +
> + count *= MB;
> + count /= fs->blocksize;
> +
> + ext2fs_numeric_progress_init(fs, &progress,
> + _("Discarding device blocks: "),
> + blocks);
> + while (cur < blocks) {
> + ext2fs_numeric_progress_update(fs, &progress, cur);
> +
> + if (cur + count > blocks)
> + count = blocks - cur;
> +
> + retval = io_channel_discard(fs->io, cur, count, fs->blocksize);
> + if (retval)
> + break;
> + cur += count;
> + }
> +
> + if (retval) {
> + ext2fs_numeric_progress_close(fs, &progress,
> + _("failed - "));
> + if (!quiet)
> + printf("%s\n",error_message(retval));
> + } else
> + ext2fs_numeric_progress_close(fs, &progress,
> + _("done \n"));
> +
> + return retval;
> +}
> +
> int main (int argc, char *argv[])
> {
> errcode_t retval = 0;
> @@ -1982,19 +2023,7 @@ int main (int argc, char *argv[])
>
> /* Can't undo discard ... */
> if (discard && (io_ptr != undo_io_manager)) {
> - blk64_t blocks = ext2fs_blocks_count(fs->super);
> - if (verbose)
> - printf(_("Calling BLKDISCARD from 0 to %llu... "),
> - (unsigned long long) blocks);
> - retval = io_channel_discard(fs->io, 0, blocks, fs->blocksize);
> - if (verbose) {
> - if (retval)
> - printf(_("failed (%s)\n"),
> - error_message(retval));
> - else
> - printf(_("succeeded\n"));
> - }
> -
> + retval = mke2fs_discard_device(fs);
> if (!retval && io_channel_discard_zeroes_data(fs->io)) {
> if (verbose)
> printf(_("Discard succeeded and will return 0s "
>
Hi Ted,
what is the status of this patch ?
Thanks!
-Lukas
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-01-03 11:06 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-13 9:45 [PATCH] mke2fs: Inform user of ongoing discard Lukas Czerner
2010-12-13 15:40 ` Tao Ma
2010-12-13 16:56 ` Lukas Czerner
2010-12-13 17:08 ` Lukas Czerner
2011-01-03 11:06 ` Lukas Czerner
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).