From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: dsterba@suse.cz
Subject: [PATCH 3/7] btrfs-progs: mkfs: Only zero out the first 1M for rootdir
Date: Fri, 20 Oct 2017 09:59:03 +0800 [thread overview]
Message-ID: <20171020015907.25430-4-wqu@suse.com> (raw)
In-Reply-To: <20171020015907.25430-1-wqu@suse.com>
It's a waste of IO to fill the whole image before creating btrfs on it,
just wiping the first 1M, and then write 1 byte to the last position to
create a sparse file.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
mkfs/main.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/mkfs/main.c b/mkfs/main.c
index 1355089505ca..7b78cfe3550e 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -404,18 +404,25 @@ static int zero_output_file(int out_fd, u64 size)
{
int loop_num;
u64 location = 0;
- char buf[4096];
+ char buf[SZ_4K];
int ret = 0, i;
ssize_t written;
- memset(buf, 0, 4096);
- loop_num = size / 4096;
+ memset(buf, 0, SZ_4K);
+
+ /* Only zero out the first 1M */
+ loop_num = SZ_1M / SZ_4K;
for (i = 0; i < loop_num; i++) {
- written = pwrite64(out_fd, buf, 4096, location);
- if (written != 4096)
+ written = pwrite64(out_fd, buf, SZ_4K, location);
+ if (written != SZ_4K)
ret = -EIO;
- location += 4096;
+ location += SZ_4K;
}
+
+ /* Then enlarge the file to size */
+ written = pwrite64(out_fd, buf, 1, size - 1);
+ if (written < 1)
+ ret = -EIO;
return ret;
}
--
2.14.2
next prev parent reply other threads:[~2017-10-20 1:59 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-20 1:59 [PATCH 0/7] btrfs-progs: mkfs: Reword --rootdir Qu Wenruo
2017-10-20 1:59 ` [PATCH 1/7] btrfs-progs: mkfs: Don't use custom chunk allocator for rootdir Qu Wenruo
2017-10-20 1:59 ` [PATCH 2/7] btrfs-progs: mkfs/rootdir: Use over-reserve method to make size estimate easier Qu Wenruo
2017-10-20 1:59 ` Qu Wenruo [this message]
2017-11-28 15:32 ` [PATCH 3/7] btrfs-progs: mkfs: Only zero out the first 1M for rootdir David Sterba
2017-10-20 1:59 ` [PATCH 4/7] btrfs-progs: mkfs/rootdir: Introduce function to get end position of last device extent Qu Wenruo
2017-11-28 15:36 ` David Sterba
2017-10-20 1:59 ` [PATCH 5/7] btrfs-progs: mkfs/rootdir: Shrink fs for rootdir option Qu Wenruo
2017-10-20 1:59 ` [PATCH 6/7] btrfs-progs: mkfs: Update allocation info before verbose output Qu Wenruo
2017-11-28 15:41 ` David Sterba
2017-10-20 1:59 ` [PATCH 7/7] btrfs-progs: mkfs: Separate shrink from rootdir Qu Wenruo
2017-11-20 20:15 ` [PATCH 0/7] btrfs-progs: mkfs: Reword --rootdir David Sterba
2017-11-28 15:44 ` David Sterba
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=20171020015907.25430-4-wqu@suse.com \
--to=wqu@suse.com \
--cc=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
/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).