From patchwork Fri Oct 20 01:59:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10018581 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 86BBA60234 for ; Fri, 20 Oct 2017 01:59:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77B4B28710 for ; Fri, 20 Oct 2017 01:59:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6CD16287AC; Fri, 20 Oct 2017 01:59:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5FA5228710 for ; Fri, 20 Oct 2017 01:59:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751888AbdJTB71 (ORCPT ); Thu, 19 Oct 2017 21:59:27 -0400 Received: from prv3-mh.provo.novell.com ([137.65.250.26]:54162 "EHLO prv3-mh.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751763AbdJTB7R (ORCPT ); Thu, 19 Oct 2017 21:59:17 -0400 Received: from adam-pc.lan (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by prv3-mh.provo.novell.com with ESMTP (NOT encrypted); Thu, 19 Oct 2017 19:59:13 -0600 From: Qu Wenruo 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 Message-Id: <20171020015907.25430-4-wqu@suse.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171020015907.25430-1-wqu@suse.com> References: <20171020015907.25430-1-wqu@suse.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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; }