From patchwork Wed Sep 2 15:35:04 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Tao X-Patchwork-Id: 32841 Return-Path: X-Original-To: patchwork-incoming@bilbo.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (ozlabs.org [203.10.76.45]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mx.ozlabs.org", Issuer "CA Cert Signing Authority" (verified OK)) by bilbo.ozlabs.org (Postfix) with ESMTPS id DFFF1B7099 for ; Thu, 3 Sep 2009 01:36:04 +1000 (EST) Received: by ozlabs.org (Postfix) id C7138DDD0B; Thu, 3 Sep 2009 01:36:04 +1000 (EST) Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id 5382EDDD01 for ; Thu, 3 Sep 2009 01:36:04 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752670AbZIBPf7 (ORCPT ); Wed, 2 Sep 2009 11:35:59 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752721AbZIBPf7 (ORCPT ); Wed, 2 Sep 2009 11:35:59 -0400 Received: from mail-ew0-f206.google.com ([209.85.219.206]:52334 "EHLO mail-ew0-f206.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752670AbZIBPf6 (ORCPT ); Wed, 2 Sep 2009 11:35:58 -0400 Received: by ewy2 with SMTP id 2so947486ewy.17 for ; Wed, 02 Sep 2009 08:36:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer; bh=XqSeDKQd55DhDBZevKPu05StNCpmnLYQP5+3o0yv0t8=; b=oDS9JGjzpMhBZBbuMjxSoblQxQfOnLTZ4WPWouJQOPnOj0MkBIYNbpabioJASv00wT PlcJTrpkIFTcefB/dC520yUsk/nRnzyMBgkPjYtaS47UTUssMcyZ+1OLj3Bib6VtktI7 MNwMHUOviNeBBK75+tzbNl/ku/ksfHsGzvWJI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=CMpx/QmiUdEKTQeOtwMvBsxcq7241aFUANqelPd8B9vAQG5H1G5VAEag7f80alGf6D KQnxPNCrUxvyJi3gQS9/iPi2zZ/0k2bzyysr+hA1iZJfWGf2jzP+/gCJF9WHnvgTOQiI HFjLCmLEwehw+OmAK/1/AOcbCBFZgfARVaHRI= Received: by 10.216.29.80 with SMTP id h58mr219283wea.159.1251905731112; Wed, 02 Sep 2009 08:35:31 -0700 (PDT) Received: from localhost.localdomain ([118.229.143.102]) by mx.google.com with ESMTPS id q9sm105385gve.21.2009.09.02.08.35.26 (version=SSLv3 cipher=RC4-MD5); Wed, 02 Sep 2009 08:35:30 -0700 (PDT) From: Peng Tao To: linux-ext4@vger.kernel.org Cc: Theodore Tso , Akira Fujita , Peng Tao Subject: [PATCH] e4defrag: fallocate donor file only once Date: Wed, 2 Sep 2009 23:35:04 +0800 Message-Id: <1251905704-10078-1-git-send-email-bergwolf@gmail.com> X-Mailer: git-send-email 1.6.2-rc2.GIT Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org If we allocate the donor file once for all, it will have a better chance to be continuous. Signed-off-by: "Peng Tao" --- misc/e4defrag.c | 21 ++++++++++----------- 1 files changed, 10 insertions(+), 11 deletions(-) diff --git a/misc/e4defrag.c b/misc/e4defrag.c index c25514a..c1e9213 100644 --- a/misc/e4defrag.c +++ b/misc/e4defrag.c @@ -1603,6 +1603,7 @@ static int file_defrag(const char *file, const struct stat64 *buf, struct fiemap_extent_list *donor_list_logical = NULL; struct fiemap_extent_group *orig_group_head = NULL; struct fiemap_extent_group *orig_group_tmp = NULL; + ext4_fsblk_t orig_block_count; defraged_file_count++; @@ -1742,19 +1743,17 @@ static int file_defrag(const char *file, const struct stat64 *buf, /* Allocate space for donor inode */ orig_group_tmp = orig_group_head; do { - ret = fallocate(donor_fd, 0, - (loff_t)orig_group_tmp->start->data.logical * block_size, - (loff_t)orig_group_tmp->len * block_size); - if (ret < 0) { - if (mode_flag & DETAIL) { - PRINT_FILE_NAME(file); - PRINT_ERR_MSG_WITH_ERRNO("Failed to fallocate"); - } - goto out; - } - + orig_block_count += orig_group_tmp->len; orig_group_tmp = orig_group_tmp->next; } while (orig_group_tmp != orig_group_head); + ret = fallocate(donor_fd, 0, 0, (loff_t)orig_block_count * block_size); + if (ret < 0) { + if (mode_flag & DETAIL) { + PRINT_FILE_NAME(file); + PRINT_ERR_MSG_WITH_ERRNO("Failed to fallocate"); + } + goto out; + } /* Get donor inode's extents */ ret = get_file_extents(donor_fd, &donor_list_physical);